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

Don't run finalizers until Guile is initialized

Prevents a problem where with-exception-handler isn't defined yet by the
time the first finalizer gets kicked off (it's a file port, probably one
that is closed already...)

* libguile/finalizers.h:
* libguile/init.c (scm_i_init_guile):
* libguile/finalizers.c (queue_finalizer_async): Mark maybe-unused.
(scm_init_finalizers): Rework to only enable notification when Guile is
finished initializing.
This commit is contained in:
Andy Wingo 2025-05-04 09:12:52 +02:00
parent 4f8d4e6c34
commit 17ca7a928e
3 changed files with 17 additions and 18 deletions

View file

@ -267,6 +267,8 @@ run_finalizers_async_thunk (void)
* scm_run_finalizers() at the next SCM_TICK in this thread.
*/
static void
queue_finalizer_async (struct gc_heap *heap, size_t count) SCM_UNUSED;
static void
queue_finalizer_async (struct gc_heap *heap, size_t count)
{
scm_thread *t = SCM_I_CURRENT_THREAD;
@ -520,18 +522,6 @@ scm_register_finalizers (void)
NULL);
}
void
scm_init_finalizers (void)
{
/* When the async is to run, the cdr of the pair gets set to the
asyncs queue of the current thread. */
run_finalizers_subr = scm_c_make_gsubr ("%run-finalizers", 0, 0, 0,
run_finalizers_async_thunk);
if (automatic_finalization_p)
gc_set_finalizer_callback (the_gc_heap, queue_finalizer_async);
}
static void
scm_init_finalizers_module (void)
{
@ -541,10 +531,21 @@ scm_init_finalizers_module (void)
}
void
scm_init_finalizer_thread (void)
scm_init_finalizers (void)
{
#if SCM_USE_PTHREAD_THREADS
/* When the async is to run, the cdr of the pair gets set to the
asyncs queue of the current thread. */
run_finalizers_subr = scm_c_make_gsubr ("%run-finalizers", 0, 0, 0,
run_finalizers_async_thunk);
if (automatic_finalization_p)
gc_set_finalizer_callback (the_gc_heap, spawn_finalizer_thread);
{
#if SCM_USE_PTHREAD_THREADS
gc_set_finalizer_callback (the_gc_heap, spawn_finalizer_thread);
#else
gc_set_finalizer_callback (the_gc_heap, queue_finalizer_async);
#endif
}
scm_run_finalizers ();
}