]> pd.if.org Git - pdclib/blobdiff - opt/dlmalloc/dlmalloc.c
PDCLib includes with quotes, not <>.
[pdclib] / opt / dlmalloc / dlmalloc.c
index 32c3c35686d582443a7a2f3033936c7e87506207..54703d480f5c5e89acf656a0f11c6a691930c107 100644 (file)
@@ -516,6 +516,7 @@ MAX_RELEASE_CHECK_RATE   default: 4095 unless not HAVE_MMAP
   improvement at the expense of carrying around more memory.\r
 */\r
 \r
+#ifndef REGTEST\r
 #include "dlmalloc.h"\r
 \r
 /* Version identifier to allow people to support multiple versions */\r
@@ -813,7 +814,7 @@ extern "C" {
 #define dlcalloc               calloc\r
 #define dlfree                 free\r
 #define dlmalloc               malloc\r
-#define dlmemalign             memalign\r
+#define dlmemalign             aligned_alloc\r
 #define dlposix_memalign       posix_memalign\r
 #define dlrealloc              realloc\r
 #define dlrealloc_in_place     realloc_in_place\r
@@ -834,6 +835,8 @@ extern "C" {
 #define dlbulk_free            bulk_free\r
 #endif /* USE_DL_PREFIX */\r
 \r
+#if 0 // Redeclaration warnings as PDCLib already declares these in <stdio.h>\r
+\r
 /*\r
   malloc(size_t n)\r
   Returns a pointer to a newly allocated chunk of at least n bytes, or\r
@@ -890,6 +893,22 @@ DLMALLOC_EXPORT void* dlcalloc(size_t, size_t);
 */\r
 DLMALLOC_EXPORT void* dlrealloc(void*, size_t);\r
 \r
+/*\r
+  memalign(size_t alignment, size_t n);\r
+  Returns a pointer to a newly allocated chunk of n bytes, aligned\r
+  in accord with the alignment argument.\r
+\r
+  The alignment argument should be a power of two. If the argument is\r
+  not a power of two, the nearest greater power is used.\r
+  8-byte alignment is guaranteed by normal malloc calls, so don't\r
+  bother calling memalign with an argument of 8 or less.\r
+\r
+  Overreliance on memalign is a sure way to fragment space.\r
+*/\r
+DLMALLOC_EXPORT void* dlmemalign(size_t, size_t);\r
+\r
+#endif\r
+\r
 /*\r
   realloc_in_place(void* p, size_t n)\r
   Resizes the space allocated for p to size n, only if this can be\r
@@ -905,20 +924,6 @@ DLMALLOC_EXPORT void* dlrealloc(void*, size_t);
 */\r
 DLMALLOC_EXPORT void* dlrealloc_in_place(void*, size_t);\r
 \r
-/*\r
-  memalign(size_t alignment, size_t n);\r
-  Returns a pointer to a newly allocated chunk of n bytes, aligned\r
-  in accord with the alignment argument.\r
-\r
-  The alignment argument should be a power of two. If the argument is\r
-  not a power of two, the nearest greater power is used.\r
-  8-byte alignment is guaranteed by normal malloc calls, so don't\r
-  bother calling memalign with an argument of 8 or less.\r
-\r
-  Overreliance on memalign is a sure way to fragment space.\r
-*/\r
-DLMALLOC_EXPORT void* dlmemalign(size_t, size_t);\r
-\r
 /*\r
   int posix_memalign(void** pp, size_t alignment, size_t n);\r
   Allocates a chunk of n bytes, aligned in accord with the alignment\r
@@ -1643,7 +1648,6 @@ unsigned char _BitScanReverse(unsigned long *index, unsigned long mask);
    is unlikely to be needed, but is supplied just in case.\r
 */\r
 #define MMAP_FLAGS           (MAP_PRIVATE)\r
-static int dev_zero_fd = -1; /* Cached file descriptor for /dev/zero. */\r
 #define MMAP_DEFAULT(s) ((dev_zero_fd < 0) ? \\r
            (dev_zero_fd = open("/dev/zero", O_RDWR), \\r
             mmap(0, (s), MMAP_PROT, MMAP_FLAGS, dev_zero_fd, 0)) : \\r
@@ -3836,7 +3840,7 @@ static void* mmap_alloc(mstate m, size_t nb) {
 /* Realloc using mmap */\r
 static mchunkptr mmap_resize(mstate m, mchunkptr oldp, size_t nb, int flags) {\r
   size_t oldsize = chunksize(oldp);\r
-  flags = flags; /* placate people compiling -Wunused */\r
+  (void) flags;\r
   if (is_small(nb)) /* Can't shrink mmap regions below small size */\r
     return 0;\r
   /* Keep old chunk if big enough but not too big */\r
@@ -6251,3 +6255,15 @@ History:
          structure of old version,  but most details differ.)\r
 \r
 */\r
+#endif\r
+\r
+#ifdef TEST\r
+#include "_PDCLIB_test.h"\r
+\r
+/* TODO: TEST ME */\r
+int main( void )\r
+{\r
+    return TEST_RESULTS;\r
+}\r
+\r
+#endif\r