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

Move r6rs-ports off scm_gc_realloc

* libguile/r6rs-ports.c (grow_byte_buffer, shrink_byte_buffer): New
helpers.
* libguile/r6rs-ports.c (bytevector_output_port_buffer_grow):
(bytevector_output_port_procedure): Use new helpers.
This commit is contained in:
Andy Wingo 2025-04-29 10:53:50 +02:00
parent 4ccd57aca8
commit 2bfc1779c5

View file

@ -1,4 +1,4 @@
/* Copyright 2009-2011,2013-2015,2018-2019,2023,2024 /* Copyright 2009-2011,2013-2015,2018-2019,2023,2024,2025
Free Software Foundation, Inc. Free Software Foundation, Inc.
This file is part of Guile. This file is part of Guile.
@ -515,6 +515,26 @@ SCM_DEFINE (scm_unget_bytevector, "unget-bytevector", 2, 2, 0,
#undef FUNC_NAME #undef FUNC_NAME
static void*
grow_byte_buffer (void *p, size_t old_size, size_t new_size)
{
void *new_p = scm_gc_malloc_pointerless (new_size, NULL);
memcpy (new_p, p, old_size);
return new_p;
}
static void*
shrink_byte_buffer (void *p, size_t old_size, size_t new_size)
{
void *new_p = scm_gc_malloc_pointerless (new_size, NULL);
memcpy (new_p, p, new_size);
return new_p;
}
/* Bytevector output port. */ /* Bytevector output port. */
@ -581,8 +601,7 @@ bytevector_output_port_buffer_grow (scm_t_bytevector_output_port_buffer *buf,
if (INT_ADD_OVERFLOW (buf->total_len, buf->total_len)) if (INT_ADD_OVERFLOW (buf->total_len, buf->total_len))
scm_num_overflow ("bytevector_output_port_buffer_grow"); scm_num_overflow ("bytevector_output_port_buffer_grow");
new_size = MAX (min_size, buf->total_len * 2); new_size = MAX (min_size, buf->total_len * 2);
new_buf = scm_gc_realloc ((void *) buf->buffer, buf->total_len, new_buf = grow_byte_buffer (buf->buffer, buf->total_len, new_size);
new_size, SCM_GC_BYTEVECTOR_OUTPUT_PORT);
} }
else else
{ {
@ -696,10 +715,9 @@ SCM_SMOB_APPLY (bytevector_output_port_procedure,
{ {
if (result_buf.total_len > result_buf.len) if (result_buf.total_len > result_buf.len)
/* Shrink the buffer. */ /* Shrink the buffer. */
result_buf.buffer = scm_gc_realloc ((void *) result_buf.buffer, result_buf.buffer = shrink_byte_buffer (result_buf.buffer,
result_buf.total_len, result_buf.total_len,
result_buf.len, result_buf.len);
SCM_GC_BYTEVECTOR_OUTPUT_PORT);
bv = scm_c_take_gc_bytevector ((signed char *) result_buf.buffer, bv = scm_c_take_gc_bytevector ((signed char *) result_buf.buffer,
result_buf.len, SCM_BOOL_F); result_buf.len, SCM_BOOL_F);