gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] [libmicrohttpd] 02/05: memorypool: use 'bool' instead MHD_Y


From: gnunet
Subject: [GNUnet-SVN] [libmicrohttpd] 02/05: memorypool: use 'bool' instead MHD_YES/MHD_NO and 'uint8_t' instead of 'char'
Date: Thu, 13 Jun 2019 00:06:37 +0200

This is an automated email from the git hooks/post-receive script.

karlson2k pushed a commit to branch master
in repository libmicrohttpd.

commit 1430529713674acda1c16112d57c506dbd0c9f8e
Author: Evgeny Grin (Karlson2k) <address@hidden>
AuthorDate: Wed Jun 12 19:08:02 2019 +0300

    memorypool: use 'bool' instead MHD_YES/MHD_NO and 'uint8_t' instead of 
'char'
---
 src/microhttpd/connection.c | 10 +++++-----
 src/microhttpd/memorypool.c | 34 ++++++++++++++--------------------
 src/microhttpd/memorypool.h |  9 ++++++---
 src/microhttpd/response.c   |  2 +-
 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,
 
   pos = MHD_pool_allocate (connection->pool,
                            sizeof (struct MHD_HTTP_Header),
-                           MHD_YES);
+                           true);
   if (NULL == pos)
     return MHD_NO;
   pos->header = (char *) key;
@@ -1370,7 +1370,7 @@ try_ready_chunked_body (struct MHD_Connection *connection)
             }
           buf = MHD_pool_allocate (connection->pool,
                                    size,
-                                   MHD_NO);
+                                   false);
         }
       while (NULL == buf);
       connection->write_buffer_size = size;
@@ -1644,7 +1644,7 @@ build_header_response (struct MHD_Connection *connection)
     {
       data = MHD_pool_allocate (connection->pool,
                                 0,
-                                MHD_YES);
+                                true);
       connection->write_buffer = data;
       connection->write_buffer_append_offset = 0;
       connection->write_buffer_send_offset = 0;
@@ -1880,7 +1880,7 @@ build_header_response (struct MHD_Connection *connection)
   /* produce data */
   data = MHD_pool_allocate (connection->pool,
                             size + 1,
-                            MHD_NO);
+                            false);
   if (NULL == data)
     {
 #ifdef HAVE_MESSAGES
@@ -2338,7 +2338,7 @@ parse_cookie_header (struct MHD_Connection *connection)
     return MHD_YES;
   cpy = MHD_pool_allocate (connection->pool,
                            hdr_len + 1,
-                           MHD_YES);
+                           true);
   if (NULL == cpy)
     {
 #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 @@
 #include "memorypool.h"
 #include <stdlib.h>
 #include <string.h>
+#include <stdint.h>
 #include "mhd_assert.h"
 #if HAVE_SYS_MMAN_H
 #include <sys/mman.h>
@@ -35,13 +36,6 @@
 #include <memoryapi.h>
 #endif
 
-#ifndef MHD_YES
-#define MHD_YES 1
-#endif
-#ifndef MHD_NO
-#define MHD_NO 0
-#endif
-
 /* define MAP_ANONYMOUS for Mac OS X */
 #if defined(MAP_ANON) && !defined(MAP_ANONYMOUS)
 #define MAP_ANONYMOUS MAP_ANON
@@ -71,7 +65,7 @@ struct MemoryPool
   /**
    * Pointer to the pool's memory
    */
-  char *memory;
+  uint8_t *memory;
 
   /**
    * Size of the pool.
@@ -89,9 +83,9 @@ struct MemoryPool
   size_t end;
 
   /**
-   * #MHD_NO if pool was malloc'ed, #MHD_YES if mmapped (VirtualAlloc'ed for 
W32).
+   * 'false' if pool was malloc'ed, 'true' if mmapped (VirtualAlloc'ed for 
W32).
    */
-  int is_mmap;
+  bool is_mmap;
 };
 
 
@@ -138,11 +132,11 @@ MHD_pool_create (size_t max)
           free (pool);
           return NULL;
         }
-      pool->is_mmap = MHD_NO;
+      pool->is_mmap = false;
     }
   else
     {
-      pool->is_mmap = MHD_YES;
+      pool->is_mmap = true;
     }
   pool->pos = 0;
   pool->end = max;
@@ -164,7 +158,7 @@ MHD_pool_destroy (struct MemoryPool *pool)
 
   mhd_assert (pool->end >= pool->pos);
   mhd_assert (pool->size >= pool->end - pool->pos);
-  if (MHD_NO == pool->is_mmap)
+  if (!pool->is_mmap)
     free (pool->memory);
   else
 #if defined(MAP_ANONYMOUS) && !defined(_WIN32)
@@ -201,7 +195,7 @@ MHD_pool_get_free (struct MemoryPool *pool)
  *
  * @param pool memory pool to use for the operation
  * @param size number of bytes to allocate
- * @param from_end allocate from end of pool (set to #MHD_YES);
+ * @param from_end allocate from end of pool (set to 'true');
  *        use this for small, persistent allocations that
  *        will never be reallocated
  * @return NULL if the pool cannot support size more
@@ -210,7 +204,7 @@ MHD_pool_get_free (struct MemoryPool *pool)
 void *
 MHD_pool_allocate (struct MemoryPool *pool,
                   size_t size,
-                   int from_end)
+                   bool from_end)
 {
   void *ret;
   size_t asize;
@@ -223,7 +217,7 @@ MHD_pool_allocate (struct MemoryPool *pool,
   if ( (pool->pos + asize > pool->end) ||
        (pool->pos + asize < pool->pos))
     return NULL;
-  if (from_end == MHD_YES)
+  if (from_end)
     {
       ret = &pool->memory[pool->end - asize];
       pool->end -= asize;
@@ -266,8 +260,8 @@ MHD_pool_reallocate (struct MemoryPool *pool,
   mhd_assert (pool->end >= pool->pos);
   mhd_assert (pool->size >= pool->end - pool->pos);
   mhd_assert (old != NULL || old_size == 0);
-  mhd_assert (old == NULL || pool->memory <= (char*)old);
-  mhd_assert (old == NULL || pool->memory + pool->size >= (char*)old + 
old_size);
+  mhd_assert (old == NULL || pool->memory <= (uint8_t*)old);
+  mhd_assert (old == NULL || pool->memory + pool->size >= (uint8_t*)old + 
old_size);
   asize = ROUND_TO_ALIGN (new_size);
   if ( (0 == asize) &&
        (0 != new_size) )
@@ -334,8 +328,8 @@ MHD_pool_reset (struct MemoryPool *pool,
   mhd_assert (pool->end >= pool->pos);
   mhd_assert (pool->size >= pool->end - pool->pos);
   mhd_assert (keep != NULL || copy_bytes == 0);
-  mhd_assert (keep == NULL || pool->memory <= (char*)keep);
-  mhd_assert (keep == NULL || pool->memory + pool->size >= (char*)keep + 
copy_bytes);
+  mhd_assert (keep == NULL || pool->memory <= (uint8_t*)keep);
+  mhd_assert (keep == NULL || pool->memory + pool->size >= (uint8_t*)keep + 
copy_bytes);
   if ( (NULL != keep) &&
        (keep != pool->memory) )
     {
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 @@
 
 #include "mhd_options.h"
 #include <stddef.h>
+#ifdef HAVE_STDBOOL_H
+#include <stdbool.h>
+#endif
 
 /**
  * Opaque handle for a memory pool.
@@ -65,7 +68,7 @@ MHD_pool_destroy (struct MemoryPool *pool);
  *
  * @param pool memory pool to use for the operation
  * @param size number of bytes to allocate
- * @param from_end allocate from end of pool (set to #MHD_YES);
+ * @param from_end allocate from end of pool (set to 'true');
  *        use this for small, persistent allocations that
  *        will never be reallocated
  * @return NULL if the pool cannot support size more
@@ -73,8 +76,8 @@ MHD_pool_destroy (struct MemoryPool *pool);
  */
 void *
 MHD_pool_allocate (struct MemoryPool *pool,
-                  size_t size,
-                   int from_end);
+                   size_t size,
+                   bool from_end);
 
 
 /**
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,
            to another protocol. */
         buf = MHD_pool_allocate (pool,
                                  avail,
-                                 MHD_NO);
+                                 false);
       }
     /* use half the buffer for inbound, half for outbound */
     urh->in_buffer_size = avail / 2;

-- 
To stop receiving notification emails like this one, please contact
address@hidden.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]