From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: Slightly extending commit 16b0520a9 Date: Sun, 06 Aug 2017 12:18:21 -0400 Message-ID: References: <87o9rtuz2r.fsf@lylat> <87h8xluxlf.fsf@lylat> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1502036374 3932 195.159.176.226 (6 Aug 2017 16:19:34 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 6 Aug 2017 16:19:34 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Aug 06 18:19:31 2017 Return-path: Envelope-to: ged-emacs-devel@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 1deOH4-0000mA-GQ for ged-emacs-devel@m.gmane.org; Sun, 06 Aug 2017 18:19:30 +0200 Original-Received: from localhost ([::1]:33722 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1deOHA-0007hI-KX for ged-emacs-devel@m.gmane.org; Sun, 06 Aug 2017 12:19:36 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:49407) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1deOGE-0007fz-Q8 for emacs-devel@gnu.org; Sun, 06 Aug 2017 12:18:39 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1deOGA-0002ld-Re for emacs-devel@gnu.org; Sun, 06 Aug 2017 12:18:38 -0400 Original-Received: from [195.159.176.226] (port=32809 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1deOGA-0002l9-Kj for emacs-devel@gnu.org; Sun, 06 Aug 2017 12:18:34 -0400 Original-Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1deOG0-0005lT-Qe for emacs-devel@gnu.org; Sun, 06 Aug 2017 18:18:24 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 35 Original-X-Complaints-To: usenet@blaine.gmane.org Cancel-Lock: sha1:b8AgCI56m7Z3s5Oexs+r8uk13d4= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 195.159.176.226 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:217341 Archived-At: >>> cond = eval_sub (XCAR (args)); >>> if (!NILP (cond)) >>> - return eval_sub (Fcar (XCDR (args))); >>> + return eval_sub (XCAR (XCDR (args))); >> I don't see anything in the preceding code that guarantees that `XCDR (args)` >> holds a cons, so I think XCAR here is unsafe. > The following line includes "XCDR (XCDR (args))", Indeed, that looks like a bug. > I believe the reason why we can assume that XCDR (args) is a cons cell > is that `if' requires at least 2 (unevalled) arguments, so args must be > a list of at least length 2. Try (eval '(if nil . "hello")) [ ... trying it himself ... ] Hmm... it turns out that indeed it seems that XCDR and XCAR here are safe because before calling those functions, eval_sub happens to call Flength on the args, and that triggers an error if the form is not a proper list, so `XCDR (args)` will indeed be a cons once we get to Fif. Arguably Fif could be called from elsewhere than eval_sub, and arguably eval_sub's implementation could be changed in such a way that it doesn't catch this error, so the safety of using XCDR is debatable. The important thing to remember, tho, is that Fif should not be performance sensitive: code whose performance matters should be byte-compiled in which case it doesn't call Fif (as is the case for all other special forms). Stefan