aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvgeny Grin (Karlson2k) <k2k@narod.ru>2019-06-12 19:08:02 +0300
committerEvgeny Grin (Karlson2k) <k2k@narod.ru>2019-06-12 19:08:02 +0300
commit1430529713674acda1c16112d57c506dbd0c9f8e (patch)
tree22e6004f53a12967f96b686ba0f7606e5b1d7f39
parentb98f757af86d20eb63a9156768bcbc24dc237afc (diff)
downloadlibmicrohttpd-1430529713674acda1c16112d57c506dbd0c9f8e.tar.gz
libmicrohttpd-1430529713674acda1c16112d57c506dbd0c9f8e.zip
memorypool: use 'bool' instead MHD_YES/MHD_NO and 'uint8_t' instead of 'char'
-rw-r--r--src/microhttpd/connection.c10
-rw-r--r--src/microhttpd/memorypool.c34
-rw-r--r--src/microhttpd/memorypool.h9
-rw-r--r--src/microhttpd/response.c2
4 files changed, 26 insertions, 29 deletions
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c
index f6c1dbb5..b3ef9441 100644
--- a/src/microhttpd/connection.c
+++ b/src/microhttpd/connection.c
@@ -791,7 +791,7 @@ MHD_set_connection_value_n_nocheck_ (struct MHD_Connection *connection,
791 791
792 pos = MHD_pool_allocate (connection->pool, 792 pos = MHD_pool_allocate (connection->pool,
793 sizeof (struct MHD_HTTP_Header), 793 sizeof (struct MHD_HTTP_Header),
794 MHD_YES); 794 true);
795 if (NULL == pos) 795 if (NULL == pos)
796 return MHD_NO; 796 return MHD_NO;
797 pos->header = (char *) key; 797 pos->header = (char *) key;
@@ -1370,7 +1370,7 @@ try_ready_chunked_body (struct MHD_Connection *connection)
1370 } 1370 }
1371 buf = MHD_pool_allocate (connection->pool, 1371 buf = MHD_pool_allocate (connection->pool,
1372 size, 1372 size,
1373 MHD_NO); 1373 false);
1374 } 1374 }
1375 while (NULL == buf); 1375 while (NULL == buf);
1376 connection->write_buffer_size = size; 1376 connection->write_buffer_size = size;
@@ -1644,7 +1644,7 @@ build_header_response (struct MHD_Connection *connection)
1644 { 1644 {
1645 data = MHD_pool_allocate (connection->pool, 1645 data = MHD_pool_allocate (connection->pool,
1646 0, 1646 0,
1647 MHD_YES); 1647 true);
1648 connection->write_buffer = data; 1648 connection->write_buffer = data;
1649 connection->write_buffer_append_offset = 0; 1649 connection->write_buffer_append_offset = 0;
1650 connection->write_buffer_send_offset = 0; 1650 connection->write_buffer_send_offset = 0;
@@ -1880,7 +1880,7 @@ build_header_response (struct MHD_Connection *connection)
1880 /* produce data */ 1880 /* produce data */
1881 data = MHD_pool_allocate (connection->pool, 1881 data = MHD_pool_allocate (connection->pool,
1882 size + 1, 1882 size + 1,
1883 MHD_NO); 1883 false);
1884 if (NULL == data) 1884 if (NULL == data)
1885 { 1885 {
1886#ifdef HAVE_MESSAGES 1886#ifdef HAVE_MESSAGES
@@ -2338,7 +2338,7 @@ parse_cookie_header (struct MHD_Connection *connection)
2338 return MHD_YES; 2338 return MHD_YES;
2339 cpy = MHD_pool_allocate (connection->pool, 2339 cpy = MHD_pool_allocate (connection->pool,
2340 hdr_len + 1, 2340 hdr_len + 1,
2341 MHD_YES); 2341 true);
2342 if (NULL == cpy) 2342 if (NULL == cpy)
2343 { 2343 {
2344#ifdef HAVE_MESSAGES 2344#ifdef HAVE_MESSAGES
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)
210void * 204void *
211MHD_pool_allocate (struct MemoryPool *pool, 205MHD_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 {
diff --git a/src/microhttpd/memorypool.h b/src/microhttpd/memorypool.h
index 2863b2f3..79b10e73 100644
--- a/src/microhttpd/memorypool.h
+++ b/src/microhttpd/memorypool.h
@@ -32,6 +32,9 @@
32 32
33#include "mhd_options.h" 33#include "mhd_options.h"
34#include <stddef.h> 34#include <stddef.h>
35#ifdef HAVE_STDBOOL_H
36#include <stdbool.h>
37#endif
35 38
36/** 39/**
37 * Opaque handle for a memory pool. 40 * Opaque handle for a memory pool.
@@ -65,7 +68,7 @@ MHD_pool_destroy (struct MemoryPool *pool);
65 * 68 *
66 * @param pool memory pool to use for the operation 69 * @param pool memory pool to use for the operation
67 * @param size number of bytes to allocate 70 * @param size number of bytes to allocate
68 * @param from_end allocate from end of pool (set to #MHD_YES); 71 * @param from_end allocate from end of pool (set to 'true');
69 * use this for small, persistent allocations that 72 * use this for small, persistent allocations that
70 * will never be reallocated 73 * will never be reallocated
71 * @return NULL if the pool cannot support size more 74 * @return NULL if the pool cannot support size more
@@ -73,8 +76,8 @@ MHD_pool_destroy (struct MemoryPool *pool);
73 */ 76 */
74void * 77void *
75MHD_pool_allocate (struct MemoryPool *pool, 78MHD_pool_allocate (struct MemoryPool *pool,
76 size_t size, 79 size_t size,
77 int from_end); 80 bool from_end);
78 81
79 82
80/** 83/**
diff --git a/src/microhttpd/response.c b/src/microhttpd/response.c
index f43ca541..035e3054 100644
--- a/src/microhttpd/response.c
+++ b/src/microhttpd/response.c
@@ -974,7 +974,7 @@ MHD_response_execute_upgrade_ (struct MHD_Response *response,
974 to another protocol. */ 974 to another protocol. */
975 buf = MHD_pool_allocate (pool, 975 buf = MHD_pool_allocate (pool,
976 avail, 976 avail,
977 MHD_NO); 977 false);
978 } 978 }
979 /* use half the buffer for inbound, half for outbound */ 979 /* use half the buffer for inbound, half for outbound */
980 urh->in_buffer_size = avail / 2; 980 urh->in_buffer_size = avail / 2;