garbage: allow for building ecl without bdwgc and with nogc

In that case we use a dummy object nogc.o that contains stubs for GC-related
functions. It also defines a substitute module.
This commit is contained in:
Daniel Kochmański 2026-02-27 12:14:39 +01:00
parent 0c8e6b38b9
commit 6be00c50c5
7 changed files with 82 additions and 17 deletions

68
src/c/mem_nogc.d Normal file
View file

@ -0,0 +1,68 @@
/* -*- Mode: C; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/* vim: set filetype=c tabstop=2 shiftwidth=2 expandtab: */
/* mem_nogc.d - this is a reference of what GC should minimally implement */
/* -- imports ---------------------------------------------------------------- */
#include <ecl/ecl.h>
#include <ecl/ecl-inl.h>
#include <ecl/internal.h>
#include <ecl/external.h>
/* -- implementation --------------------------------------------------------- */
void _ecl_set_max_heap_size(size_t new_size) {}
void ecl_register_root(cl_object *p) {}
void ecl_set_finalizer_unprotected(cl_object o, cl_object f) {}
cl_object
si_gc(cl_narg narg, ...)
{
const cl_env_ptr the_env = ecl_process_env();
ecl_return0(the_env);
}
cl_object
si_get_finalizer(cl_object o)
{
const cl_env_ptr the_env = ecl_process_env();
ecl_return0(the_env);
}
cl_object
si_set_finalizer(cl_object o, cl_object f)
{
const cl_env_ptr the_env = ecl_process_env();
ecl_return0(the_env);
}
cl_object
si_make_weak_pointer(cl_object o)
{
const cl_env_ptr the_env = ecl_process_env();
ecl_return1(the_env, ECL_NIL);
}
cl_object
si_weak_pointer_value(cl_object o)
{
const cl_env_ptr the_env = ecl_process_env();
ecl_return2(the_env, ECL_NIL, ECL_NIL);
}
ecl_def_ct_base_string(str_gc, "NO-GC", 5, static, const);
static struct ecl_module module_gc = {
.name = str_gc,
.create = ecl_module_no_op,
.enable = ecl_module_no_op,
.init_env = ecl_module_no_op_env,
.init_cpu = ecl_module_no_op_cpu,
.free_cpu = ecl_module_no_op_cpu,
.free_env = ecl_module_no_op_env,
.disable = ecl_module_no_op,
.destroy = ecl_module_no_op
};
cl_object ecl_module_gc = (cl_object)&module_gc;

View file

@ -610,8 +610,10 @@ asynchronous_signal_servicing_thread()
interrupt_signal =
ecl_option_values[ECL_OPT_THREAD_INTERRUPT_SIGNAL];
sigdelset(&handled_set, interrupt_signal);
#ifdef GBC_BOEHM
sigdelset(&handled_set, GC_get_suspend_signal());
sigdelset(&handled_set, GC_get_thr_restart_signal());
#endif /* GBC_BOEHM */
sigdelset(&handled_set, SIGSEGV);
sigdelset(&handled_set, SIGBUS);
}

9
src/configure vendored
View file

@ -7214,7 +7214,7 @@ if test "${enable_threads}" = "yes" ; then
as_fn_error $? "Threads aren't supported on this system." "$LINENO" 5
else
LIBS="${THREAD_LIBS} ${LIBS}"
CFLAGS="${CFLAGS} ${THREAD_CFLAGS} -DGC_NO_THREAD_REDIRECTS"
CFLAGS="${CFLAGS} ${THREAD_CFLAGS}"
ac_fn_c_check_func "$LINENO" "pthread_rwlock_init" "ac_cv_func_pthread_rwlock_init"
if test "x$ac_cv_func_pthread_rwlock_init" = xyes
@ -7271,7 +7271,12 @@ else
fi
if test ${enable_boehm} = "no" ; then
as_fn_error $? "Boehm GC library is currently needed to build ECL" "$LINENO" 5;
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: WARNING: Building ECL without Boehm GC library" >&5
printf "%s\n" "$as_me: WARNING: Building ECL without Boehm GC library" >&2;};
LSP_FEATURES="${LSP_FEATURES} :dummy-gc"
EXTRA_OBJS="${EXTRA_OBJS} mem_nogc.${OBJEXT}"
else

View file

@ -602,7 +602,9 @@ fi
dnl ----------------------------------------------------------------------
dnl Boehm-Weiser garbage collector
if test ${enable_boehm} = "no" ; then
AC_MSG_ERROR([Boehm GC library is currently needed to build ECL]);
AC_MSG_WARN([Building ECL without Boehm GC library]);
ECL_ADD_FEATURE(dummy-gc)
EXTRA_OBJS="${EXTRA_OBJS} mem_nogc.${OBJEXT}"
else
ECL_BOEHM_GC
ECL_ADD_FEATURE(boehm-gc)

View file

@ -798,14 +798,12 @@ extern ECL_API cl_object cl_format _ECL_ARGS((cl_narg narg, cl_object stream, cl
#define GC_enabled() !GC_is_disabled()
#define GC_enable() GC_enable()
#define GC_disable() GC_disable()
extern ECL_API void ecl_register_root(cl_object *p);
extern ECL_API cl_object si_gc(cl_narg narg, ...);
extern ECL_API cl_object si_gc_dump(void);
extern ECL_API cl_object si_gc_stats(cl_object enable);
#else
# error "IMPLEMENT ME!"
#endif /* GBC_BOEHM */
extern ECL_API void ecl_register_root(cl_object *p);
extern ECL_API cl_object si_gc(cl_narg narg, ...);
/* gfun.c */

View file

@ -59,9 +59,7 @@ extern void _ecl_dealloc_env(cl_env_ptr);
/* mem_bdwgc.d */
#ifdef GBC_BOEHM
#define ECL_COMPACT_OBJECT_EXTRA(x) ((void*)((x)->array.displaced))
#endif
extern void _ecl_set_max_heap_size(size_t new_size);
extern cl_object ecl_alloc_bytecodes(cl_index data_size, cl_index code_size);
extern cl_index ecl_object_byte_size(cl_type t);

View file

@ -109,14 +109,6 @@ Returns, as a string, the version of the software under which ECL runs."
aux
nil))))
;;
;; * Set up some room
;;
#-boehm-gc
(progn
(sys::allocate 'CONS 200)
(sys::allocate 'BASE-STRING 40))
;;
;; * Set configuration pathnames. Notice the trailing slash!
;; Otherwise it would not be a directory.