From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: ludo@gnu.org (Ludovic =?UTF-8?Q?Court=C3=A8s?=) Newsgroups: gmane.lisp.guile.bugs Subject: bug#12095: Protecting pointer on bytevector with guardian does not protect memory Date: Sat, 06 Oct 2012 23:41:03 +0200 Message-ID: <874nm75le8.fsf@gnu.org> References: <20502.44997.295661.951990@vagabond.local> <878vdskmde.fsf@Kagami.home> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1349559712 27348 80.91.229.3 (6 Oct 2012 21:41:52 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 6 Oct 2012 21:41:52 +0000 (UTC) Cc: 12095@debbugs.gnu.org, Ian Price To: Daniel Hartwig Original-X-From: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Sat Oct 06 23:41:58 2012 Return-path: Envelope-to: guile-bugs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1TKc8D-0001Kr-SK for guile-bugs@m.gmane.org; Sat, 06 Oct 2012 23:41:57 +0200 Original-Received: from localhost ([::1]:50423 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TKc88-0001uo-1u for guile-bugs@m.gmane.org; Sat, 06 Oct 2012 17:41:52 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:37964) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TKc83-0001pv-Kt for bug-guile@gnu.org; Sat, 06 Oct 2012 17:41:48 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TKc80-0003J7-DG for bug-guile@gnu.org; Sat, 06 Oct 2012 17:41:47 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:48431) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TKc80-0003J2-8u for bug-guile@gnu.org; Sat, 06 Oct 2012 17:41:44 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1TKc8I-00089m-6n for bug-guile@gnu.org; Sat, 06 Oct 2012 17:42:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: ludo@gnu.org (Ludovic =?UTF-8?Q?Court=C3=A8s?=) Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-guile@gnu.org Resent-Date: Sat, 06 Oct 2012 21:42:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 12095 X-GNU-PR-Package: guile X-GNU-PR-Keywords: Original-Received: via spool by 12095-submit@debbugs.gnu.org id=B12095.134955968631307 (code B ref 12095); Sat, 06 Oct 2012 21:42:02 +0000 Original-Received: (at 12095) by debbugs.gnu.org; 6 Oct 2012 21:41:26 +0000 Original-Received: from localhost ([127.0.0.1]:58682 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1TKc7h-00088t-MS for submit@debbugs.gnu.org; Sat, 06 Oct 2012 17:41:25 -0400 Original-Received: from xanadu.aquilenet.fr ([88.191.123.111]:44914) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1TKc7f-00088m-3X for 12095@debbugs.gnu.org; Sat, 06 Oct 2012 17:41:23 -0400 Original-Received: from localhost (localhost [127.0.0.1]) by xanadu.aquilenet.fr (Postfix) with ESMTP id 22A3611F0; Sat, 6 Oct 2012 23:41:04 +0200 (CEST) Original-Received: from xanadu.aquilenet.fr ([127.0.0.1]) by localhost (xanadu.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id h1u5MozPitLx; Sat, 6 Oct 2012 23:41:04 +0200 (CEST) Original-Received: from pluto (reverse-83.fdn.fr [80.67.176.83]) by xanadu.aquilenet.fr (Postfix) with ESMTPSA id 8D89B4F3; Sat, 6 Oct 2012 23:41:03 +0200 (CEST) In-Reply-To: (Daniel Hartwig's message of "Tue, 7 Aug 2012 11:32:10 +0800") User-Agent: Gnus/5.130005 (Ma Gnus v0.5) Emacs/24.2 (gnu/linux) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 140.186.70.43 X-BeenThere: bug-guile@gnu.org List-Id: "Bug reports for GUILE, GNU's Ubiquitous Extension Language" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Original-Sender: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.bugs:6543 Archived-At: Hi, Daniel Hartwig 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: =E2=80=98bytevector->pointer=E2=80=99 creates a w= eak 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=E2=80=99re observing. (And no, guardians don=E2=80=99t pro= tect 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 =E2=80=9Creal world=E2=80=9D situations, one has to take all steps necessary to ensure th= at the lifetime of C objects and that of their Scheme counterparts is in sync. Hope this helps, Ludo=E2=80=99.