From 33af6a98c6801e7b4880d1d3f78f7e2097c2174e Mon Sep 17 00:00:00 2001 From: Jonas Hahnfeld Date: Fri, 2 Jul 2021 23:03:17 +0200 Subject: [PATCH 2/3] Avoid matching calls of scm_gc_free There is no point in registering memory with the garbage collector if it doesn't need to do its job. In fact, calling scm_gc_free in a free function is wrong because it relies on Java finalization. * libguile/random.c (scm_c_random_bignum): Replace matching calls of scm_gc_calloc and scm_gc_free. * libguile/regex-posix.c (scm_make_regexp, regex_free): Avoid call of scm_gc_free in free function. * test-suite/standalone/test-smob-mark.c (make_x, free_x): Avoid call of scm_gc_free in free function. --- THANKS | 1 + libguile/random.c | 8 ++------ libguile/regex-posix.c | 6 +++--- test-suite/standalone/test-smob-mark.c | 4 ++-- 4 files changed, 8 insertions(+), 11 deletions(-) diff --git a/THANKS b/THANKS index aa4877e95..786b65d1a 100644 --- a/THANKS +++ b/THANKS @@ -13,6 +13,7 @@ Contributors since the last release: Volker Grabsch Julian Graham Michael Gran + Jonas Hahnfeld Daniel Hartwig No Itisnt Neil Jerram diff --git a/libguile/random.c b/libguile/random.c index 63da7f5d6..ac400a9fd 100644 --- a/libguile/random.c +++ b/libguile/random.c @@ -324,9 +324,7 @@ scm_c_random_bignum (scm_t_rstate *state, SCM m) /* we know the result will be this big */ mpz_realloc2 (SCM_I_BIG_MPZ (result), m_bits); - random_chunks = - (uint32_t *) scm_gc_calloc (num_chunks * sizeof (uint32_t), - "random bignum chunks"); + random_chunks = (uint32_t *) scm_calloc (num_chunks * sizeof (uint32_t)); do { @@ -363,9 +361,7 @@ scm_c_random_bignum (scm_t_rstate *state, SCM m) /* if result >= m, regenerate it (it is important to regenerate all bits in order not to get a distorted distribution) */ } while (mpz_cmp (SCM_I_BIG_MPZ (result), SCM_I_BIG_MPZ (m)) >= 0); - scm_gc_free (random_chunks, - num_chunks * sizeof (uint32_t), - "random bignum chunks"); + free (random_chunks); return scm_i_normbig (result); } diff --git a/libguile/regex-posix.c b/libguile/regex-posix.c index a08da02db..36bb639e0 100644 --- a/libguile/regex-posix.c +++ b/libguile/regex-posix.c @@ -67,7 +67,7 @@ static size_t regex_free (SCM obj) { regfree (SCM_RGX (obj)); - scm_gc_free (SCM_RGX (obj), sizeof(regex_t), "regex"); + free (SCM_RGX (obj)); return 0; } @@ -164,7 +164,7 @@ SCM_DEFINE (scm_make_regexp, "make-regexp", 1, 0, 1, flag = SCM_CDR (flag); } - rx = scm_gc_malloc_pointerless (sizeof (regex_t), "regex"); + rx = scm_malloc (sizeof (regex_t)); c_pat = scm_to_locale_string (pat); status = regcomp (rx, c_pat, /* Make sure they're not passing REG_NOSUB; @@ -174,7 +174,7 @@ SCM_DEFINE (scm_make_regexp, "make-regexp", 1, 0, 1, if (status != 0) { SCM errmsg = scm_regexp_error_msg (status, rx); - scm_gc_free (rx, sizeof(regex_t), "regex"); + free (rx); scm_error_scm (scm_regexp_error_key, scm_from_utf8_string (FUNC_NAME), errmsg, diff --git a/test-suite/standalone/test-smob-mark.c b/test-suite/standalone/test-smob-mark.c index 586a2b081..edbb51f89 100644 --- a/test-suite/standalone/test-smob-mark.c +++ b/test-suite/standalone/test-smob-mark.c @@ -56,7 +56,7 @@ make_x () x_t *c_x; i++; - c_x = (x_t *) scm_gc_malloc (sizeof (x_t), "x"); + 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); @@ -78,7 +78,7 @@ free_x (SCM x) { x_t *c_x; c_x = (x_t *) SCM_SMOB_DATA (x); - scm_gc_free (c_x, sizeof (x_t), "x"); + free (c_x); SCM_SET_SMOB_DATA (x, NULL); return 0; } -- 2.32.0