From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Maxime Devos Newsgroups: gmane.lisp.guile.devel Subject: Re: GC + Java finalization Date: Fri, 19 Nov 2021 13:13:01 +0000 Message-ID: <1cc3648e5196bf23023ec7a0ab95a9ad46f8554c.camel@telenet.be> References: <9ce77d5e08d50456eddc575179b68ac17afc9bf6.camel@hahnjo.de> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="14775"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Evolution 3.38.3-1 To: Jonas Hahnfeld , guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Fri Nov 19 14:16:59 2021 Return-path: Envelope-to: guile-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mo3lC-0003a8-ST for guile-devel@m.gmane-mx.org; Fri, 19 Nov 2021 14:16:58 +0100 Original-Received: from localhost ([::1]:36016 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mo3lB-0005Ot-Kg for guile-devel@m.gmane-mx.org; Fri, 19 Nov 2021 08:16:57 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:48882) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mo3hV-000304-Dm for guile-devel@gnu.org; Fri, 19 Nov 2021 08:13:09 -0500 Original-Received: from [2a02:1800:120:4::f00:14] (port=45554 helo=xavier.telenet-ops.be) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mo3hT-0006hx-CI for guile-devel@gnu.org; Fri, 19 Nov 2021 08:13:09 -0500 Original-Received: from ptr-bvsjgyhxw7psv60dyze.18120a2.ip6.access.telenet.be ([IPv6:2a02:1811:8c09:9d00:3c5f:2eff:feb0:ba5a]) by xavier.telenet-ops.be with bizsmtp id LDD12600U4UW6Th01DD1FQ; Fri, 19 Nov 2021 14:13:01 +0100 In-Reply-To: <9ce77d5e08d50456eddc575179b68ac17afc9bf6.camel@hahnjo.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telenet.be; s=r21; t=1637327581; bh=eR6r/JoOQevFqinqPs9oeDsrSAwmbkT2QKYXBOWbDW8=; h=Subject:From:To:Date:In-Reply-To:References; b=tK1lOcFllL+gQVr6w5/iUK77og7HSLyfGrc7u36sAd3Hp3Fms/eQKlYDEat+meHDr Lj+guz601030FZQzOd4W6nLHaKz2WHVfIRJnVX6ukq19LEzq7bE9jA1eWHHLY0YWJF NWwBSy3U9g1jqW6LpJ6fQvR7LQOM3wzkih3Ph9IRgL4xnKfRIVm5CSxmPKfWrnaS1B Hahw13CyPKisVZM4KE6LRvnP1/WtZcYBX0xNVRK8RfuQ5TPPIEBaxq/U5jl9Kx1LpH CzH0yaWCEdvCoYBGB4Ch80nR5Wol7jrLL+/gV1w4MdbiEksdqbttzE7nIF2j+SDOGx e0eJJy+ig/FEQ== X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a02:1800:120:4::f00:14 (failed) Received-SPF: pass client-ip=2a02:1800:120:4::f00:14; envelope-from=maximedevos@telenet.be; helo=xavier.telenet-ops.be X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Original-Sender: "guile-devel" Xref: news.gmane.io gmane.lisp.guile.devel:20956 Archived-At: Jonas Hahnfeld schreef op do 15-07-2021 om 20:44 [+0200]: > 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); >From the manual (about scm_gc_calloc & friends): ‘Memory blocks allocated this way may be released explicitly; however, this is not strictly needed, and we recommend _not_ calling ‘scm_gc_free’. All memory allocated with ‘scm_gc_malloc’ or ‘scm_gc_malloc_pointerless’ is automatically reclaimed when the garbage collector no longer sees any live reference to it(1).’ As such, I'd recommend simply dropping the scm_gc_free (here and in other places), if the scm_gc_free was problematic because of Java finalization reasons. >    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)); If the regex why scm_gc_malloc_pointerless -> scm_malloc? Is rx not pointerless? You coud simply ... > -      scm_gc_free (rx, sizeof(regex_t), "regex"); > +      free (rx); drop the scm_gc_free AFAIK. Greetings, Maxime