gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [libmicrohttpd] branch master updated (2abfb2cc -> 739d5528


From: gnunet
Subject: [GNUnet-SVN] [libmicrohttpd] branch master updated (2abfb2cc -> 739d5528)
Date: Thu, 13 Jun 2019 00:06:35 +0200

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

karlson2k pushed a change to branch master
in repository libmicrohttpd.

    from 2abfb2cc memorypool: refactored includes, moved out unrelated function
     new b98f757a memorypool: further narrow down includes
     new 14305297 memorypool: use 'bool' instead MHD_YES/MHD_NO and 'uint8_t' 
instead of 'char'
     new d15bd7c0 memorypool: fixed possible crash if failed to allocate memory 
on W32
     new a0b48ac7 memorypool: minor macro and comment fixes
     new 739d5528 test_large_put: test memory realloc too

The 5 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/microhttpd/connection.c   | 10 ++++-----
 src/microhttpd/memorypool.c   | 47 ++++++++++++++++++++++++++-----------------
 src/microhttpd/memorypool.h   | 15 ++++++++------
 src/microhttpd/response.c     |  2 +-
 src/testcurl/test_large_put.c |  2 +-
 5 files changed, 45 insertions(+), 31 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 415b8aa5..3746eb71 100644
--- a/src/microhttpd/memorypool.c
+++ b/src/microhttpd/memorypool.c
@@ -25,14 +25,24 @@
  * @author Karlson2k (Evgeny Grin)
  */
 #include "memorypool.h"
-#include "internal.h"
+#include <stdlib.h>
+#include <string.h>
+#include <stdint.h>
 #include "mhd_assert.h"
+#if HAVE_SYS_MMAN_H
+#include <sys/mman.h>
+#endif
+#ifdef _WIN32
+#include <memoryapi.h>
+#endif
 
 /* define MAP_ANONYMOUS for Mac OS X */
 #if defined(MAP_ANON) && !defined(MAP_ANONYMOUS)
 #define MAP_ANONYMOUS MAP_ANON
 #endif
-#ifndef MAP_FAILED
+#if defined(_WIN32)
+#define MAP_FAILED NULL
+#elif ! defined(MAP_FAILED)
 #define MAP_FAILED ((void*)-1)
 #endif
 
@@ -44,7 +54,7 @@
 /**
  * Round up 'n' to a multiple of ALIGN_SIZE.
  */
-#define ROUND_TO_ALIGN(n) ((n+(ALIGN_SIZE-1)) & (~(ALIGN_SIZE-1)))
+#define ROUND_TO_ALIGN(n) (((n)+(ALIGN_SIZE-1)) & (~(ALIGN_SIZE-1)))
 
 
 /**
@@ -57,7 +67,7 @@ struct MemoryPool
   /**
    * Pointer to the pool's memory
    */
-  char *memory;
+  uint8_t *memory;
 
   /**
    * Size of the pool.
@@ -70,14 +80,14 @@ struct MemoryPool
   size_t pos;
 
   /**
-   * Offset of the last unallocated byte.
+   * Offset of the byte after the last unallocated byte.
    */
   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;
 };
 
 
@@ -92,6 +102,7 @@ MHD_pool_create (size_t max)
 {
   struct MemoryPool *pool;
 
+  max = ROUND_TO_ALIGN(max);
   pool = malloc (sizeof (struct MemoryPool));
   if (NULL == pool)
     return NULL;
@@ -124,11 +135,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;
@@ -150,7 +161,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)
@@ -187,7 +198,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
@@ -196,7 +207,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;
@@ -209,7 +220,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;
@@ -230,7 +241,7 @@ MHD_pool_allocate (struct MemoryPool *pool,
  * If the given block is not the most recently
  * (re)allocated block, the memory of the previous
  * allocation may be leaked until the pool is
- * destroyed (and copying the data maybe required).
+ * destroyed or reset.
  *
  * @param pool memory pool to use for the operation
  * @param old the existing block
@@ -252,8 +263,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) )
@@ -320,8 +331,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..c5fe7ada 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);
 
 
 /**
@@ -84,15 +87,15 @@ MHD_pool_allocate (struct MemoryPool *pool,
  * If the given block is not the most recently
  * (re)allocated block, the memory of the previous
  * allocation may be leaked until the pool is
- * destroyed (and copying the data maybe required).
+ * destroyed or reset.
  *
  * @param pool memory pool to use for the operation
  * @param old the existing block
  * @param old_size the size of the existing block
  * @param new_size the new size of the block
  * @return new address of the block, or
- *         NULL if the pool cannot support new_size
- *         bytes (old continues to be valid for old_size)
+ *         NULL if the pool cannot support @a new_size
+ *         bytes (old continues to be valid for @a old_size)
  */
 void *
 MHD_pool_reallocate (struct MemoryPool *pool,
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;
diff --git a/src/testcurl/test_large_put.c b/src/testcurl/test_large_put.c
index 352a1732..4495cfd6 100644
--- a/src/testcurl/test_large_put.c
+++ b/src/testcurl/test_large_put.c
@@ -202,7 +202,7 @@ testPutInternalThread (unsigned int add_flag)
   d = MHD_start_daemon (MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG | 
add_flag,
                         port,
                         NULL, NULL, &ahc_echo, &done_flag,
-                       MHD_OPTION_CONNECTION_MEMORY_LIMIT, (size_t)(incr_read 
? 1024 : (PUT_SIZE * 4)),
+                       MHD_OPTION_CONNECTION_MEMORY_LIMIT, (size_t)(incr_read 
? 1024 : (PUT_SIZE * 4 / 3)),
                        MHD_OPTION_END);
   if (d == NULL)
     return 1;

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



reply via email to

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