GNU bug report logs - #15715
24.3; Sanity check of ARGLIST when calling `defun'

Previous Next

Package: emacs;

Reported by: Nicolas Richard <theonewiththeevillook <at> yahoo.fr>

Date: Fri, 25 Oct 2013 12:28:01 UTC

Severity: wishlist

Tags: patch

Found in version 24.3

Fixed in version 26.1

Done: Glenn Morris <rgm <at> gnu.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 15715 in the body.
You can then email your comments to 15715 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#15715; Package emacs. (Fri, 25 Oct 2013 12:28:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Nicolas Richard <theonewiththeevillook <at> yahoo.fr>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Fri, 25 Oct 2013 12:28:03 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Nicolas Richard <theonewiththeevillook <at> yahoo.fr>
To: bug-gnu-emacs <at> gnu.org
Subject: 24.3; Sanity check of ARGLIST when calling `defun'
Date: Fri, 25 Oct 2013 14:27:06 +0200
[Message part 1 (text/plain, inline)]
Hello,

As suggested here http://permalink.gmane.org/gmane.emacs.help/94196 I
attach a patch to make (defun ...) check that the arglist is an actual
list of symbols when defining a function, and otherwise signal an error.

Without this, code like (defun test-foobar ...) succeeds although the
function is doomed to fail at runtime.

This won't catch every missing "arglist" but that looks impossible
anyway.

[0001-Sanity-check-for-ARGLIST-in-defun.patch (text/x-diff, inline)]
diff --git a/lisp/emacs-lisp/byte-run.el b/lisp/emacs-lisp/byte-run.el
index 0bb0495..d671892 100644
--- a/lisp/emacs-lisp/byte-run.el
+++ b/lisp/emacs-lisp/byte-run.el
@@ -180,6 +180,10 @@ The return value is undefined.
   ;; from
   ;;    (defun foo (arg) (toto)).
   (declare (doc-string 3))
+  (if (null
+       (and (listp arglist)
+            (null (delq t (mapcar #'symbolp arglist)))))
+      (error "Malformed arglist: %s" arglist))
   (let ((decls (cond
                 ((eq (car-safe docstring) 'declare)
                  (prog1 (cdr docstring) (setq docstring nil)))
@@ -209,7 +213,7 @@ The return value is undefined.
                     nil)
                    (t (message "Warning: Unknown defun property `%S' in %S"
                                (car x) name)))))
-                   decls))
+            decls))
           (def (list 'defalias
                      (list 'quote name)
                      (list 'function
-- 
1.8.1.5

[Message part 3 (text/plain, inline)]
It was also suggested in that thread by P.J. Bourguignon to use
alternate methods, but both required parts of cl (for "every" and
"dolist"), hence I'm submitting this version (and checked that "make
bootstrap" succeeds).

Another version would be something along the lines of:
  (mapc (function (lambda (elt)
                    (if (null (symbolp elt))
                        (error "Malformed arglist: %s" arglist))))
        (if (listp arglist)
            arglist
          '("")))
but it doesn't look more efficient from my (very limited) test.

-- 
Nico.

Added tag(s) patch. Request was from Nicolas Richard <theonewiththeevillook <at> yahoo.fr> to control <at> debbugs.gnu.org. (Mon, 10 Feb 2014 12:02:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#15715; Package emacs. (Wed, 24 Feb 2016 04:01:01 GMT) Full text and rfc822 format available.

Message #10 received at 15715 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Nicolas Richard <theonewiththeevillook <at> yahoo.fr>
Cc: 15715 <at> debbugs.gnu.org
Subject: Re: bug#15715: 24.3; Sanity check of ARGLIST when calling `defun'
Date: Wed, 24 Feb 2016 15:00:27 +1100
Nicolas Richard <theonewiththeevillook <at> yahoo.fr> writes:

> As suggested here http://permalink.gmane.org/gmane.emacs.help/94196 I
> attach a patch to make (defun ...) check that the arglist is an actual
> list of symbols when defining a function, and otherwise signal an error.
>
> Without this, code like (defun test-foobar ...) succeeds although the
> function is doomed to fail at runtime.

I think this is a good idea (catching errors early is always nice), but
it might break a lot of code out there in the wild.  People defining
functions in their .emacs that they never actually call, for instance.
So I think this change sounds kinda dangerous.

What do all y'all think?

> This won't catch every missing "arglist" but that looks impossible
> anyway.
>
> diff --git a/lisp/emacs-lisp/byte-run.el b/lisp/emacs-lisp/byte-run.el
> index 0bb0495..d671892 100644
> --- a/lisp/emacs-lisp/byte-run.el
> +++ b/lisp/emacs-lisp/byte-run.el
> @@ -180,6 +180,10 @@ The return value is undefined.
>    ;; from
>    ;;    (defun foo (arg) (toto)).
>    (declare (doc-string 3))
> +  (if (null
> +       (and (listp arglist)
> +            (null (delq t (mapcar #'symbolp arglist)))))
> +      (error "Malformed arglist: %s" arglist))
>    (let ((decls (cond
>                  ((eq (car-safe docstring) 'declare)
>                   (prog1 (cdr docstring) (setq docstring nil)))
> @@ -209,7 +213,7 @@ The return value is undefined.
>                      nil)
>                     (t (message "Warning: Unknown defun property `%S' in %S"
>                                 (car x) name)))))
> -                   decls))
> +            decls))
>            (def (list 'defalias
>                       (list 'quote name)
>                       (list 'function

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




Reply sent to Glenn Morris <rgm <at> gnu.org>:
You have taken responsibility. (Sun, 11 Dec 2016 01:49:02 GMT) Full text and rfc822 format available.

Notification sent to Nicolas Richard <theonewiththeevillook <at> yahoo.fr>:
bug acknowledged by developer. (Sun, 11 Dec 2016 01:49:02 GMT) Full text and rfc822 format available.

Message #15 received at 15715-done <at> debbugs.gnu.org (full text, mbox):

From: Glenn Morris <rgm <at> gnu.org>
To: 15715-done <at> debbugs.gnu.org
Subject: Re: bug#15715: 24.3; Sanity check of ARGLIST when calling `defun'
Date: Sat, 10 Dec 2016 20:48:35 -0500
Version: 26.1

Thanks; applied as 0107336.




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sun, 08 Jan 2017 12:24:03 GMT) Full text and rfc822 format available.

This bug report was last modified 8 years and 222 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.