From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: ludo@gnu.org (Ludovic =?iso-8859-1?Q?Court=E8s?=) Newsgroups: gmane.lisp.guile.devel Subject: =?utf-8?b?4oCYc2V0LWNkciHigJk=?= and weak-cdr pairs Date: Sun, 13 Mar 2011 16:25:07 +0100 Message-ID: <87fwqrqbzg.fsf@gnu.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: dough.gmane.org 1300029932 23946 80.91.229.12 (13 Mar 2011 15:25:32 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sun, 13 Mar 2011 15:25:32 +0000 (UTC) To: guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Sun Mar 13 16:25:27 2011 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1PynAd-0006Ae-AJ for guile-devel@m.gmane.org; Sun, 13 Mar 2011 16:25:27 +0100 Original-Received: from localhost ([127.0.0.1]:49787 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PynAc-0001Hv-Pu for guile-devel@m.gmane.org; Sun, 13 Mar 2011 11:25:26 -0400 Original-Received: from [140.186.70.92] (port=44770 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PynAY-0001GJ-IY for guile-devel@gnu.org; Sun, 13 Mar 2011 11:25:23 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PynAX-00054H-EG for guile-devel@gnu.org; Sun, 13 Mar 2011 11:25:22 -0400 Original-Received: from lo.gmane.org ([80.91.229.12]:56630) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PynAX-000548-3I for guile-devel@gnu.org; Sun, 13 Mar 2011 11:25:21 -0400 Original-Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1PynAV-00069E-Gq for guile-devel@gnu.org; Sun, 13 Mar 2011 16:25:19 +0100 Original-Received: from reverse-83.fdn.fr ([80.67.176.83]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 13 Mar 2011 16:25:19 +0100 Original-Received: from ludo by reverse-83.fdn.fr with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 13 Mar 2011 16:25:19 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 65 Original-X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: reverse-83.fdn.fr X-URL: http://www.fdn.fr/~lcourtes/ X-Revolutionary-Date: 23 =?iso-8859-1?Q?Vent=F4se?= an 219 de la =?iso-8859-1?Q?R=E9volution?= X-PGP-Key-ID: 0xEA52ECF4 X-PGP-Key: http://www.fdn.fr/~lcourtes/ludovic.asc X-PGP-Fingerprint: 83C4 F8E5 10A3 3B4C 5BEA D15D 77DD 95E2 EA52 ECF4 X-OS: x86_64-unknown-linux-gnu User-Agent: Gnus/5.110013 (No Gnus v0.13) Emacs/23.3 (gnu/linux) Cancel-Lock: sha1:47cO9e3wtXy0jYcJl/Tb+j22f0E= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 80.91.229.12 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:11863 Archived-At: Hello, A bit of explanation for commit ca33b501a93f8de389c1e3e1bc987f63b6912029... Try this: --8<---------------cut here---------------start------------->8--- (use-modules (srfi srfi-1) (srfi srfi-9)) (define-record-type (make-foo x) foo? (x foo-x)) (define register! (let ((t (make-weak-value-hash-table 10))) (lambda (x) (let ((k+v (hash-create-handle! t x #f))) (or (cdr k+v) (let ((o (make-foo x))) (set-cdr! k+v o) o)))))) (every (lambda (x) (make-foo #f) (let ((o (register! x))) (or (foo? o) (pk 'bad! o)))) (circular-list 1 2 3 4 5 6 7 8 9)) --8<---------------cut here---------------end--------------->8--- Eventually ‘(foo? o)’ fails and Guile segfaults while trying to display O. Changing ‘register!’ to the following works: --8<---------------cut here---------------start------------->8--- (define register! (let ((t (make-weak-value-hash-table 10))) (lambda (x) (or (hash-ref t x) (let ((o (make-foo x))) (hash-set! t x o) o))))) --8<---------------cut here---------------end--------------->8--- The problem is that ‘hash-create-handle!’ above created a weak-cdr pair—i.e., a pair whose cdr is /not/ scanned for pointers—but ‘set-cdr!’ did not register a disappearing link from O to K+V. Consequently, O eventually gets collected, but K+V remains; the storage of O then gets reused, and the cdr of K+V ends up containing either an unrelated or >an invalid Scheme object. This problem is explicitly addressed in ‘scm_hash_fn_set_x’. AFAICS ‘set-cdr!’ has no way of knowing whether its passed a normal pair or a weak-cdr one, so it cannot be changed to handle weak-cdr pairs gracefully. And of course, we have the same problem with weak-car pairs and ‘set-car!’, but ‘set-car!’ is unlikely to be used on weak-car pairs. Thoughts? Ludo’.