From fecd6c00e42f884c7b83aa42e4525ae1b40f0710 Mon Sep 17 00:00:00 2001 From: Andy Wingo Date: Mon, 30 Jun 2025 09:43:34 +0200 Subject: [PATCH] Pin bytevector parents * libguile/bytevectors.c (make_bytevector_from_buffer): If there is a parent GC-managed object for the buffer, pin that object so that the buffer remains valid. --- libguile/bytevectors.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/libguile/bytevectors.c b/libguile/bytevectors.c index ee73b03bb..82132193c 100644 --- a/libguile/bytevectors.c +++ b/libguile/bytevectors.c @@ -258,9 +258,9 @@ make_bytevector_from_buffer (size_t len, void *contents, size_t bytes_per_elt = scm_i_array_element_type_sizes[element_type]/8; size_t c_len = len * bytes_per_elt; + scm_thread *thr = SCM_I_CURRENT_THREAD; struct scm_bytevector *bv = - scm_allocate_tagged (SCM_I_CURRENT_THREAD, - sizeof (struct scm_bytevector)); + scm_allocate_tagged (thr, sizeof (struct scm_bytevector)); scm_t_bits flags = is_immutable ? SCM_F_BYTEVECTOR_IMMUTABLE : 0; bv->tag_flags_and_element_type = make_bytevector_tag (flags, element_type); @@ -268,6 +268,9 @@ make_bytevector_from_buffer (size_t len, void *contents, bv->contents = contents; bv->parent = parent; + if (scm_is_true (parent)) + scm_gc_pin_object (thr, parent); + return bv; }