diff options
author | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2019-06-12 19:08:02 +0300 |
---|---|---|
committer | Evgeny Grin (Karlson2k) <k2k@narod.ru> | 2019-06-12 19:08:02 +0300 |
commit | 1430529713674acda1c16112d57c506dbd0c9f8e (patch) | |
tree | 22e6004f53a12967f96b686ba0f7606e5b1d7f39 /src/microhttpd/memorypool.c | |
parent | b98f757af86d20eb63a9156768bcbc24dc237afc (diff) | |
download | libmicrohttpd-1430529713674acda1c16112d57c506dbd0c9f8e.tar.gz libmicrohttpd-1430529713674acda1c16112d57c506dbd0c9f8e.zip |
memorypool: use 'bool' instead MHD_YES/MHD_NO and 'uint8_t' instead of 'char'
Diffstat (limited to 'src/microhttpd/memorypool.c')
-rw-r--r-- | src/microhttpd/memorypool.c | 34 |
1 files changed, 14 insertions, 20 deletions
diff --git a/src/microhttpd/memorypool.c b/src/microhttpd/memorypool.c index 63acb841..843dd540 100644 --- a/src/microhttpd/memorypool.c +++ b/src/microhttpd/memorypool.c | |||
@@ -27,6 +27,7 @@ | |||
27 | #include "memorypool.h" | 27 | #include "memorypool.h" |
28 | #include <stdlib.h> | 28 | #include <stdlib.h> |
29 | #include <string.h> | 29 | #include <string.h> |
30 | #include <stdint.h> | ||
30 | #include "mhd_assert.h" | 31 | #include "mhd_assert.h" |
31 | #if HAVE_SYS_MMAN_H | 32 | #if HAVE_SYS_MMAN_H |
32 | #include <sys/mman.h> | 33 | #include <sys/mman.h> |
@@ -35,13 +36,6 @@ | |||
35 | #include <memoryapi.h> | 36 | #include <memoryapi.h> |
36 | #endif | 37 | #endif |
37 | 38 | ||
38 | #ifndef MHD_YES | ||
39 | #define MHD_YES 1 | ||
40 | #endif | ||
41 | #ifndef MHD_NO | ||
42 | #define MHD_NO 0 | ||
43 | #endif | ||
44 | |||
45 | /* define MAP_ANONYMOUS for Mac OS X */ | 39 | /* define MAP_ANONYMOUS for Mac OS X */ |
46 | #if defined(MAP_ANON) && !defined(MAP_ANONYMOUS) | 40 | #if defined(MAP_ANON) && !defined(MAP_ANONYMOUS) |
47 | #define MAP_ANONYMOUS MAP_ANON | 41 | #define MAP_ANONYMOUS MAP_ANON |
@@ -71,7 +65,7 @@ struct MemoryPool | |||
71 | /** | 65 | /** |
72 | * Pointer to the pool's memory | 66 | * Pointer to the pool's memory |
73 | */ | 67 | */ |
74 | char *memory; | 68 | uint8_t *memory; |
75 | 69 | ||
76 | /** | 70 | /** |
77 | * Size of the pool. | 71 | * Size of the pool. |
@@ -89,9 +83,9 @@ struct MemoryPool | |||
89 | size_t end; | 83 | size_t end; |
90 | 84 | ||
91 | /** | 85 | /** |
92 | * #MHD_NO if pool was malloc'ed, #MHD_YES if mmapped (VirtualAlloc'ed for W32). | 86 | * 'false' if pool was malloc'ed, 'true' if mmapped (VirtualAlloc'ed for W32). |
93 | */ | 87 | */ |
94 | int is_mmap; | 88 | bool is_mmap; |
95 | }; | 89 | }; |
96 | 90 | ||
97 | 91 | ||
@@ -138,11 +132,11 @@ MHD_pool_create (size_t max) | |||
138 | free (pool); | 132 | free (pool); |
139 | return NULL; | 133 | return NULL; |
140 | } | 134 | } |
141 | pool->is_mmap = MHD_NO; | 135 | pool->is_mmap = false; |
142 | } | 136 | } |
143 | else | 137 | else |
144 | { | 138 | { |
145 | pool->is_mmap = MHD_YES; | 139 | pool->is_mmap = true; |
146 | } | 140 | } |
147 | pool->pos = 0; | 141 | pool->pos = 0; |
148 | pool->end = max; | 142 | pool->end = max; |
@@ -164,7 +158,7 @@ MHD_pool_destroy (struct MemoryPool *pool) | |||
164 | 158 | ||
165 | mhd_assert (pool->end >= pool->pos); | 159 | mhd_assert (pool->end >= pool->pos); |
166 | mhd_assert (pool->size >= pool->end - pool->pos); | 160 | mhd_assert (pool->size >= pool->end - pool->pos); |
167 | if (MHD_NO == pool->is_mmap) | 161 | if (!pool->is_mmap) |
168 | free (pool->memory); | 162 | free (pool->memory); |
169 | else | 163 | else |
170 | #if defined(MAP_ANONYMOUS) && !defined(_WIN32) | 164 | #if defined(MAP_ANONYMOUS) && !defined(_WIN32) |
@@ -201,7 +195,7 @@ MHD_pool_get_free (struct MemoryPool *pool) | |||
201 | * | 195 | * |
202 | * @param pool memory pool to use for the operation | 196 | * @param pool memory pool to use for the operation |
203 | * @param size number of bytes to allocate | 197 | * @param size number of bytes to allocate |
204 | * @param from_end allocate from end of pool (set to #MHD_YES); | 198 | * @param from_end allocate from end of pool (set to 'true'); |
205 | * use this for small, persistent allocations that | 199 | * use this for small, persistent allocations that |
206 | * will never be reallocated | 200 | * will never be reallocated |
207 | * @return NULL if the pool cannot support size more | 201 | * @return NULL if the pool cannot support size more |
@@ -210,7 +204,7 @@ MHD_pool_get_free (struct MemoryPool *pool) | |||
210 | void * | 204 | void * |
211 | MHD_pool_allocate (struct MemoryPool *pool, | 205 | MHD_pool_allocate (struct MemoryPool *pool, |
212 | size_t size, | 206 | size_t size, |
213 | int from_end) | 207 | bool from_end) |
214 | { | 208 | { |
215 | void *ret; | 209 | void *ret; |
216 | size_t asize; | 210 | size_t asize; |
@@ -223,7 +217,7 @@ MHD_pool_allocate (struct MemoryPool *pool, | |||
223 | if ( (pool->pos + asize > pool->end) || | 217 | if ( (pool->pos + asize > pool->end) || |
224 | (pool->pos + asize < pool->pos)) | 218 | (pool->pos + asize < pool->pos)) |
225 | return NULL; | 219 | return NULL; |
226 | if (from_end == MHD_YES) | 220 | if (from_end) |
227 | { | 221 | { |
228 | ret = &pool->memory[pool->end - asize]; | 222 | ret = &pool->memory[pool->end - asize]; |
229 | pool->end -= asize; | 223 | pool->end -= asize; |
@@ -266,8 +260,8 @@ MHD_pool_reallocate (struct MemoryPool *pool, | |||
266 | mhd_assert (pool->end >= pool->pos); | 260 | mhd_assert (pool->end >= pool->pos); |
267 | mhd_assert (pool->size >= pool->end - pool->pos); | 261 | mhd_assert (pool->size >= pool->end - pool->pos); |
268 | mhd_assert (old != NULL || old_size == 0); | 262 | mhd_assert (old != NULL || old_size == 0); |
269 | mhd_assert (old == NULL || pool->memory <= (char*)old); | 263 | mhd_assert (old == NULL || pool->memory <= (uint8_t*)old); |
270 | mhd_assert (old == NULL || pool->memory + pool->size >= (char*)old + old_size); | 264 | mhd_assert (old == NULL || pool->memory + pool->size >= (uint8_t*)old + old_size); |
271 | asize = ROUND_TO_ALIGN (new_size); | 265 | asize = ROUND_TO_ALIGN (new_size); |
272 | if ( (0 == asize) && | 266 | if ( (0 == asize) && |
273 | (0 != new_size) ) | 267 | (0 != new_size) ) |
@@ -334,8 +328,8 @@ MHD_pool_reset (struct MemoryPool *pool, | |||
334 | mhd_assert (pool->end >= pool->pos); | 328 | mhd_assert (pool->end >= pool->pos); |
335 | mhd_assert (pool->size >= pool->end - pool->pos); | 329 | mhd_assert (pool->size >= pool->end - pool->pos); |
336 | mhd_assert (keep != NULL || copy_bytes == 0); | 330 | mhd_assert (keep != NULL || copy_bytes == 0); |
337 | mhd_assert (keep == NULL || pool->memory <= (char*)keep); | 331 | mhd_assert (keep == NULL || pool->memory <= (uint8_t*)keep); |
338 | mhd_assert (keep == NULL || pool->memory + pool->size >= (char*)keep + copy_bytes); | 332 | mhd_assert (keep == NULL || pool->memory + pool->size >= (uint8_t*)keep + copy_bytes); |
339 | if ( (NULL != keep) && | 333 | if ( (NULL != keep) && |
340 | (keep != pool->memory) ) | 334 | (keep != pool->memory) ) |
341 | { | 335 | { |