[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Slightly extending commit 16b0520a9

From: Stefan Monnier
Subject: Re: Slightly extending commit 16b0520a9
Date: Sun, 06 Aug 2017 12:18:21 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux)

>>> 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).


reply via email to

[Prev in Thread] Current Thread [Next in Thread]