From: Ian Price <ianprice90@googlemail.com>
To: Stefan Israelsson Tampe <stefan.itampe@gmail.com>
Cc: 9900@debbugs.gnu.org
Subject: bug#9900: Using a guardian on a value in a weak hash
Date: Sat, 29 Oct 2011 19:51:11 +0100 [thread overview]
Message-ID: <m3ty6rbpi8.fsf@googlemail.com> (raw)
In-Reply-To: <CAGua6m2S1Zq0e+Y5=54RjQC2PHy-rScJqEfDZnTrOCN0CTUxTg@mail.gmail.com> (Stefan Israelsson Tampe's message of "Sat, 29 Oct 2011 19:42:13 +0200")
Stefan Israelsson Tampe <stefan.itampe@gmail.com> writes:
> f below in the code is referencing a direct function and not a closure that is not gc:able it seams
> although there is no references to it. It looks like the loaded file references that code and it will not be
> gc:ed until the same file is loaded again (make sure to save the old guardian so that one can inspect)
This does seem to be the case
scheme@(guile−user)> (load "gcbug.scm")
;;; note: source file /tmp/gcbug.scm
;;; newer than compiled /home/ian/.cache/guile/ccache/2.0−LE−4−2.0/tmp/gcbug.scm.go
;;; note: auto−compilation is enabled, set GUILE_AUTO_COMPILE=0
;;; or pass the −−no−auto−compile argument to disable.
;;; compiling /tmp/gcbug.scm
;;; compiled /home/ian/.cache/guile/ccache/2.0−LE−4−2.0/tmp/gcbug.scm.go
#<weak−key−hash−table 1/31>
#<weak−key−hash−table 0/31>
#f
scheme@(guile−user)> guardian
$1 = #<guardian 8503710 (reachable: 1 unreachable: 0)>
scheme@(guile−user)> (guardian)
$2 = #f
scheme@(guile−user)> (guardian)
$3 = #f
scheme@(guile−user)> (define k guardian)
scheme@(guile−user)> (load "gcbug.scm")
#<weak−key−hash−table 1/31>
#<weak−key−hash−table 0/31>
#f
scheme@(guile−user)> (guardian)
$4 = #f
scheme@(guile−user)> (guardian)
$5 = #f
scheme@(guile−user)> (k)
$6 = (foo . foo)
scheme@(guile−user)> (k)
$7 = #f
scheme@(guile−user)>
here, f is the pair (foo . foo).
> The weak key hastable is wrongly used and swaping key and value gives
> correct behavior
I disagree. While I would certainly expect it to work if I made the
reference to f weak, it would miss the point of my code entirely. Namely
to make sure that f isn't gc'd until after some other value is (hence
the weak reference to a cons, and my comment about expecting to need 2 gcs).
FWIW, I swapped it and ran again
[ian@Kagami tmp]$ guile -s gcbug.scm
;;; note: source file /tmp/gcbug.scm
;;; newer than compiled /home/ian/.cache/guile/ccache/2.0−LE−4−2.0/tmp/gcbug.scm.go
;;; note: auto−compilation is enabled, set GUILE_AUTO_COMPILE=0
;;; or pass the −−no−auto−compile argument to disable.
;;; compiling /tmp/gcbug.scm
;;; compiled /home/ian/.cache/guile/ccache/2.0−LE−4−2.0/tmp/gcbug.scm.go
#<weak−key−hash−table 1/31>
#<weak−key−hash−table 1/31>
#f
which isn't correct either, but not surprising if something else is
holding onto f.
--
Ian Price
"Programming is like pinball. The reward for doing it well is
the opportunity to do it again" - from "The Wizardy Compiled"
next prev parent reply other threads:[~2011-10-29 18:51 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-28 20:42 bug#9900: Using a guardian on a value in a weak hash Ian Price
2011-10-29 17:42 ` Stefan Israelsson Tampe
2011-10-29 18:51 ` Ian Price [this message]
2011-10-30 13:52 ` bug#9900: local vars not cleaned Stefan Israelsson Tampe
2011-10-30 18:49 ` Stefan Israelsson Tampe
2011-11-01 0:20 ` Ludovic Courtès
2011-11-01 19:53 ` Andy Wingo
2011-11-09 22:47 ` bug#9900: Using a guardian on a value in a weak hash Andy Wingo
2011-12-14 21:49 ` Ludovic Courtès
2011-12-15 21:55 ` Andy Wingo
2011-12-18 23:38 ` Ludovic Courtès
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m3ty6rbpi8.fsf@googlemail.com \
--to=ianprice90@googlemail.com \
--cc=9900@debbugs.gnu.org \
--cc=stefan.itampe@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).