From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Newsgroups: gmane.lisp.guile.bugs Subject: bug#28590: [PATCH 5/7] weak-table: 'move_weak_entry' reports disappeared links. Date: Tue, 3 Oct 2017 13:43:50 +0200 Message-ID: <20171003114352.13984-6-ludo@gnu.org> References: <20171003114352.13984-1-ludo@gnu.org> NNTP-Posting-Host: blaine.gmane.org X-Trace: blaine.gmane.org 1507031206 19667 195.159.176.226 (3 Oct 2017 11:46:46 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 3 Oct 2017 11:46:46 +0000 (UTC) Cc: Ludovic =?UTF-8?Q?Court=C3=A8s?= , 28590@debbugs.gnu.org To: wingo@igalia.com Original-X-From: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Tue Oct 03 13:46:36 2017 Return-path: Envelope-to: guile-bugs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dzLel-0004IV-1H for guile-bugs@m.gmane.org; Tue, 03 Oct 2017 13:46:35 +0200 Original-Received: from localhost ([::1]:57961 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dzLes-0003JD-HJ for guile-bugs@m.gmane.org; Tue, 03 Oct 2017 07:46:42 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:34021) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dzLeL-00032T-5I for bug-guile@gnu.org; Tue, 03 Oct 2017 07:46:10 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dzLeG-0006cp-HT for bug-guile@gnu.org; Tue, 03 Oct 2017 07:46:09 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:36643) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dzLeG-0006cY-Ec for bug-guile@gnu.org; Tue, 03 Oct 2017 07:46:04 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1dzLeG-0006lU-8h; Tue, 03 Oct 2017 07:46:04 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Tue, 03 Oct 2017 11:46:04 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 28590 X-GNU-PR-Package: guile X-GNU-PR-Keywords: Original-Received: via spool by 28590-submit@debbugs.gnu.org id=B28590.150703111425869 (code B ref 28590); Tue, 03 Oct 2017 11:46:04 +0000 Original-Received: (at 28590) by debbugs.gnu.org; 3 Oct 2017 11:45:14 +0000 Original-Received: from localhost ([127.0.0.1]:45314 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dzLdR-0006j6-W0 for submit@debbugs.gnu.org; Tue, 03 Oct 2017 07:45:14 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:42626) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dzLdN-0006hg-Mr for 28590@debbugs.gnu.org; Tue, 03 Oct 2017 07:45:11 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dzLdF-0005rz-DU for 28590@debbugs.gnu.org; Tue, 03 Oct 2017 07:45:04 -0400 Original-Received: from fencepost.gnu.org ([2001:4830:134:3::e]:59155) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dzLcY-0005CT-HU; Tue, 03 Oct 2017 07:44:18 -0400 Original-Received: from [193.50.110.164] (port=33316 helo=gnu.org) by fencepost.gnu.org with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1dzLcY-0000d1-2S; Tue, 03 Oct 2017 07:44:18 -0400 X-Mailer: git-send-email 2.14.2 In-Reply-To: <20171003114352.13984-1-ludo@gnu.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.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" Xref: news.gmane.org gmane.lisp.guile.bugs:8845 Archived-At: * libguile/weak-table.c (move_weak_entry): Change to return a Boolean. (give_to_poor): Remove 'copy_weak_entry' call and adjust accordingly. --- libguile/weak-table.c | 46 +++++++++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/libguile/weak-table.c b/libguile/weak-table.c index b5db3ef48..5c4b3d30a 100644 --- a/libguile/weak-table.c +++ b/libguile/weak-table.c @@ -199,28 +199,45 @@ move_disappearing_links (scm_t_weak_entry *from, scm_t_weak_entry *to, } } -static void +/* Move weak entry FROM to TO. Return non-zero on success, and zero if + the entry at FROM disappeared in the meantime. */ +static int move_weak_entry (scm_t_weak_entry *from, scm_t_weak_entry *to, scm_t_weak_table_kind kind) { if (from->hash) { scm_t_weak_entry copy; - + copy_weak_entry (from, ©); - to->hash = copy.hash; - to->key = copy.key; - to->value = copy.value; - move_disappearing_links (from, to, - SCM_PACK (copy.key), SCM_PACK (copy.value), - kind); + if (copy.key != 0 && copy.value != 0) + { + to->hash = copy.hash; + to->key = copy.key; + to->value = copy.value; + + move_disappearing_links (from, to, + SCM_PACK (copy.key), SCM_PACK (copy.value), + kind); + return 1; + } + else + { + /* Lost weak reference: make sure all the disappearing links + are registered (in the case of a doubly-weak table, one of + the disappearing links could still be there.) */ + memset (to, '\0', sizeof *to); + unregister_disappearing_links (from, kind); + return 0; + } } else { + unregister_disappearing_links (from, kind); to->hash = 0; - to->key = 0; - to->value = 0; + to->key = to->value = 0; + return 0; } } @@ -301,16 +318,14 @@ give_to_poor (scm_t_weak_table *table, unsigned long k) { unsigned long next = (k + 1) % size; unsigned long hash; - scm_t_weak_entry copy; hash = table->entries[next].hash; if (!hash || hash_to_index (hash, size) == next) break; - copy_weak_entry (&table->entries[next], ©); - - if (!copy.key || !copy.value) + if (!move_weak_entry (&table->entries[next], &table->entries[k], + table->kind)) /* Lost weak reference. */ { give_to_poor (table, next); @@ -318,9 +333,6 @@ give_to_poor (scm_t_weak_table *table, unsigned long k) continue; } - move_weak_entry (&table->entries[next], &table->entries[k], - table->kind); - k = next; } -- 2.14.2