]> Savannah Git Hosting - gnulib.git/commitdiff
ssfmalloc: Portability to Cygwin.
authorBruno Haible <bruno@clisp.org>
Sun, 25 Oct 2020 17:08:44 +0000 (18:08 +0100)
committerBruno Haible <bruno@clisp.org>
Sun, 25 Oct 2020 17:08:44 +0000 (18:08 +0100)
* lib/ssfmalloc.h: Add parameter PAGESIZE_MAX.
(pg_offset_t): Define depending on PAGESIZE_MAX.
* tests/test-ssfmalloc.c: Undefine PAGESIZE.
(PAGESIZE_MAX): New macro.

ChangeLog
lib/ssfmalloc.h
tests/test-ssfmalloc.c

index ed0195d760725f105cb08a2f5de60320ac42a565..5f8279324e5092eb66262a3526ef1aa57efdb652 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2020-10-25  Bruno Haible  <bruno@clisp.org>
 
+       ssfmalloc: Portability to Cygwin.
+       * lib/ssfmalloc.h: Add parameter PAGESIZE_MAX.
+       (pg_offset_t): Define depending on PAGESIZE_MAX.
+       * tests/test-ssfmalloc.c: Undefine PAGESIZE.
+       (PAGESIZE_MAX): New macro.
+
        ssfmalloc: Fix buffer overrun in bitmap search.
        * lib/ssfmalloc-bitmap.h (find_first_packet_set): Don't access the
        word *words_end.
index 999126eaa68d9ea7dd47778eb6ca940c27fc1b97..43d0851567f9e06b313f020e1d0bbdf0b99e82a9 100644 (file)
@@ -55,6 +55,8 @@
      PAGESIZE           A variable-like macro of type intptr_t or uintptr_t
                         that evaluates to the memory page size (>= 4096).
 
+     PAGESIZE_MAX       A constant that specifies an upper bound for PAGESIZE.
+
      ALLOC_PAGES        A function-like macro with the signature
                           uintptr_t ALLOC_PAGES (size_t size)
                         where the argument size is > 0 and a multiple of the
@@ -151,7 +153,11 @@ struct any_page_header
 /* ========================= Small and medium blocks ======================== */
 
 /* An integer type, capable of holding the values 0 .. PAGESIZE.  */
+#if PAGESIZE_MAX >= 0x10000
+typedef unsigned int   pg_offset_t;
+#else
 typedef unsigned short pg_offset_t;
+#endif
 
 /* Tree element that corresponds to a page.
    These tree elements are allocated via malloc().  */
index e1dfcec3256f86e2d3d7ce066f165c5aa5a5bf92..09427c77013f0cb24e565b5d5ab4d02542309e10 100644 (file)
@@ -118,13 +118,25 @@ free_pages (uintptr_t pages, size_t size)
 #endif
 }
 
+/* Cygwin defines PAGESIZE in <limits.h>.  */
+#undef PAGESIZE
+
 /* ======================= Instantiate the front end ======================= */
 
 #define PAGESIZE pagesize
+/* On Cygwin, PAGESIZE is 65536.  On all other platforms, it is either 4096
+   or 8192.  */
+#ifdef __CYGWIN__
+# define PAGESIZE_MAX 65536
+#else
+# define PAGESIZE_MAX 8192
+#endif
+
 #define ALLOC_PAGES alloc_pages
 #define FREE_PAGES free_pages
 #define ALIGNMENT (sizeof (void *)) /* or 8 or 16 or 32 */
 #define PAGE_RESERVED_HEADER_SIZE (3 * UINTPTR_WIDTH / 8) /* = 3 * sizeof (void *) */
+
 #include "ssfmalloc.h"
 
 /* ================================= Tests ================================= */