regtest: fix wrong interfaces in calls to operator delete
[valgrind.git] / tests / malloc.h
bloba64abbf2d79439134907d551fa33679dbdf7c3a8
1 // Replacement for malloc.h which factors out platform differences.
3 #include <stdlib.h>
4 #include "config.h"
5 #if defined(VGO_darwin)
6 # include <malloc/malloc.h>
7 #elif defined(VGO_freebsd)
8 # include <stdlib.h>
9 # include <malloc_np.h>
10 #else
11 # include <malloc.h>
12 #endif
14 #include <assert.h>
16 // Allocates a 16-aligned block. Asserts if the allocation fails.
17 __attribute__((unused))
18 static void* memalign16(size_t szB)
20 void* x;
21 #if defined(VGO_darwin) || defined(VGO_freebsd)
22 // Darwin lacks memalign, but its malloc is always 16-aligned anyway.
23 posix_memalign((void **)&x, 16, szB);
24 #else
25 x = memalign(16, szB);
26 #endif
27 assert(x);
28 assert(0 == ((16-1) & (unsigned long)x));
29 return x;
32 // Allocates a 32-aligned block. Asserts if the allocation fails.
33 __attribute__((unused))
34 static void* memalign32(size_t szB)
36 void* x;
37 #if defined(VGO_darwin) || defined(VGO_freebsd)
38 // Darwin lacks memalign
39 posix_memalign((void **)&x, 32, szB);
40 #else
41 x = memalign(32, szB);
42 #endif
43 assert(x);
44 assert(0 == ((32-1) & (unsigned long)x));
45 return x;
48 // Allocates a 64-aligned block. Asserts if the allocation fails.
49 __attribute__((unused))
50 static void* memalign64(size_t szB)
52 void* x;
53 #if defined(VGO_darwin) || defined(VGO_freebsd)
54 // Darwin lacks memalign
55 posix_memalign((void **)&x, 64, szB);
56 #else
57 x = memalign(64, szB);
58 #endif
59 assert(x);
60 assert(0 == ((64-1) & (unsigned long)x));
61 return x;