1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-06 12:10:28 +02:00

Remove scm_gc_realloc

Whippet may add a shrink interface, if it is needed.

* doc/ref/api-memory.texi (Memory Blocks): Remove some 1.8 references.
Remove discussion of scm_gc_malloc.  Remove discussion of scm_gc_free.
* libguile/gc.h:
* libguile/gc-malloc.c (scm_gc_malloc): Remove.
This commit is contained in:
Andy Wingo 2025-04-30 11:30:52 +02:00
parent a13c30eeba
commit dd0e455755
3 changed files with 7 additions and 32 deletions

View file

@ -116,25 +116,16 @@ garbage collector and the error reporting system.
Memory blocks that are associated with Scheme objects (for example a
foreign object) should be allocated with @code{scm_gc_malloc} or
@code{scm_gc_malloc_pointerless}. These two functions will either
return a valid pointer or signal an error. Memory blocks allocated this
way may be released explicitly; however, this is not strictly needed,
and we recommend @emph{not} calling @code{scm_gc_free}. All memory
allocated with @code{scm_gc_malloc} or @code{scm_gc_malloc_pointerless}
is automatically reclaimed when the garbage collector no longer sees any
live reference to it@footnote{In Guile up to version 1.8, memory
allocated with @code{scm_gc_malloc} @emph{had} to be freed with
@code{scm_gc_free}.}.
return a valid pointer or signal an error. All memory allocated with
@code{scm_gc_malloc} or @code{scm_gc_malloc_pointerless} is
automatically reclaimed when the garbage collector no longer sees any
live reference to it.
When garbage collection occurs, Guile will visit the words in memory
allocated with @code{scm_gc_malloc}, looking for live pointers. This
means that if @code{scm_gc_malloc}-allocated memory contains a pointer
to some other part of the memory, the garbage collector notices it and
prevents it from being reclaimed@footnote{In Guile up to 1.8, memory
allocated with @code{scm_gc_malloc} was @emph{not} visited by the
collector in the mark phase. Consequently, the GC had to be told
explicitly about pointers to live objects contained in the memory block,
e.g., @i{via} SMOB mark functions (@pxref{Smobs,
@code{scm_set_smob_mark}})}. Conversely, memory allocated with
prevents it from being reclaimed. Conversely, memory allocated with
@code{scm_gc_malloc_pointerless} is assumed to be ``pointer-less'' and
is not scanned for pointers.
@ -145,10 +136,8 @@ an error. However, it will not assume that the new memory block can
be freed by a garbage collection. The memory must be explicitly freed
with @code{free}.
There is also @code{scm_gc_realloc} and @code{scm_realloc}, to be used
in place of @code{realloc} when appropriate, and @code{scm_gc_calloc}
and @code{scm_calloc}, to be used in place of @code{calloc} when
appropriate.
There is also @code{scm_gc_calloc} and @code{scm_calloc}, to be used in
place of @code{calloc} when appropriate.
The function @code{scm_dynwind_free} can be useful when memory should be
freed with libc's @code{free} when leaving a dynwind context,
@ -191,7 +180,6 @@ This function will call @code{scm_gc_register_allocation}.
@deftypefn {C Function} {void *} scm_gc_malloc (size_t @var{size}, const char *@var{what})
@deftypefnx {C Function} {void *} scm_gc_malloc_pointerless (size_t @var{size}, const char *@var{what})
@deftypefnx {C Function} {void *} scm_gc_realloc (void *@var{mem}, size_t @var{old_size}, size_t @var{new_size}, const char *@var{what});
@deftypefnx {C Function} {void *} scm_gc_calloc (size_t @var{size}, const char *@var{what})
Allocate @var{size} bytes of automatically-managed memory. The memory
is automatically freed when no longer referenced from any live memory
@ -202,10 +190,6 @@ allocated with @code{scm_gc_malloc} or @code{scm_gc_calloc}, looking for
pointers to other memory allocations that are managed by the GC. In
contrast, memory allocated by @code{scm_gc_malloc_pointerless} is not
scanned for pointers.
The @code{scm_gc_realloc} call preserves the ``pointerlessness'' of the
memory area pointed to by @var{mem}. Note that you need to pass the old
size of a reallocated memory block as well. See below for a motivation.
@end deftypefn

View file

@ -173,13 +173,6 @@ scm_gc_calloc (size_t size, const char *what)
return scm_gc_malloc (size, what);
}
void *
scm_gc_realloc (void *mem, size_t old_size, size_t new_size, const char *what)
{
/* FIXME: Remove me. */
return GC_REALLOC (mem, new_size ? new_size : sizeof (void *));
}
char *
scm_gc_strndup (const char *str, size_t n, const char *what)
{

View file

@ -128,8 +128,6 @@ SCM_API void *scm_gc_calloc (size_t size, const char *what)
SCM_MALLOC;
SCM_API void *scm_gc_malloc (size_t size, const char *what)
SCM_MALLOC;
SCM_API void *scm_gc_realloc (void *mem, size_t old_size,
size_t new_size, const char *what);
SCM_API char *scm_gc_strdup (const char *str, const char *what)
SCM_MALLOC;
SCM_API char *scm_gc_strndup (const char *str, size_t n, const char *what)