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

Remove SMOB mark functions

Oh yeah!  They are almost impossible to use correctly as-is, have mostly
disappeared in practice (I am aware of only two users), have the wrong
interface for moving collectors, and current usage has cemented smobs as
conservatively-marked objects.  In order to move forward with Whippet,
they have to go!

* libguile/deprecated.h (SCM_SMOB_MARK, SCM_GLOBAL_SMOB_MARK, scm_mark0)
(scm_markcdr, scm_free0, scm_set_smob_mark, scm_gc_mark): Remove these,
leaving defines to indicate that users should talk to guile-devel to
figure out what to do.
* libguile/smob.h: Remove interfaces relating to mark functions.
(scm_new_double_smob, scm_new_smob): Make not inline
* libguile/smob.c: Remove mark functions from here.
(scm_new_smob): Out-of-line-only definition.
(scm_smob_prehistory): Don't create a new GC kind for smobs.

* test-suite/standalone/test-smob-mark-race.c:
* test-suite/standalone/test-smob-mark.c: Remove.
* test-suite/standalone/Makefile.am: Update.
This commit is contained in:
Andy Wingo 2025-05-15 10:31:12 +02:00
parent 2bfc66554e
commit 0e8c6b6727
6 changed files with 26 additions and 457 deletions

View file

@ -1,6 +1,6 @@
## Process this file with automake to produce Makefile.in.
##
## Copyright 2003-2014, 2020-2024 Free Software Foundation, Inc.
## Copyright 2003-2014, 2020-2025 Free Software Foundation, Inc.
##
## This file is part of GUILE.
##
@ -292,18 +292,6 @@ EXTRA_DIST += test-with-guile-module.c test-scm-with-guile.c
endif
test_smob_mark_SOURCES = test-smob-mark.c
test_smob_mark_CFLAGS = ${test_cflags}
test_smob_mark_LDADD = $(LIBGUILE_LDADD) $(top_builddir)/lib/libgnu.la
check_PROGRAMS += test-smob-mark
TESTS += test-smob-mark
test_smob_mark_race_SOURCES = test-smob-mark-race.c
test_smob_mark_race_CFLAGS = ${test_cflags}
test_smob_mark_race_LDADD = $(LIBGUILE_LDADD) $(top_builddir)/lib/libgnu.la
check_PROGRAMS += test-smob-mark-race
TESTS += test-smob-mark-race
check_SCRIPTS += test-stack-overflow
TESTS += test-stack-overflow

View file

@ -1,66 +0,0 @@
/* Copyright 2016
Free Software Foundation, Inc.
This file is part of Guile.
Guile is free software: you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Guile is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public
License along with Guile. If not, see
<https://www.gnu.org/licenses/>. */
#if HAVE_CONFIG_H
#include <config.h>
#endif
#undef NDEBUG
#include <libguile.h>
#include <assert.h>
static SCM
mark_smob (SCM smob)
{
assert (SCM_SMOB_DATA (smob) == 1);
return SCM_BOOL_F;
}
static size_t
finalize_smob (SCM smob)
{
assert (SCM_SMOB_DATA (smob) == 1);
SCM_SET_SMOB_DATA (smob, 0);
/* Allocate a bit in the hopes of triggering a new GC, making the
marker race with the finalizer. */
scm_cons (SCM_BOOL_F, SCM_BOOL_F);
return 0;
}
static void
tests (void *data, int argc, char **argv)
{
scm_t_bits tc16;
int i;
tc16 = scm_make_smob_type ("smob with finalizer", 0);
scm_set_smob_mark (tc16, mark_smob);
scm_set_smob_free (tc16, finalize_smob);
for (i = 0; i < 1000 * 1000; i++)
scm_new_smob (tc16, 1);
}
int
main (int argc, char *argv[])
{
scm_boot_guile (argc, argv, tests, NULL);
return 0;
}

View file

@ -1,136 +0,0 @@
/* Copyright 2013-2014,2018,2025
Free Software Foundation, Inc.
This file is part of Guile.
Guile is free software: you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Guile is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public
License along with Guile. If not, see
<https://www.gnu.org/licenses/>. */
#if HAVE_CONFIG_H
#include <config.h>
#endif
#undef NDEBUG
#include <assert.h>
#include <libguile.h>
#include <stdio.h>
#include <stdlib.h>
#define SMOBS_COUNT (10000)
struct x_tag
{
SCM scm_value;
int c_value;
};
typedef struct x_tag x_t;
unsigned int mark_call_count = 0;
static scm_t_bits x_tag;
static SCM make_x (void);
static SCM mark_x (SCM x);
static int print_x (SCM x, SCM port, scm_print_state * pstate);
static size_t free_x (SCM x);
static void init_smob_type (void);
static void test_scm_smob_mark (void);
static SCM
make_x ()
{
static int i = 0;
SCM s_x;
x_t *c_x;
i++;
c_x = (x_t *) scm_malloc (sizeof (x_t));
c_x->scm_value = scm_from_int (i);
c_x->c_value = i;
SCM_NEWSMOB (s_x, x_tag, c_x);
return s_x;
}
static SCM
mark_x (SCM x)
{
x_t *c_x;
c_x = (x_t *) SCM_SMOB_DATA (x);
scm_gc_mark (c_x->scm_value);
mark_call_count++;
return SCM_BOOL_F;
}
static size_t
free_x (SCM x)
{
x_t *c_x;
c_x = (x_t *) SCM_SMOB_DATA (x);
free (c_x);
c_x = NULL;
return 0;
}
static int
print_x (SCM x, SCM port, scm_print_state * pstate SCM_UNUSED)
{
x_t *c_x = (x_t *) SCM_SMOB_DATA (x);
scm_puts ("#<x ", port);
if (c_x == (x_t *) NULL)
scm_puts ("(freed)", port);
else
scm_write (c_x->scm_value, port);
scm_puts (">", port);
return 1;
}
static void
test_scm_smob_mark ()
{
int i;
mark_call_count = 0;
for (i = 0; i < SMOBS_COUNT; i++)
make_x ();
scm_gc ();
if (mark_call_count < SMOBS_COUNT)
{
fprintf (stderr, "FAIL: SMOB mark function called for each SMOB\n");
exit (EXIT_FAILURE);
}
}
static void
init_smob_type ()
{
x_tag = scm_make_smob_type ("x", sizeof (x_t));
scm_set_smob_free (x_tag, free_x);
scm_set_smob_print (x_tag, print_x);
scm_set_smob_mark (x_tag, mark_x);
}
static void
tests (void *data, int argc, char **argv)
{
init_smob_type ();
test_scm_smob_mark ();
}
int
main (int argc, char *argv[])
{
scm_boot_guile (argc, argv, tests, NULL);
return 0;
}