Skip to content

Commit

Permalink
Move GET_MEM() definition to gc_priv.h
Browse files Browse the repository at this point in the history
(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.
  • Loading branch information
ivmai committed Nov 26, 2024
1 parent d61d065 commit 517ca84
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 49 deletions.
46 changes: 46 additions & 0 deletions include/private/gc_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */ \
Expand Down
49 changes: 0 additions & 49 deletions include/private/gcconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

0 comments on commit 517ca84

Please sign in to comment.