From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: David Thompson Newsgroups: gmane.lisp.guile.devel Subject: [PATCH] Test for weak pairs in hash-for-each Date: Sat, 08 Mar 2014 17:20:48 -0500 Message-ID: <87vbvotjr3.fsf@izanagi.i-did-not-set--mail-host-address--so-tickle-me> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1394317265 20359 80.91.229.3 (8 Mar 2014 22:21:05 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 8 Mar 2014 22:21:05 +0000 (UTC) To: guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Sat Mar 08 23:21:13 2014 Return-path: Envelope-to: guile-devel@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 1WMPcG-0003tW-GX for guile-devel@m.gmane.org; Sat, 08 Mar 2014 23:21:12 +0100 Original-Received: from localhost ([::1]:42004 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WMPcG-0003me-0w for guile-devel@m.gmane.org; Sat, 08 Mar 2014 17:21:12 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:60611) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WMPc6-0003cQ-RY for guile-devel@gnu.org; Sat, 08 Mar 2014 17:21:09 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WMPby-000889-14 for guile-devel@gnu.org; Sat, 08 Mar 2014 17:21:02 -0500 Original-Received: from na3sys009aog125.obsmtp.com ([74.125.149.153]:59865) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WMPbx-00087m-PX for guile-devel@gnu.org; Sat, 08 Mar 2014 17:20:53 -0500 Original-Received: from mail-qc0-f177.google.com ([209.85.216.177]) (using TLSv1) by na3sys009aob125.postini.com ([74.125.148.12]) with SMTP ID DSNKUxuXw4WuT5+F0tZbQiWm3Iqd1nuMCcqt@postini.com; Sat, 08 Mar 2014 14:20:53 PST Original-Received: by mail-qc0-f177.google.com with SMTP id w7so6217843qcr.36 for ; Sat, 08 Mar 2014 14:20:50 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:user-agent:date:message-id :mime-version:content-type; bh=lt/yD5sAKwhuR8l/Kwm/Qizps7HKCz5GT1m04QMrDTk=; b=UC02KJeKwTO3hQBbhB2I6BEPpC34TBi4T+iDRC/03jbRuyawAlEwtx/fCAb6RXM/c9 W3fw74z0dcH369X48b8D3vu1nmxLXXUSdZIxIHcsIZmtdo/zRcLaLUb+La5XVJ0dm9tE 5bHdwEO8SPNfoNhd4DsOEZXDZN9Nhy2B89YAt8gg6k8+CLGvQHZWAsGyxKUw+hxKwm7L bV7KY3SdcrulvM2o4490m0cl26OAogD03i+kBePBjV/pLt7QjL3K1TBvH+k3ICtsFRUJ oXemRn6aRynZHjMWYrB4ve7Zb6SmXNjoSUvmu/cNKF0Y83uWMFlgZWdUycmmmsAo+21p fA5g== X-Gm-Message-State: ALoCoQk4O1DOCTg9eqCxnDlMobdq1WklteZWdRjBMX0IeqyvUZNqyD6hTTQm+7u7X8x17FCed/JQPsb8wnzmk7kQOoqMSgpkz5luzRLbKSi4rhEXeZ8LABktSA0oehmsOjbPbns3F+MympLWQ+YSdf5O5n8B5W4jRg== X-Received: by 10.140.31.247 with SMTP id f110mr29315650qgf.58.1394317250863; Sat, 08 Mar 2014 14:20:50 -0800 (PST) X-Received: by 10.140.31.247 with SMTP id f110mr29315641qgf.58.1394317250767; Sat, 08 Mar 2014 14:20:50 -0800 (PST) Original-Received: from izanagi (209-6-40-86.c3-0.smr-ubr1.sbo-smr.ma.cable.rcn.com. [209.6.40.86]) by mx.google.com with ESMTPSA id a10sm42770344qas.6.2014.03.08.14.20.48 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Sat, 08 Mar 2014 14:20:49 -0800 (PST) User-Agent: Notmuch/0.17 (http://notmuchmail.org) Emacs/24.3.1 (x86_64-pc-linux-gnu) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x X-Received-From: 74.125.149.153 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:16951 Archived-At: --=-=-= Content-Type: text/plain Hello all, This patch fixes a segfault that occurs when iterating over a weak hash table with deleted weak pairs. WDYT? - Dave --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Test-for-deleted-weak-pairs-in-hash-for-each.patch >From 531c773dae023f15e0719d76a4352064e3681a7b Mon Sep 17 00:00:00 2001 From: David Thompson Date: Sat, 8 Mar 2014 17:15:52 -0500 Subject: [PATCH] Test for deleted weak pairs in hash-for-each. * libguile/hashtab.c (hash-for-each): Test for deleted weak pairs. * test-suite/tests/hash.test: Add test case. --- libguile/hashtab.c | 4 +++- test-suite/tests/hash.test | 12 ++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/libguile/hashtab.c b/libguile/hashtab.c index 9107ce5..c5277c1 100644 --- a/libguile/hashtab.c +++ b/libguile/hashtab.c @@ -1464,7 +1464,9 @@ scm_internal_hash_for_each_handle (scm_t_hash_handle_fn fn, void *closure, handle = SCM_CAR (ls); if (!scm_is_pair (handle)) SCM_WRONG_TYPE_ARG (SCM_ARG3, buckets); - fn (closure, handle); + if (!SCM_HASHTABLE_WEAK_P (table) || + !SCM_WEAK_PAIR_DELETED_P (handle)) + fn (closure, handle); ls = SCM_CDR (ls); } } diff --git a/test-suite/tests/hash.test b/test-suite/tests/hash.test index 64d10bb..4c21d71 100644 --- a/test-suite/tests/hash.test +++ b/test-suite/tests/hash.test @@ -347,3 +347,15 @@ (pass-if (equal? 2 (hash-count (lambda (k v) (string? v)) table))))) + +;;; +;;; weak key hash table +;;; + +(with-test-prefix "weak key hash table" + (pass-if "hash-for-each after gc" + (let ((table (make-weak-key-hash-table))) + (hashq-set! table (list 'foo) 'bar) + (gc) + ;; Iterate over deleted weak ref without crashing. + (unspecified? (hash-for-each (lambda (key value) key) table))))) -- 1.8.5.3 --=-=-=--