GNU bug report logs - #12095
Protecting pointer on bytevector with guardian does not protect memory

Previous Next

Package: guile;

Reported by: Patrick Bernaud <patrickb <at> chez.com>

Date: Mon, 30 Jul 2012 16:48:01 UTC

Severity: normal

Done: ludo <at> gnu.org (Ludovic Courtès)

Bug is archived. No further changes may be made.

Full log


Message #14 received at 12095 <at> debbugs.gnu.org (full text, mbox):

From: ludo <at> gnu.org (Ludovic Courtès)
To: Daniel Hartwig <mandyke <at> gmail.com>
Cc: Patrick Bernaud <patrickb <at> chez.com>, 12095 <at> debbugs.gnu.org,
	Ian Price <ianprice90 <at> googlemail.com>
Subject: Re: bug#12095: Protecting pointer on bytevector with guardian does
	not protect memory
Date: Sat, 06 Oct 2012 23:41:03 +0200
Hi,

Daniel Hartwig <mandyke <at> 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’.




This bug report was last modified 12 years and 291 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.