wingo pushed a commit to branch wip-whippet in repository guile. commit 290a57b1b0bdc88c4595db5c337090fd2213243d Author: Andy Wingo <wi...@pobox.com> AuthorDate: Fri Jun 20 11:07:34 2025 +0200
Add scm_allocate_{pointerless,tagged,sloppy} * libguile/gc-inline.h (scm_inline_allocate_pointerless): (scm_inline_allocate_tagged): (scm_inline_allocate_sloppy): * libguile/gc.h: * libguile/gc-malloc.c (scm_allocate_pointerless): (scm_allocate_tagged): (scm_allocate_sloppy): New functions. (scm_gc_malloc): (scm_gc_malloc_pointerless): Dispatch to scm_allocate functions. --- libguile/gc-inline.h | 21 +++++++++++++++++++++ libguile/gc-malloc.c | 26 +++++++++++++++++++++++--- libguile/gc.h | 5 +++++ 3 files changed, 49 insertions(+), 3 deletions(-) diff --git a/libguile/gc-inline.h b/libguile/gc-inline.h index 2949d335f..6761a78ef 100644 --- a/libguile/gc-inline.h +++ b/libguile/gc-inline.h @@ -45,6 +45,27 @@ +static inline void * +scm_inline_allocate_pointerless (scm_thread *thread, size_t bytes) +{ + return gc_allocate (thread->mutator, bytes, + GC_ALLOCATION_UNTAGGED_POINTERLESS); +} + +static inline void * +scm_inline_allocate_tagged (scm_thread *thread, size_t bytes) +{ + return gc_allocate (thread->mutator, bytes, + GC_ALLOCATION_TAGGED); +} + +static inline void * +scm_inline_allocate_sloppy (scm_thread *thread, size_t bytes) +{ + return gc_allocate (thread->mutator, bytes, + GC_ALLOCATION_UNTAGGED_CONSERVATIVE); +} + static inline void * scm_inline_gc_malloc_pointerless (scm_thread *thread, size_t bytes) { diff --git a/libguile/gc-malloc.c b/libguile/gc-malloc.c index 69aeebf55..30a8ad089 100644 --- a/libguile/gc-malloc.c +++ b/libguile/gc-malloc.c @@ -149,6 +149,27 @@ scm_gc_unregister_collectable_memory (void *mem, size_t size, const char *what) { } +void * +scm_allocate_pointerless (struct scm_thread *thr, size_t size) +{ + if (!size) abort(); + return scm_inline_allocate_pointerless (thr, size); +} + +void * +scm_allocate_tagged (struct scm_thread *thr, size_t size) +{ + if (!size) abort(); + return scm_inline_allocate_tagged (thr, size); +} + +void * +scm_allocate_sloppy (struct scm_thread *thr, size_t size) +{ + if (!size) abort(); + return scm_inline_allocate_sloppy (thr, size); +} + /* Allocate SIZE bytes of memory whose contents should not be scanned for pointers (useful, e.g., for strings). Note though that this memory is *not* cleared; be sure to initialize it to prevent @@ -156,14 +177,13 @@ scm_gc_unregister_collectable_memory (void *mem, size_t size, const char *what) void * scm_gc_malloc_pointerless (size_t size, const char *what) { - return scm_inline_gc_malloc_pointerless (SCM_I_CURRENT_THREAD, - size ? size : 1); + return scm_allocate_pointerless (SCM_I_CURRENT_THREAD, size ? size : 1); } void * scm_gc_malloc (size_t size, const char *what) { - return scm_inline_gc_malloc (SCM_I_CURRENT_THREAD, size ? size : 1); + return scm_allocate_sloppy (SCM_I_CURRENT_THREAD, size ? size : 1); } void * diff --git a/libguile/gc.h b/libguile/gc.h index 62505691b..91da59946 100644 --- a/libguile/gc.h +++ b/libguile/gc.h @@ -120,6 +120,11 @@ SCM_API void scm_gc_register_collectable_memory (void *mem, size_t size, const char *what); SCM_API void scm_gc_unregister_collectable_memory (void *mem, size_t size, const char *what); + +SCM_API void *scm_allocate_pointerless (struct scm_thread *thr, size_t size); +SCM_API void *scm_allocate_tagged (struct scm_thread *thr, size_t size); +SCM_API void *scm_allocate_sloppy (struct scm_thread *thr, size_t size); + SCM_API void *scm_gc_malloc_pointerless (size_t size, const char *what) SCM_MALLOC; SCM_API void *scm_gc_calloc (size_t size, const char *what)