From: ludo@gnu.org (Ludovic Courtès)
To: Daniel Hartwig <mandyke@gmail.com>
Cc: 12095@debbugs.gnu.org, Ian Price <ianprice90@googlemail.com>
Subject: bug#12095: Protecting pointer on bytevector with guardian does not protect memory
Date: Sun, 07 Oct 2012 22:38:33 +0200 [thread overview]
Message-ID: <87y5ji2f1y.fsf@gnu.org> (raw)
In-Reply-To: <CAN3veRc=22ZfX2LJxTgO24KWQrZ4nzDA5iseu8-t0-O7nh8_3w@mail.gmail.com> (Daniel Hartwig's message of "Sun, 7 Oct 2012 10:56:55 +0800")
Hi,
Daniel Hartwig <mandyke@gmail.com> skribis:
> On 7 October 2012 05:41, Ludovic Courtès <ludo@gnu.org> wrote:
>> Hi,
>>
>> Daniel Hartwig <mandyke@gmail.com> skribis:
>>
>>> (define x (bytevector->pointer (make-bytevector len 1)))
>>> (define a (pointer-address x))
>>> (display x)(newline)
>>> (my-guardian x)
>>> ;(my-guardian (pointer->bytevector x len))
>>> (set! x #f)
>>>
>>> (define (dump-struct)
>>> (write (pointer->bytevector (make-pointer a) len))(newline))
>>
>> This is expected to fail: ‘bytevector->pointer’ creates a weak reference
>> from the returned pointer object to the given bytevector. So when the
>> pointer object is reclaimed, the bytevector can be reclaimed too, hence
>> the problem you’re observing. (And no, guardians don’t protect objects
>> from garbage collection.)
>
> If I understand correctly, there is never any non-weak reference to
> the bv above and so it can be collected at any time.
There’s a weak reference from the pointer object to the bytevector.
Once that pointer object has been collected (as in the example above),
the bytevector can be collected anytime.
Thanks,
Ludo’.
next prev parent reply other threads:[~2012-10-07 20:38 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-07-30 16:01 bug#12095: Protecting pointer on bytevector with guardian does not protect memory Patrick Bernaud
2012-08-06 16:37 ` Ian Price
2012-08-07 3:32 ` Daniel Hartwig
2012-10-06 21:41 ` Ludovic Courtès
2012-10-07 2:56 ` Daniel Hartwig
2012-10-07 20:38 ` Ludovic Courtès [this message]
2012-10-07 23:49 ` Daniel Hartwig
2012-10-08 13:44 ` Ludovic Courtès
2012-10-08 14:10 ` Daniel Hartwig
2012-10-08 15:42 ` 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=87y5ji2f1y.fsf@gnu.org \
--to=ludo@gnu.org \
--cc=12095@debbugs.gnu.org \
--cc=ianprice90@googlemail.com \
--cc=mandyke@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).