From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Han-Wen Nienhuys Newsgroups: gmane.lisp.guile.devel Subject: Re: [PATCH] Avoid `SCM_VALIDATE_LIST ()' Date: Sun, 31 Aug 2008 21:12:10 -0300 Message-ID: References: <87hc90u9lb.fsf@gnu.org> Reply-To: hanwen@xs4all.nl NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1220228042 24387 80.91.229.12 (1 Sep 2008 00:14:02 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 1 Sep 2008 00:14:02 +0000 (UTC) To: guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Mon Sep 01 02:14:56 2008 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.50) id 1KZx4K-0004xE-BY for guile-devel@m.gmane.org; Mon, 01 Sep 2008 02:14:56 +0200 Original-Received: from localhost ([127.0.0.1]:34501 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KZx3L-0004kU-Cr for guile-devel@m.gmane.org; Sun, 31 Aug 2008 20:13:55 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KZx37-0004bd-7D for guile-devel@gnu.org; Sun, 31 Aug 2008 20:13:41 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KZx36-0004aw-HZ for guile-devel@gnu.org; Sun, 31 Aug 2008 20:13:40 -0400 Original-Received: from [199.232.76.173] (port=55588 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KZx36-0004ao-3L for guile-devel@gnu.org; Sun, 31 Aug 2008 20:13:40 -0400 Original-Received: from main.gmane.org ([80.91.229.2]:52281 helo=ciao.gmane.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1KZx35-0003Kx-Nu for guile-devel@gnu.org; Sun, 31 Aug 2008 20:13:40 -0400 Original-Received: from list by ciao.gmane.org with local (Exim 4.43) id 1KZx34-0002CJ-Ic for guile-devel@gnu.org; Mon, 01 Sep 2008 00:13:38 +0000 Original-Received: from 201.80.3.52 ([201.80.3.52]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 01 Sep 2008 00:13:38 +0000 Original-Received: from hanwen by 201.80.3.52 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 01 Sep 2008 00:13:38 +0000 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 58 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: 201.80.3.52 User-Agent: Thunderbird 2.0.0.16 (X11/20080723) In-Reply-To: <87hc90u9lb.fsf@gnu.org> X-detected-kernel: by monty-python.gnu.org: Linux 2.6, seldom 2.4 (older, 4) 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:7565 Archived-At: Ludovic Courtès escreveu: > Hello, > > This is a followup to this discussion: > > http://thread.gmane.org/gmane.lisp.guile.devel/7194 > > The attached patch changes several list-related functions so that they > don't validate their input with `SCM_VALIDATE_LIST ()' since it's O(n). > > A side-effect (besides performance improvements) is that all these > functions will now happily traverse circular lists, and will silently > deal with dotted lists. This is acceptable behavior IMO. > > Nevertheless, the second patch below implements the "tortoise and the > hare" in `list-copy' so that it detects circular list; it seems > worthwhile to check that here since `list-copy' would otherwise exhaust > memory. > > (Note that SRFI-1's `list-copy' *does* accept improper lists, including > circular lists, although SRFI-1 does not explicitly mention that it > should handle improper list.) > > Also, in some cases, the `wrong-type-arg' message is different (but the > exception key is the same). > > OK to apply to both branches? - return scm_c_memq (x, lst); + for (; !SCM_NULL_OR_NIL_P (lst); lst = SCM_CDR (lst)) + { + SCM_VALIDATE_CONS (2, lst); Looks cleaner to use SCM_CONS_P (or whatever it is called) as loop guard, so it is obviously correct, and crash if the lst is not properly terminated after the loop (- perhaps only if we're not compiling in optimizing mode). On a tangent, is anyone still seriously considering to run Emacs atop GUILE? (It looks a bit like a travesty if we're trying to accomodate elisp while also trying to follow standards like SRFI-x and RxRS) - SCM from_here; + SCM from_here, hare; you could do the init to lst right here. IMO it's neater not to have uninitialized memory locations during program execution. ;;;; list.test --- tests guile's lists -*- scheme -*- -;;;; Copyright (C) 2000, 2001, 2006 Free Software Foundation, Inc. +;;;; Copyright (C) 2000, 2001, 2006, 2008 Free Software Foundation, Inc. Can we do this in one fell swoop, adding 2008 to all files? After all publishing a commit is a release in some sense. Then, we don't have to worry about the file headers anymore. -- Han-Wen Nienhuys - hanwen@xs4all.nl - http://www.xs4all.nl/~hanwen