[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#12095: Protecting pointer on bytevector with guardian does not prote
From: |
Ludovic Courtès |
Subject: |
bug#12095: Protecting pointer on bytevector with guardian does not protect memory |
Date: |
Sat, 06 Oct 2012 23:41:03 +0200 |
User-agent: |
Gnus/5.130005 (Ma Gnus v0.5) Emacs/24.2 (gnu/linux) |
Hi,
Daniel Hartwig <address@hidden> 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’.
- bug#12095: Protecting pointer on bytevector with guardian does not protect memory,
Ludovic Courtès <=