bug-guile
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#12095: Protecting pointer on bytevector with guardian does not prote


From: Daniel Hartwig
Subject: bug#12095: Protecting pointer on bytevector with guardian does not protect memory
Date: Sun, 7 Oct 2012 10:56:55 +0800

On 7 October 2012 05:41, Ludovic Courtès <address@hidden> wrote:
> 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.)

If I understand correctly, there is never any non-weak reference to
the bv above and so it can be collected at any time.

It's a bit of an “of course!” moment to realise that the pointer is
only a weak reference.

Thanks





reply via email to

[Prev in Thread] Current Thread [Next in Thread]