From b067ab9202c07513d07674227471dfcd11317542 Mon Sep 17 00:00:00 2001
From: Ozkan Sezer <[EMAIL REDACTED]>
Date: Thu, 1 Dec 2022 03:11:00 +0300
Subject: [PATCH] restore SDL_malloc.c original formatting.
(cherry picked from commit 45025799b75f544251f4a853e1c3f206243f0109)
---
src/stdlib/SDL_malloc.c | 4133 +++++++++++++++++++--------------------
1 file changed, 2004 insertions(+), 2129 deletions(-)
diff --git a/src/stdlib/SDL_malloc.c b/src/stdlib/SDL_malloc.c
index de02b5eefd6c..7640592fb6d1 100644
--- a/src/stdlib/SDL_malloc.c
+++ b/src/stdlib/SDL_malloc.c
@@ -405,9 +405,9 @@ MALLINFO_FIELD_TYPE default: size_t
size_t. The value is used only if HAVE_USR_INCLUDE_MALLOC_H is not set
REALLOC_ZERO_BYTES_FREES default: not defined
- This should be set if a call to realloc with zero bytes should
- be the same as a call to free. Some people think it should. Otherwise,
- since this malloc returns a unique pointer for malloc(0), so does
+ This should be set if a call to realloc with zero bytes should
+ be the same as a call to free. Some people think it should. Otherwise,
+ since this malloc returns a unique pointer for malloc(0), so does
realloc(p, 0).
LACKS_UNISTD_H, LACKS_FCNTL_H, LACKS_SYS_PARAM_H, LACKS_SYS_MMAN_H
@@ -483,9 +483,8 @@ DEFAULT_MMAP_THRESHOLD default: 256K
#ifndef WIN32
#ifdef _WIN32
#define WIN32 1
-#endif /* _WIN32 */
-#endif /* WIN32 */
-
+#endif /* _WIN32 */
+#endif /* WIN32 */
#ifdef WIN32
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
@@ -502,8 +501,8 @@ DEFAULT_MMAP_THRESHOLD default: 256K
#define LACKS_ERRNO_H
#define LACKS_FCNTL_H
#define MALLOC_FAILURE_ACTION
-#define MMAP_CLEARS 0 /* WINCE and some others apparently don't clear */
-#endif /* WIN32 */
+#define MMAP_CLEARS 0 /* WINCE and some others apparently don't clear */
+#endif /* WIN32 */
#ifdef __OS2__
#define INCL_DOS
@@ -518,113 +517,113 @@ DEFAULT_MMAP_THRESHOLD default: 256K
#ifndef HAVE_MORECORE
#define HAVE_MORECORE 0
#define HAVE_MMAP 1
-#endif /* HAVE_MORECORE */
-#endif /* DARWIN */
+#endif /* HAVE_MORECORE */
+#endif /* DARWIN */
#ifndef LACKS_SYS_TYPES_H
-#include <sys/types.h> /* For size_t */
-#endif /* LACKS_SYS_TYPES_H */
+#include <sys/types.h> /* For size_t */
+#endif /* LACKS_SYS_TYPES_H */
/* The maximum possible size_t value has all bits set */
#define MAX_SIZE_T (~(size_t)0)
#ifndef ONLY_MSPACES
#define ONLY_MSPACES 0
-#endif /* ONLY_MSPACES */
+#endif /* ONLY_MSPACES */
#ifndef MSPACES
#if ONLY_MSPACES
#define MSPACES 1
-#else /* ONLY_MSPACES */
+#else /* ONLY_MSPACES */
#define MSPACES 0
-#endif /* ONLY_MSPACES */
-#endif /* MSPACES */
+#endif /* ONLY_MSPACES */
+#endif /* MSPACES */
#ifndef MALLOC_ALIGNMENT
#define MALLOC_ALIGNMENT ((size_t)8U)
-#endif /* MALLOC_ALIGNMENT */
+#endif /* MALLOC_ALIGNMENT */
#ifndef FOOTERS
#define FOOTERS 0
-#endif /* FOOTERS */
+#endif /* FOOTERS */
#ifndef ABORT
#define ABORT abort()
-#endif /* ABORT */
+#endif /* ABORT */
#ifndef ABORT_ON_ASSERT_FAILURE
#define ABORT_ON_ASSERT_FAILURE 1
-#endif /* ABORT_ON_ASSERT_FAILURE */
+#endif /* ABORT_ON_ASSERT_FAILURE */
#ifndef PROCEED_ON_ERROR
#define PROCEED_ON_ERROR 0
-#endif /* PROCEED_ON_ERROR */
+#endif /* PROCEED_ON_ERROR */
#ifndef USE_LOCKS
#define USE_LOCKS 0
-#endif /* USE_LOCKS */
+#endif /* USE_LOCKS */
#ifndef INSECURE
#define INSECURE 0
-#endif /* INSECURE */
+#endif /* INSECURE */
#ifndef HAVE_MMAP
#define HAVE_MMAP 1
-#endif /* HAVE_MMAP */
+#endif /* HAVE_MMAP */
#ifndef MMAP_CLEARS
#define MMAP_CLEARS 1
-#endif /* MMAP_CLEARS */
+#endif /* MMAP_CLEARS */
#ifndef HAVE_MREMAP
#ifdef linux
#define HAVE_MREMAP 1
-#else /* linux */
+#else /* linux */
#define HAVE_MREMAP 0
-#endif /* linux */
-#endif /* HAVE_MREMAP */
+#endif /* linux */
+#endif /* HAVE_MREMAP */
#ifndef MALLOC_FAILURE_ACTION
#define MALLOC_FAILURE_ACTION errno = ENOMEM;
-#endif /* MALLOC_FAILURE_ACTION */
+#endif /* MALLOC_FAILURE_ACTION */
#ifndef HAVE_MORECORE
#if ONLY_MSPACES
#define HAVE_MORECORE 0
-#else /* ONLY_MSPACES */
+#else /* ONLY_MSPACES */
#define HAVE_MORECORE 1
-#endif /* ONLY_MSPACES */
-#endif /* HAVE_MORECORE */
+#endif /* ONLY_MSPACES */
+#endif /* HAVE_MORECORE */
#if !HAVE_MORECORE
#define MORECORE_CONTIGUOUS 0
-#else /* !HAVE_MORECORE */
+#else /* !HAVE_MORECORE */
#ifndef MORECORE
#define MORECORE sbrk
-#endif /* MORECORE */
+#endif /* MORECORE */
#ifndef MORECORE_CONTIGUOUS
#define MORECORE_CONTIGUOUS 1
-#endif /* MORECORE_CONTIGUOUS */
-#endif /* HAVE_MORECORE */
+#endif /* MORECORE_CONTIGUOUS */
+#endif /* HAVE_MORECORE */
#ifndef DEFAULT_GRANULARITY
#if MORECORE_CONTIGUOUS
-#define DEFAULT_GRANULARITY (0) /* 0 means to compute in init_mparams */
-#else /* MORECORE_CONTIGUOUS */
+#define DEFAULT_GRANULARITY (0) /* 0 means to compute in init_mparams */
+#else /* MORECORE_CONTIGUOUS */
#define DEFAULT_GRANULARITY ((size_t)64U * (size_t)1024U)
-#endif /* MORECORE_CONTIGUOUS */
-#endif /* DEFAULT_GRANULARITY */
+#endif /* MORECORE_CONTIGUOUS */
+#endif /* DEFAULT_GRANULARITY */
#ifndef DEFAULT_TRIM_THRESHOLD
#ifndef MORECORE_CANNOT_TRIM
#define DEFAULT_TRIM_THRESHOLD ((size_t)2U * (size_t)1024U * (size_t)1024U)
-#else /* MORECORE_CANNOT_TRIM */
+#else /* MORECORE_CANNOT_TRIM */
#define DEFAULT_TRIM_THRESHOLD MAX_SIZE_T
-#endif /* MORECORE_CANNOT_TRIM */
-#endif /* DEFAULT_TRIM_THRESHOLD */
+#endif /* MORECORE_CANNOT_TRIM */
+#endif /* DEFAULT_TRIM_THRESHOLD */
#ifndef DEFAULT_MMAP_THRESHOLD
#if HAVE_MMAP
#define DEFAULT_MMAP_THRESHOLD ((size_t)256U * (size_t)1024U)
-#else /* HAVE_MMAP */
+#else /* HAVE_MMAP */
#define DEFAULT_MMAP_THRESHOLD MAX_SIZE_T
-#endif /* HAVE_MMAP */
-#endif /* DEFAULT_MMAP_THRESHOLD */
+#endif /* HAVE_MMAP */
+#endif /* DEFAULT_MMAP_THRESHOLD */
#ifndef USE_BUILTIN_FFS
#define USE_BUILTIN_FFS 0
-#endif /* USE_BUILTIN_FFS */
+#endif /* USE_BUILTIN_FFS */
#ifndef USE_DEV_RANDOM
#define USE_DEV_RANDOM 0
-#endif /* USE_DEV_RANDOM */
+#endif /* USE_DEV_RANDOM */
#ifndef NO_MALLINFO
#define NO_MALLINFO 0
-#endif /* NO_MALLINFO */
+#endif /* NO_MALLINFO */
#ifndef MALLINFO_FIELD_TYPE
#define MALLINFO_FIELD_TYPE size_t
-#endif /* MALLINFO_FIELD_TYPE */
+#endif /* MALLINFO_FIELD_TYPE */
#ifndef memset
#define memset SDL_memset
@@ -675,27 +674,25 @@ DEFAULT_MMAP_THRESHOLD default: 256K
#include "/usr/include/malloc.h"
#else /* HAVE_USR_INCLUDE_MALLOC_H */
-struct mallinfo
-{
- MALLINFO_FIELD_TYPE arena; /* non-mmapped space allocated from system */
- MALLINFO_FIELD_TYPE ordblks; /* number of free chunks */
- MALLINFO_FIELD_TYPE smblks; /* always 0 */
- MALLINFO_FIELD_TYPE hblks; /* always 0 */
- MALLINFO_FIELD_TYPE hblkhd; /* space in mmapped regions */
- MALLINFO_FIELD_TYPE usmblks; /* maximum total allocated space */
- MALLINFO_FIELD_TYPE fsmblks; /* always 0 */
- MALLINFO_FIELD_TYPE uordblks; /* total allocated space */
- MALLINFO_FIELD_TYPE fordblks; /* total free space */
- MALLINFO_FIELD_TYPE keepcost; /* releasable (via malloc_trim) space */
+struct mallinfo {
+ MALLINFO_FIELD_TYPE arena; /* non-mmapped space allocated from system */
+ MALLINFO_FIELD_TYPE ordblks; /* number of free chunks */
+ MALLINFO_FIELD_TYPE smblks; /* always 0 */
+ MALLINFO_FIELD_TYPE hblks; /* always 0 */
+ MALLINFO_FIELD_TYPE hblkhd; /* space in mmapped regions */
+ MALLINFO_FIELD_TYPE usmblks; /* maximum total allocated space */
+ MALLINFO_FIELD_TYPE fsmblks; /* always 0 */
+ MALLINFO_FIELD_TYPE uordblks; /* total allocated space */
+ MALLINFO_FIELD_TYPE fordblks; /* total free space */
+ MALLINFO_FIELD_TYPE keepcost; /* releasable (via malloc_trim) space */
};
#endif /* HAVE_USR_INCLUDE_MALLOC_H */
#endif /* NO_MALLINFO */
#ifdef __cplusplus
-extern "C"
-{
-#endif /* __cplusplus */
+extern "C" {
+#endif /* __cplusplus */
#if !ONLY_MSPACES
@@ -718,7 +715,7 @@ extern "C"
#define dlmalloc_max_footprint malloc_max_footprint
#define dlindependent_calloc independent_calloc
#define dlindependent_comalloc independent_comalloc
-#endif /* USE_DL_PREFIX */
+#endif /* USE_DL_PREFIX */
/*
@@ -735,7 +732,7 @@ extern "C"
maximum supported value of n differs across systems, but is in all
cases less than the maximum representable value of a size_t.
*/
- void * SDLCALL dlmalloc(size_t);
+void* SDLCALL dlmalloc(size_t);
/*
free(void* p)
@@ -744,14 +741,14 @@ extern "C"
It has no effect if p is null. If p was not malloced or already
freed, free(p) will by default cause the current program to abort.
*/
- void SDLCALL dlfree(void *);
+void SDLCALL dlfree(void*);
/*
calloc(size_t n_elements, size_t element_size);
Returns a pointer to n_elements * element_size bytes, with all locations
set to zero.
*/
- void * SDLCALL dlcalloc(size_t, size_t);
+void* SDLCALL dlcalloc(size_t, size_t);
/*
realloc(void* p, size_t n)
@@ -776,7 +773,7 @@ extern "C"
to be used as an argument to realloc is not supported.
*/
- void * SDLCALL dlrealloc(void *, size_t);
+void* SDLCALL dlrealloc(void*, size_t);
/*
memalign(size_t alignment, size_t n);
@@ -790,14 +787,14 @@ extern "C"
Overreliance on memalign is a sure way to fragment space.
*/
- void *dlmemalign(size_t, size_t);
+void* dlmemalign(size_t, size_t);
/*
valloc(size_t n);
Equivalent to memalign(pagesize, n), where pagesize is the page
size of the system. If the pagesize is unknown, 4096 is used.
*/
- void *dlvalloc(size_t);
+void* dlvalloc(size_t);
/*
mallopt(int parameter_number, int parameter_value)
@@ -817,7 +814,7 @@ extern "C"
M_GRANULARITY -2 page size any power of 2 >= page size
M_MMAP_THRESHOLD -3 256*1024 any (or 0 if no MMAP support)
*/
- int dlmallopt(int, int);
+int dlmallopt(int, int);
/*
malloc_footprint();
@@ -828,7 +825,7 @@ extern "C"
Even if locks are otherwise defined, this function does not use them,
so results might not be up to date.
*/
- size_t dlmalloc_footprint(void);
+size_t dlmalloc_footprint(void);
/*
malloc_max_footprint();
@@ -841,7 +838,7 @@ extern "C"
otherwise defined, this function does not use them, so results might
not be up to date.
*/
- size_t dlmalloc_max_footprint(void);
+size_t dlmalloc_max_footprint(void);
#if !NO_MALLINFO
/*
@@ -866,8 +863,8 @@ extern "C"
be kept as longs, the reported values may wrap around zero and
thus be inaccurate.
*/
- struct mallinfo dlmallinfo(void);
-#endif /* NO_MALLINFO */
+struct mallinfo dlmallinfo(void);
+#endif /* NO_MALLINFO */
/*
independent_calloc(size_t n_elements, size_t element_size, void* chunks[]);
@@ -921,7 +918,7 @@ extern "C"
return first;
}
*/
- void **dlindependent_calloc(size_t, size_t, void **);
+void** dlindependent_calloc(size_t, size_t, void**);
/*
independent_comalloc(size_t n_elements, size_t sizes[], void* chunks[]);
@@ -982,7 +979,7 @@ extern "C"
since it cannot reuse existing noncontiguous small chunks that
might be available for some of the elements.
*/
- void **dlindependent_comalloc(size_t, size_t *, void **);
+void** dlindependent_comalloc(size_t, size_t*, void**);
/*
@@ -990,7 +987,7 @@ extern "C"
Equivalent to valloc(minimum-page-that-holds(n)), that is,
round up n to nearest pagesize.
*/
- void *dlpvalloc(size_t);
+void* dlpvalloc(size_t);
/*
malloc_trim(size_t pad);
@@ -1013,7 +1010,7 @@ extern "C"
Malloc_trim returns 1 if it actually released any memory, else 0.
*/
- int dlmalloc_trim(size_t);
+int dlmalloc_trim(size_t);
/*
malloc_usable_size(void* p);
@@ -1029,7 +1026,7 @@ extern "C"
p = malloc(n);
assert(malloc_usable_size(p) >= 256);
*/
- size_t dlmalloc_usable_size(void *);
+size_t dlmalloc_usable_size(void*);
/*
malloc_stats();
@@ -1050,9 +1047,9 @@ extern "C"
malloc_stats prints only the most commonly interesting statistics.
More information can be obtained by calling mallinfo.
*/
- void dlmalloc_stats(void);
+void dlmalloc_stats(void);
-#endif /* ONLY_MSPACES */
+#endif /* ONLY_MSPACES */
#if MSPACES
@@ -1060,7 +1057,7 @@ extern "C"
mspace is an opaque type representing an independent
region of space that supports mspace_malloc, etc.
*/
- typedef void *mspace;
+typedef void* mspace;
/*
create_mspace creates and returns a new independent space with the
@@ -1073,7 +1070,7 @@ extern "C"
compiling with a different DEFAULT_GRANULARITY or dynamically
setting with mallopt(M_GRANULARITY, value).
*/
- mspace create_mspace(size_t capacity, int locked);
+mspace create_mspace(size_t capacity, int locked);
/*
destroy_mspace destroys the given space, and attempts to return all
@@ -1081,7 +1078,7 @@ extern "C"
bytes freed. After destruction, the results of access to all memory
used by the space become undefined.
*/
- size_t destroy_mspace(mspace msp);
+size_t destroy_mspace(mspace msp);
/*
create_mspace_with_base uses the memory supplied as the initial base
@@ -1092,13 +1089,13 @@ extern "C"
Destroying this space will deallocate all additionally allocated
space (if possible) but not the initial base.
*/
- mspace create_mspace_with_base(void *base, size_t capacity, int locked);
+mspace create_mspace_with_base(void* base, size_t capacity, int locked);
/*
mspace_malloc behaves as malloc, but operates within
the given space.
*/
- void *mspace_malloc(mspace msp, size_t bytes);
+void* mspace_malloc(mspace msp, size_t bytes);
/*
mspace_free behaves as free, but operates within
@@ -1108,7 +1105,7 @@ extern "C"
free may be called instead of mspace_free because freed chunks from
any space are handled by their originating spaces.
*/
- void mspace_free(mspace msp, void *mem);
+void mspace_free(mspace msp, void* mem);
/*
mspace_realloc behaves as realloc, but operates within
@@ -1119,45 +1116,45 @@ extern "C"
realloced chunks from any space are handled by their originating
spaces.
*/
- void *mspace_realloc(mspace msp, void *mem, size_t newsize);
+void* mspace_realloc(mspace msp, void* mem, size_t newsize);
/*
mspace_calloc behaves as calloc, but operates within
the given space.
*/
- void *mspace_calloc(mspace msp, size_t n_elements, size_t elem_size);
+void* mspace_calloc(mspace msp, size_t n_elements, size_t elem_size);
/*
mspace_memalign behaves as memalign, but operates within
the given space.
*/
- void *mspace_memalign(mspace msp, size_t alignment, size_t bytes);
+void* mspace_memalign(mspace msp, size_t alignment, size_t bytes);
/*
mspace_independent_calloc behaves as independent_calloc, but
operates within the given space.
*/
- void **mspace_independent_calloc(mspace msp, size_t n_elements,
- size_t elem_size, void *chunks[]);
+void** mspace_independent_calloc(mspace msp, size_t n_elements,
+ size_t elem_size, void* chunks[]);
/*
mspace_independent_comalloc behaves as independent_comalloc, but
operates within the given space.
*/
- void **mspace_independent_comalloc(mspace msp, size_t n_elements,
- size_t sizes[], void *chunks[]);
+void** mspace_independent_comalloc(mspace msp, size_t n_elements,
+ size_t sizes[], void* chunks[]);
/*
mspace_footprint() returns the number of bytes obtained from the
system for this space.
*/
- size_t mspace_footprint(mspace msp);
+size_t mspace_footprint(mspace msp);
/*
mspace_max_footprint() returns the peak number of bytes obtained from the
system for this space.
*/
- size_t mspace_max_footprint(mspace msp);
+size_t mspace_max_footprint(mspace msp);
#if !NO_MALLINFO
@@ -1165,30 +1162,30 @@ extern "C"
mspace_mallinfo behaves as mallinfo, but reports properties of
the given space.
*/
- struct mallinfo mspace_mallinfo(mspace msp);
-#endif /* NO_MALLINFO */
+struct mallinfo mspace_mallinfo(mspace msp);
+#endif /* NO_MALLINFO */
/*
mspace_malloc_stats behaves as malloc_stats, but reports
properties of the given space.
*/
- void mspace_malloc_stats(mspace msp);
+void mspace_malloc_stats(mspace msp);
/*
mspace_trim behaves as malloc_trim, but
operates within the given space.
*/
- int mspace_trim(mspace msp, size_t pad);
+int mspace_trim(mspace msp, size_t pad);
/*
An alias for mallopt.
*/
- int mspace_mallopt(int, int);
+int mspace_mallopt(int, int);
-#endif /* MSPACES */
+#endif /* MSPACES */
#ifdef __cplusplus
-}; /* end of extern "C" */
+}; /* end of extern "C" */
#endif /* __cplusplus */
/*
@@ -1204,21 +1201,21 @@ extern "C"
/*------------------------------ internal #includes ---------------------- */
#ifdef _MSC_VER
-#pragma warning( disable : 4146 ) /* no "unsigned" warnings */
+#pragma warning( disable : 4146 ) /* no "unsigned" warnings */
#endif /* _MSC_VER */
#ifndef LACKS_STDIO_H
-#include <stdio.h> /* for printing in malloc_stats */
+#include <stdio.h> /* for printing in malloc_stats */
#endif
#ifndef LACKS_ERRNO_H
-#include <errno.h> /* for MALLOC_FAILURE_ACTION */
+#include <errno.h> /* for MALLOC_FAILURE_ACTION */
#endif /* LACKS_ERRNO_H */
#if FOOTERS
-#include <time.h> /* for magic initialization */
+#include <time.h> /* for magic initialization */
#endif /* FOOTERS */
#ifndef LACKS_STDLIB_H
-#include <stdlib.h> /* for abort() */
+#include <stdlib.h> /* for abort() */
#endif /* LACKS_STDLIB_H */
#ifdef DEBUG
#if ABORT_ON_ASSERT_FAILURE
@@ -1226,20 +1223,20 @@ extern "C"
#else /* ABORT_ON_ASSERT_FAILURE */
#include <assert.h>
#endif /* ABORT_ON_ASSERT_FAILURE */
-#else /* DEBUG */
+#else /* DEBUG */
#define assert(x)
#endif /* DEBUG */
#ifndef LACKS_STRING_H
-#include <string.h> /* for memset etc */
-#endif /* LACKS_STRING_H */
+#include <string.h> /* for memset etc */
+#endif /* LACKS_STRING_H */
#if USE_BUILTIN_FFS
#ifndef LACKS_STRINGS_H
-#include <strings.h> /* for ffs */
+#include <strings.h> /* for ffs */
#endif /* LACKS_STRINGS_H */
#endif /* USE_BUILTIN_FFS */
#if HAVE_MMAP
#ifndef LACKS_SYS_MMAN_H
-#include <sys/mman.h> /* for mmap */
+#include <sys/mman.h> /* for mmap */
#endif /* LACKS_SYS_MMAN_H */
#ifndef LACKS_FCNTL_H
#include <fcntl.h>
@@ -1247,17 +1244,17 @@ extern "C"
#endif /* HAVE_MMAP */
#if HAVE_MORECORE
#ifndef LACKS_UNISTD_H
-#include <unistd.h> /* for sbrk */
+#include <unistd.h> /* for sbrk */
#else /* LACKS_UNISTD_H */
#if !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__NetBSD__) && !defined(__DragonFly__)
-extern void *sbrk(ptrdiff_t);
+extern void* sbrk(ptrdiff_t);
#endif /* FreeBSD etc */
#endif /* LACKS_UNISTD_H */
#endif /* HAVE_MMAP */
#ifndef WIN32
#ifndef malloc_getpagesize
-# ifdef _SC_PAGESIZE /* some SVR4 systems omit an underscore */
+# ifdef _SC_PAGESIZE /* some SVR4 systems omit an underscore */
# ifndef _SC_PAGE_SIZE
# define _SC_PAGE_SIZE _SC_PAGESIZE
# endif
@@ -1266,10 +1263,10 @@ extern void *sbrk(ptrdiff_t);
# define malloc_getpagesize sysconf(_SC_PAGE_SIZE)
# else
# if defined(BSD) || defined(DGUX) || defined(HAVE_GETPAGESIZE)
-extern size_t getpagesize();
+ extern size_t getpagesize();
# define malloc_getpagesize getpagesize()
# else
-# ifdef WIN32 /* use supplied emulation of getpagesize */
+# ifdef WIN32 /* use supplied emulation of getpagesize */
# define malloc_getpagesize getpagesize()
# else
# ifndef LACKS_SYS_PARAM_H
@@ -1340,7 +1337,7 @@ extern size_t getpagesize();
/* MORECORE and MMAP must return MFAIL on failure */
#define MFAIL ((void*)(MAX_SIZE_T))
-#define CMFAIL ((char*)(MFAIL)) /* defined for convenience */
+#define CMFAIL ((char*)(MFAIL)) /* defined for convenience */
#if !HAVE_MMAP
#define IS_MMAPPED_BIT (SIZE_T_ZERO)
@@ -1353,7 +1350,7 @@ extern size_t getpagesize();
#define IS_MMAPPED_BIT (SIZE_T_ONE)
#define USE_MMAP_BIT (SIZE_T_ONE)
-#if !defined(WIN32) && !defined (__OS2__)
+#if !defined(WIN32) && !defined(__OS2__)
#define CALL_MUNMAP(a, s) munmap((a), (s))
#define MMAP_PROT (PROT_READ|PROT_WRITE)
#if !defined(MAP_ANONYMOUS) && defined(MAP_ANON)
@@ -1368,7 +1365,7 @@ extern size_t getpagesize();
is unlikely to be needed, but is supplied just in case.
*/
#define MMAP_FLAGS (MAP_PRIVATE)
-static int dev_zero_fd = -1; /* Cached file descriptor for /dev/zero. */
+static int dev_zero_fd = -1; /* Cached file descriptor for /dev/zero. */
#define CALL_MMAP(s) ((dev_zero_fd < 0) ? \
(dev_zero_fd = open("/dev/zero", O_RDWR), \
mmap(0, (s), MMAP_PROT, MMAP_FLAGS, dev_zero_fd, 0)) : \
@@ -1415,41 +1412,34 @@ static int os2munmap(void* ptr, size_t size) {
#else /* WIN32 */
/* Win32 MMAP via VirtualAlloc */
-static void *
-win32mmap(size_t size)
-{
- void *ptr =
- VirtualAlloc(0, size, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
- return (ptr != 0) ? ptr : MFAIL;
+static void* win32mmap(size_t size) {
+ void* ptr = VirtualAlloc(0, size, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE);
+ return (ptr != 0)? ptr: MFAIL;
}
/* For direct MMAP, use MEM_TOP_DOWN to minimize interference */
-static void *
-win32direct_mmap(size_t size)
-{
- void *ptr = VirtualAlloc(0, size, MEM_RESERVE | MEM_COMMIT | MEM_TOP_DOWN,
- PAGE_READWRITE);
- return (ptr != 0) ? ptr : MFAIL;
+static void* win32direct_mmap(size_t size) {
+ void* ptr = VirtualAlloc(0, size, MEM_RESERVE|MEM_COMMIT|MEM_TOP_DOWN,
+ PAGE_READWRITE);
+ return (ptr != 0)? ptr: MFAIL;
}
/* This function supports releasing coalesed segments */
-static int
-win32munmap(void *ptr, size_t size)
-{
- MEMORY_BASIC_INFORMATION minfo;
- char *cptr = ptr;
- while (size) {
- if (VirtualQuery(cptr, &minfo, sizeof(minfo)) == 0)
- return -1;
- if (minfo.BaseAddress != cptr || minfo.AllocationBase != cptr ||
- minfo.State != MEM_COMMIT || minfo.RegionSize > size)
- return -1;
- if (VirtualFree(cptr, 0, MEM_RELEASE) == 0)
- return -1;
- cptr += minfo.RegionSize;
- size -= minfo.RegionSize;
- }
- return 0;
+static int win32munmap(void* ptr, size_t size) {
+ MEMORY_BASIC_INFORMATION minfo;
+ char* cptr = ptr;
+ while (size) {
+ if (VirtualQuery(cptr, &minfo, sizeof(minfo)) == 0)
+ return -1;
+ if (minfo.BaseAddress != cptr || minfo.AllocationBase != cptr ||
+ minfo.State != MEM_COMMIT || minfo.RegionSize > size)
+ return -1;
+ if (VirtualFree(cptr, 0, MEM_RELEASE) == 0)
+ return -1;
+ cptr += minfo.RegionSize;
+ size -= minfo.RegionSize;
+ }
+ return 0;
}
#define CALL_MMAP(s) win32mmap(s)
@@ -1460,13 +1450,13 @@ win32munmap(void *ptr, size_t size)
#if HAVE_MMAP && HAVE_MREMAP
#define CALL_MREMAP(addr, osz, nsz, mv) mremap((addr), (osz), (nsz), (mv))
-#else /* HAVE_MMAP && HAVE_MREMAP */
+#else /* HAVE_MMAP && HAVE_MREMAP */
#define CALL_MREMAP(addr, osz, nsz, mv) MFAIL
#endif /* HAVE_MMAP && HAVE_MREMAP */
#if HAVE_MORECORE
#define CALL_MORECORE(S) MORECORE(S)
-#else /* HAVE_MORECORE */
+#else /* HAVE_MORECORE */
#define CALL_MORECORE(S) MFAIL
#endif /* HAVE_MORECORE */
@@ -1526,25 +1516,21 @@ static MLOCK_T magic_init_mutex;
*/
#define MLOCK_T long
-static int
-win32_acquire_lock(MLOCK_T * sl)
-{
- for (;;) {
+static int win32_acquire_lock (MLOCK_T *sl) {
+ for (;;) {
#ifdef InterlockedCompareExchangePointer
- if (!InterlockedCompareExchange(sl, 1, 0))
- return 0;
-#else /* Use older void* version */
- if (!InterlockedCompareExchange((void **) sl, (void *) 1, (void *) 0))
- return 0;
+ if (!InterlockedCompareExchange(sl, 1, 0))
+ return 0;
+#else /* Use older void* version */
+ if (!InterlockedCompareExchange((void**)sl, (void*)1, (void*)0))
+ return 0;
#endif /* InterlockedCompareExchangePointer */
- Sleep(0);
- }
+ Sleep (0);
+ }
}
-static void
-win32_release_lock(MLOCK_T * sl)
-{
- InterlockedExchange(sl, 0);
+static void win32_release_lock (MLOCK_T *sl) {
+ InterlockedExchange (sl, 0);
}
#define INITIAL_LOCK(l) *(l)=0
@@ -1557,7 +1543,7 @@ static MLOCK_T magic_init_mutex;
#endif /* WIN32 */
#define USE_LOCK_BIT (2U)
-#else /* USE_LOCKS */
+#else /* USE_LOCKS */
#define USE_LOCK_BIT (0U)
#define INITIAL_LOCK(l)
#endif /* USE_LOCKS */
@@ -1573,7 +1559,7 @@ static MLOCK_T magic_init_mutex;
#if USE_LOCKS
#define ACQUIRE_MAGIC_INIT_LOCK() ACQUIRE_LOCK(&magic_init_mutex);
#define RELEASE_MAGIC_INIT_LOCK() RELEASE_LOCK(&magic_init_mutex);
-#else /* USE_LOCKS */
+#else /* USE_LOCKS */
#define ACQUIRE_MAGIC_INIT_LOCK()
#define RELEASE_MAGIC_INIT_LOCK()
#endif /* USE_LOCKS */
@@ -1716,20 +1702,19 @@ static MLOCK_T magic_init_mutex;
*/
-struct malloc_chunk
-{
- size_t prev_foot; /* Size of previous chunk (if free). */
- size_t head; /* Size and inuse bits. */
- struct malloc_chunk *fd; /* double links -- used only if free. */
- struct malloc_chunk *bk;
+struct malloc_chunk {
+ size_t prev_foot; /* Size of previous chunk (if free). */
+ size_t head; /* Size and inuse bits. */
+ struct malloc_chunk* fd; /* double links -- used only if free. */
+ struct malloc_chunk* bk;
};
-typedef struct malloc_chunk mchunk;
-typedef struct malloc_chunk *mchunkptr;
-typedef struct malloc_chunk *sbinptr; /* The type of bins of chunks */
-typedef size_t bindex_t; /* Described below */
-typedef unsigned int binmap_t; /* Described below */
-typedef unsigned int flag_t; /* The type of various bit flag sets */
+typedef struct malloc_chunk mchunk;
+typedef struct malloc_chunk* mchunkptr;
+typedef struct malloc_chunk* sbinptr; /* The type of bins of chunks */
+typedef size_t bindex_t; /* Described below */
+typedef unsigned int binmap_t; /* Described below */
+typedef unsigned int flag_t; /* The type of various bit flag sets */
/* ------------------- Chunks sizes and alignments ----------------------- */
@@ -1922,22 +1907,21 @@ nextchunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
is of course much better.
*/
-struct malloc_tree_chunk
-{
- /* The first four fields must be compatible with malloc_chunk */
- size_t prev_foot;
- size_t head;
- struct malloc_tree_chunk *fd;
- struct malloc_tree_chunk *bk;
-
- struct malloc_tree_chunk *child[2];
- struct malloc_tree_chunk *parent;
- bindex_t index;
+struct malloc_tree_chunk {
+ /* The first four fields must be compatible with malloc_chunk */
+ size_t prev_foot;
+ size_t head;
+ struct malloc_tree_chunk* fd;
+ struct malloc_tree_chunk* bk;
+
+ struct malloc_tree_chunk* child[2];
+ struct malloc_tree_chunk* parent;
+ bindex_t index;
};
-typedef struct malloc_tree_chunk tchunk;
-typedef struct malloc_tree_chunk *tchunkptr;
-typedef struct malloc_tree_chunk *tbinptr; /* The type of bins of trees */
+typedef struct malloc_tree_chunk tchunk;
+typedef struct malloc_tree_chunk* tchunkptr;
+typedef struct malloc_tree_chunk* tbinptr; /* The type of bins of trees */
/* A little helper macro for trees */
#define leftmost_child(t) ((t)->child[0] != 0? (t)->child[0] : (t)->child[1])
@@ -1999,19 +1983,18 @@ typedef struct malloc_tree_chunk *tbinptr; /* The type of bins of trees */
and deallocated/trimmed using MORECORE with negative arguments.
*/
-struct malloc_segment
-{
- char *base; /* base address */
- size_t size; /* allocated size */
- struct malloc_segment *next; /* ptr to next segment */
- flag_t sflags; /* mmap and extern flag */
+struct malloc_segment {
+ char* base; /* base address */
+ size_t size; /* allocated size */
+ struct malloc_segment* next; /* ptr to next segment */
+ flag_t sflags; /* mmap and extern flag */
};
#define is_mmapped_segment(S) ((S)->sflags & IS_MMAPPED_BIT)
#define is_extern_segment(S) ((S)->sflags & EXTERN_BIT)
-typedef struct malloc_segment msegment;
-typedef struct malloc_segment *msegmentptr;
+typedef struct malloc_segment msegment;
+typedef struct malloc_segment* msegmentptr;
/* ---------------------------- malloc_state ----------------------------- */
@@ -2098,29 +2081,28 @@ typedef struct malloc_segment *msegmentptr;
#define MAX_SMALL_SIZE (MIN_LARGE_SIZE - SIZE_T_ONE)
#define MAX_SMALL_REQUEST (MAX_SMALL_SIZE - CHUNK_ALIGN_MASK - CHUNK_OVERHEAD)
-struct malloc_state
-{
- binmap_t smallmap;
- binmap_t treemap;
- size_t dvsize;
- size_t topsize;
- char *least_addr;
- mchunkptr dv;
- mchunkptr top;
- size_t trim_check;
- size_t magic;
- mchunkptr smallbins[(NSMALLBINS + 1) * 2];
- tbinptr treebins[NTREEBINS];
- size_t footprint;
- size_t max_footprint;
- flag_t mflags;
+struct malloc_state {
+ binmap_t smallmap;
+ binmap_t treemap;
+ size_t dvsize;
+ size_t topsize;
+ char* least_addr;
+ mchunkptr dv;
+ mchunkptr top;
+ size_t trim_check;
+ size_t magic;
+ mchunkptr smallbins[(NSMALLBINS+1)*2];
+ tbinptr treebins[NTREEBINS];
+ size_t footprint;
+ size_t max_footprint;
+ flag_t mflags;
#if USE_LOCKS
- MLOCK_T mutex; /* locate lock among fields that rarely change */
-#endif /* USE_LOCKS */
- msegment seg;
+ MLOCK_T mutex; /* locate lock among fields that rarely change */
+#endif /* USE_LOCKS */
+ msegment seg;
};
-typedef struct malloc_state *mstate;
+typedef struct malloc_state* mstate;
/* ------------- Global malloc_state and malloc_params ------------------- */
@@ -2130,14 +2112,13 @@ typedef struct malloc_state *mstate;
initialized in init_mparams.
*/
-struct malloc_params
-{
- size_t magic;
- size_t page_size;
- size_t granularity;
- size_t mmap_threshold;
- size_t trim_threshold;
- flag_t default_mflags;
+struct malloc_params {
+ size_t magic;
+ size_t page_size;
+ size_t granularity;
+ size_t mmap_threshold;
+ size_t trim_threshold;
+ flag_t default_mflags;
};
static struct malloc_params mparams;
@@ -2186,34 +2167,30 @@ static struct malloc_state _gm_;
((char*)(A) >= S->base && (char*)(A) < S->base + S->size)
/* Return segment holding given address */
-static msegmentptr
-segment_holding(mstate m, char *addr)
-{
- msegmentptr sp = &m->seg;
- for (;;) {
- if (addr >= sp->base && addr < sp->base + sp->size)
- return sp;
- if ((sp = sp->next) == 0)
- return 0;
- }
+static msegmentptr segment_holding(mstate m, char* addr) {
+ msegmentptr sp = &m->seg;
+ for (;;) {
+ if (addr >= sp->base && addr < sp->base + sp->size)
+ return sp;
+ if ((sp = sp->next) == 0)
+ return 0;
+ }
}
/* Re
(Patch may be truncated, please check the link at the top of this post.)