Commit fca28d4e authored by Yoni Fogel's avatar Yoni Fogel

[t:2499] Windows port of casting to typeof().

Implement workaround.  Currently windows allows implicit casts from void* to whatever*.
May need to be revisited once windows cilk is included.

git-svn-id: file:///svn/toku/tokudb@19937 c7de825b-a66e-492c-adef-691d508d4ae1
parent 03c66d52
...@@ -57,27 +57,27 @@ void *toku_realloc(void *, size_t size) __attribute__((__visibility__("default" ...@@ -57,27 +57,27 @@ void *toku_realloc(void *, size_t size) __attribute__((__visibility__("default"
* struct foo *MALLOC(x); * struct foo *MALLOC(x);
* and you cannot go wrong. * and you cannot go wrong.
*/ */
#define MALLOC(v) v = (__typeof__(v)) toku_malloc(sizeof(*v)) #define MALLOC(v) v = cast_to_typeof(v) toku_malloc(sizeof(*v))
/* MALLOC_N is like calloc(Except no 0ing of data): It makes an array. Write /* MALLOC_N is like calloc(Except no 0ing of data): It makes an array. Write
* int *MALLOC_N(5,x); * int *MALLOC_N(5,x);
* to make an array of 5 integers. * to make an array of 5 integers.
*/ */
#define MALLOC_N(n,v) v = (__typeof__(v)) toku_malloc((n)*sizeof(*v)) #define MALLOC_N(n,v) v = cast_to_typeof(v) toku_malloc((n)*sizeof(*v))
//CALLOC_N is like calloc with auto-figuring out size of members //CALLOC_N is like calloc with auto-figuring out size of members
#define CALLOC_N(n,v) v = (__typeof__(v)) toku_calloc((n), sizeof(*v)) #define CALLOC_N(n,v) v = cast_to_typeof(v) toku_calloc((n), sizeof(*v))
#define CALLOC(v) CALLOC_N(1,v) #define CALLOC(v) CALLOC_N(1,v)
#define REALLOC_N(n,v) v = (__typeof__(v)) toku_realloc(v, (n)*sizeof(*v)) #define REALLOC_N(n,v) v = cast_to_typeof(v) toku_realloc(v, (n)*sizeof(*v))
// XMALLOC macros are like MALLOC except they abort if the operation fails // XMALLOC macros are like MALLOC except they abort if the operation fails
#define XMALLOC(v) v = (__typeof__(v)) toku_xmalloc(sizeof(*v)) #define XMALLOC(v) v = cast_to_typeof(v) toku_xmalloc(sizeof(*v))
#define XMALLOC_N(n,v) v = (__typeof__(v)) toku_xmalloc((n)*sizeof(*v)) #define XMALLOC_N(n,v) v = cast_to_typeof(v) toku_xmalloc((n)*sizeof(*v))
#define XCALLOC_N(n,v) v = (__typeof__(v)) toku_xcalloc((n), (sizeof(*v))) #define XCALLOC_N(n,v) v = cast_to_typeof(v) toku_xcalloc((n), (sizeof(*v)))
#define XCALLOC(v) XCALLOC_N(1,(v)) #define XCALLOC(v) XCALLOC_N(1,(v))
#define XREALLOC_N(n,v) v = (__typeof__(v)) toku_xrealloc(v, (n)*sizeof(*v)) #define XREALLOC_N(n,v) v = cast_to_typeof(v) toku_xrealloc(v, (n)*sizeof(*v))
/* If you have a type such as /* If you have a type such as
* struct pma *PMA; * struct pma *PMA;
......
...@@ -52,6 +52,8 @@ typedef int64_t toku_off_t; ...@@ -52,6 +52,8 @@ typedef int64_t toku_off_t;
#define UNUSED_WARNING(a) a=a /* To make up for missing attributes */ #define UNUSED_WARNING(a) a=a /* To make up for missing attributes */
#define cast_to_typeof(v)
#elif defined(__INTEL_COMPILER) #elif defined(__INTEL_COMPILER)
#if defined(__ICC) #if defined(__ICC)
...@@ -64,6 +66,7 @@ typedef int64_t toku_off_t; ...@@ -64,6 +66,7 @@ typedef int64_t toku_off_t;
#endif #endif
#define cast_to_typeof(v) (__typeof__(v))
#elif defined(__GNUC__) #elif defined(__GNUC__)
// GCC linux // GCC linux
...@@ -76,6 +79,7 @@ typedef int64_t toku_off_t; ...@@ -76,6 +79,7 @@ typedef int64_t toku_off_t;
#include <stdarg.h> #include <stdarg.h>
#endif #endif
#define cast_to_typeof(v) (__typeof__(v))
#else #else
#error Not ICC and not GNUC. What compiler? #error Not ICC and not GNUC. What compiler?
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment