unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
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: Sat, 06 Oct 2012 23:41:03 +0200	[thread overview]
Message-ID: <874nm75le8.fsf@gnu.org> (raw)
In-Reply-To: <CAN3veRd86=y8pUQAFNzmedym3aQ4eUe86-pf2cSTg1Wxgvy0cA@mail.gmail.com> (Daniel Hartwig's message of "Tue, 7 Aug 2012 11:32:10 +0800")

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.)

To put it differently, memory management is left to the user.  The weak
reference I mention is a convenience for simple cases, but for “real
world” situations, one has to take all steps necessary to ensure that
the lifetime of C objects and that of their Scheme counterparts is in sync.

Hope this helps,
Ludo’.





  reply	other threads:[~2012-10-06 21:41 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 [this message]
2012-10-07  2:56       ` Daniel Hartwig
2012-10-07 20:38         ` Ludovic Courtès
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=874nm75le8.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).