From 517ca8423368e12ffec4a5e97c79001898ecc9d0 Mon Sep 17 00:00:00 2001
From: Ivan Maidanski <ivmai@mail.ru>
Date: Tue, 26 Nov 2024 23:38:42 +0300
Subject: [PATCH] Move GET_MEM() definition to gc_priv.h (refactoring)

* include/private/gc_priv.h (GET_MEM): Copy from `gcconfig.h` file.
* include/private/gc_priv.h (GC_win32_get_mem, GC_wince_get_mem,
GC_durango_get_mem, GC_haiku_get_mem, os2_alloc, GC_unix_get_mem): Move
declaration from `gcconfig.h` file.
* include/private/gc_priv.h [(CYGWIN32 || MSWIN32) && !USE_WINALLOC
|| !(CYGWIN32 || MSWIN32) && !MSWINCE && !MSWIN_XBOX1 && !HAIKU && !OS2
&& !(DOS4GW || EMBOX || KOS || NEXT || NONSTOP || RTEMS || __CC_ARM
|| SOLARIS && !USE_MMAP) && !GET_MEM] (NEED_UNIX_GET_MEM): Move
definition from `gcconfig.h` file.
* include/private/gcconfig.h [GC_PRIVATE_H] (GET_MEM): Remove.
---
 include/private/gc_priv.h  | 46 +++++++++++++++++++++++++++++++++++
 include/private/gcconfig.h | 49 --------------------------------------
 2 files changed, 46 insertions(+), 49 deletions(-)

diff --git a/include/private/gc_priv.h b/include/private/gc_priv.h
index f37f8a343..17a324ad5 100644
--- a/include/private/gc_priv.h
+++ b/include/private/gc_priv.h
@@ -1862,6 +1862,52 @@ GC_EXTERN size_t GC_real_page_size;
 #  define GC_real_page_size GC_page_size
 #endif
 
+/* Get heap memory from the OS.                                       */
+/* Note that sbrk()-like allocation is preferred, since it usually    */
+/* makes it possible to merge consecutively allocated chunks.         */
+/* It also avoids unintended recursion with REDIRECT_MALLOC macro     */
+/* defined.  GET_MEM() argument should be of size_t type and have no  */
+/* side-effect.  GET_MEM() returns HBLKSIZE-aligned chunk (NULL means */
+/* a failure).  In case of MMAP_SUPPORTED, the argument must also be  */
+/* a multiple of a physical page size.  GET_MEM is currently not      */
+/* assumed to retrieve zero-filled space.                             */
+/* TODO: Take advantage of GET_MEM() returning a zero-filled space.   */
+#if defined(CYGWIN32) || defined(MSWIN32)
+void *GC_win32_get_mem(size_t lb);
+#  define GET_MEM(lb) GC_win32_get_mem(lb)
+#  ifndef USE_WINALLOC
+#    define NEED_UNIX_GET_MEM
+#  endif
+#elif defined(MSWINCE)
+void *GC_wince_get_mem(size_t lb);
+#  define GET_MEM(lb) GC_wince_get_mem(lb)
+#elif defined(MSWIN_XBOX1)
+void *GC_durango_get_mem(size_t lb);
+#  define GET_MEM(lb) GC_durango_get_mem(lb)
+#elif defined(HAIKU)
+void *GC_haiku_get_mem(size_t lb);
+#  define GET_MEM(lb) GC_haiku_get_mem(lb)
+#elif defined(OS2)
+void *os2_alloc(size_t lb);
+#  define GET_MEM(lb)                                                  \
+    ((void *)HBLKPTR((ptr_t)os2_alloc(SIZET_SAT_ADD(lb, GC_page_size)) \
+                     + GC_page_size - 1))
+#elif defined(DOS4GW) || defined(EMBOX) || defined(KOS) || defined(NEXT) \
+    || defined(NONSTOP) || defined(RTEMS) || defined(__CC_ARM)           \
+    || (defined(SOLARIS) && !defined(USE_MMAP))
+/* TODO: Use page_alloc() directly on Embox.    */
+#  if defined(REDIRECT_MALLOC) && !defined(CPPCHECK)
+#    error Malloc redirection is unsupported
+#  endif
+#  define GET_MEM(lb)                                                  \
+    ((void *)HBLKPTR((ptr_t)calloc(1, SIZET_SAT_ADD(lb, GC_page_size)) \
+                     + GC_page_size - 1))
+#elif !defined(GET_MEM)
+void *GC_unix_get_mem(size_t lb);
+#  define GET_MEM(lb) GC_unix_get_mem(lb)
+#  define NEED_UNIX_GET_MEM
+#endif
+
 /* Round up allocation size to a multiple of a page size.       */
 /* GC_setpagesize() is assumed to be already invoked.           */
 #define ROUNDUP_PAGESIZE(lb) /* lb should have no side-effect */ \
diff --git a/include/private/gcconfig.h b/include/private/gcconfig.h
index edf2a6a83..019cc56e2 100644
--- a/include/private/gcconfig.h
+++ b/include/private/gcconfig.h
@@ -3391,55 +3391,6 @@ extern ptr_t GC_data_start;
 /* the client files those are using pthread_create and friends).    */
 #endif
 
-#ifdef GC_PRIVATE_H
-/* This relies on some type definitions from gc_priv.h, from where it */
-/* is normally included.  How to get heap memory from the OS:         */
-/* Note that sbrk()-like allocation is preferred, since it usually    */
-/* makes it possible to merge consecutively allocated chunks.         */
-/* It also avoids unintended recursion with REDIRECT_MALLOC macro     */
-/* defined.  GET_MEM() argument should be of size_t type and have no  */
-/* side-effect.  GET_MEM() returns HBLKSIZE-aligned chunk (NULL means */
-/* a failure).  In case of MMAP_SUPPORTED, the argument must also be  */
-/* a multiple of a physical page size.  GET_MEM is currently not      */
-/* assumed to retrieve zero-filled space.                             */
-/* TODO: Take advantage of GET_MEM() returning a zero-filled space.   */
-#  if defined(CYGWIN32) || defined(MSWIN32)
-void *GC_win32_get_mem(size_t lb);
-#    define GET_MEM(lb) GC_win32_get_mem(lb)
-#    ifndef USE_WINALLOC
-#      define NEED_UNIX_GET_MEM
-#    endif
-#  elif defined(MSWINCE)
-void *GC_wince_get_mem(size_t lb);
-#    define GET_MEM(lb) GC_wince_get_mem(lb)
-#  elif defined(MSWIN_XBOX1)
-void *GC_durango_get_mem(size_t lb);
-#    define GET_MEM(lb) GC_durango_get_mem(lb)
-#  elif defined(HAIKU)
-void *GC_haiku_get_mem(size_t lb);
-#    define GET_MEM(lb) GC_haiku_get_mem(lb)
-#  elif defined(OS2)
-void *os2_alloc(size_t lb);
-#    define GET_MEM(lb)                                                  \
-      ((void *)HBLKPTR((ptr_t)os2_alloc(SIZET_SAT_ADD(lb, GC_page_size)) \
-                       + GC_page_size - 1))
-#  elif defined(DOS4GW) || defined(EMBOX) || defined(KOS) || defined(NEXT) \
-      || defined(NONSTOP) || defined(RTEMS) || defined(__CC_ARM)           \
-      || (defined(SOLARIS) && !defined(USE_MMAP))
-/* TODO: Use page_alloc() directly on Embox.    */
-#    if defined(REDIRECT_MALLOC) && !defined(CPPCHECK)
-#      error Malloc redirection is unsupported
-#    endif
-#    define GET_MEM(lb)                                                  \
-      ((void *)HBLKPTR((ptr_t)calloc(1, SIZET_SAT_ADD(lb, GC_page_size)) \
-                       + GC_page_size - 1))
-#  elif !defined(GET_MEM)
-void *GC_unix_get_mem(size_t lb);
-#    define GET_MEM(lb) GC_unix_get_mem(lb)
-#    define NEED_UNIX_GET_MEM
-#  endif
-#endif /* GC_PRIVATE_H */
-
 EXTERN_C_END
 
 #endif /* GCCONFIG_H */