Merge remote branch 'origin/master' into lp-binning
[mesa.git] / src / gallium / auxiliary / util / u_memory.h
index ec32d60fbe75ea2a26b9f678b96571c0c3bf89e7..c3f8c918338f5e495817305dc55f367d8d0ca26b 100644 (file)
 
 
 #include "util/u_pointer.h"
+#include "util/u_debug.h"
 
 
- /* Define ENOMEM for WINCE */ 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/* Define ENOMEM for WINCE */ 
 #if (_WIN32_WCE < 600)
 #ifndef ENOMEM
 #define ENOMEM 12
 #endif
 
 
-
-#if defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY) && defined(DEBUG) 
+#if defined(PIPE_OS_WINDOWS) && defined(DEBUG) 
 
 /* memory debugging */
 
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
 
 #define MALLOC( _size ) \
    debug_malloc( __FILE__, __LINE__, __FUNCTION__, _size )
@@ -95,8 +100,14 @@ ExFreePool(void *P);
 #define MALLOC( SIZE )  malloc( SIZE )
 #define CALLOC( COUNT, SIZE )   calloc( COUNT, SIZE )
 #define FREE( PTR )  free( PTR )
-#define REALLOC( OLDPTR, OLDSIZE, NEWSIZE )  realloc( OLDPTR, NEWSIZE )
 
+static INLINE void *
+_REALLOC( void *old_ptr, unsigned old_size, unsigned new_size )
+{
+   (void) old_size;
+   return realloc(old_ptr, new_size);
+}
+#define REALLOC( a, b, c ) _REALLOC( a, b, c )
 #endif
 
 
@@ -146,6 +157,8 @@ REALLOC( void *old_ptr, unsigned old_size, unsigned new_size )
 
 #define CALLOC_STRUCT(T)   (struct T *) CALLOC(1, sizeof(struct T))
 
+#define CALLOC_VARIANT_LENGTH_STRUCT(T,more_size)   ((struct T *) CALLOC(1, sizeof(struct T) + more_size))
+
 
 /**
  * Return memory on given byte alignment
@@ -184,9 +197,11 @@ align_free(void *ptr)
 #if defined(HAVE_POSIX_MEMALIGN)
    FREE(ptr);
 #else
-   void **cubbyHole = (void **) ((char *) ptr - sizeof(void *));
-   void *realAddr = *cubbyHole;
-   FREE(realAddr);
+   if (ptr) {
+      void **cubbyHole = (void **) ((char *) ptr - sizeof(void *));
+      void *realAddr = *cubbyHole;
+      FREE(realAddr);
+   }
 #endif /* defined(HAVE_POSIX_MEMALIGN) */
 }
 
@@ -219,4 +234,9 @@ mem_dup(const void *src, uint size)
 
 
 
+#ifdef __cplusplus
+}
+#endif
+
+
 #endif /* U_MEMORY_H */