From eadd64444e9336b40f5e2ea70aeaa587f3e53431 Mon Sep 17 00:00:00 2001 From: Gerd Moellmann Date: Fri, 12 Oct 2001 14:20:14 +0000 Subject: [PATCH] (byte-compile-check-lambda-list): New function checking that lambda-list consists of non-constant symbols, that &rest and &optional are followed by variable names, that &rest VAR is the last element, and that variables aren't doubled. (byte-compile-lambda): Use it. --- lisp/ChangeLog | 9 +++++++++ lisp/emacs-lisp/bytecomp.el | 29 ++++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index a7a4f0565ca..cb077880569 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,12 @@ +2001-10-12 Gerd Moellmann + + * emacs-lisp/bytecomp.el (byte-compile-check-lambda-list): New + function checking that lambda-list consists of non-constant + symbols, that &rest and &optional are followed by variable names, + that &rest VAR is the last element, and that variables aren't + doubled. + (byte-compile-lambda): Use it. + 2001-10-12 Eli Barzilay * calculator.el (calculator-eng-display): Don't call concat diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el index 332a7c79504..8813e3891b5 100644 --- a/lisp/emacs-lisp/bytecomp.el +++ b/lisp/emacs-lisp/bytecomp.el @@ -10,7 +10,7 @@ ;;; This version incorporates changes up to version 2.10 of the ;;; Zawinski-Furuseth compiler. -(defconst byte-compile-version "$Revision: 2.87 $") +(defconst byte-compile-version "$Revision: 2.88.1.1 $") ;; This file is part of GNU Emacs. @@ -2133,12 +2133,37 @@ If FORM is a lambda or a macro, byte-compile it as a function." (nth 3 function)))))) +(defun byte-compile-check-lambda-list (list) + "Check lambda-list LIST for errors." + (let (vars) + (while list + (let ((arg (car list))) + (cond ((or (not (symbolp arg)) + (keywordp arg) + (memq arg '(t nil))) + (error "Invalid lambda variable %s" arg)) + ((eq arg '&rest) + (unless (cdr list) + (error "&rest without variable name")) + (when (cddr list) + (error "Garbage following &rest VAR in lambda-list"))) + ((eq arg '&optional) + (unless (cdr list) + (error "Variable name missing after &optional"))) + ((memq arg vars) + (error "Repeated variable %s in lambda-list" arg)) + (t + (push arg vars)))) + (setq list (cdr list))))) + + ;; Byte-compile a lambda-expression and return a valid function. ;; The value is usually a compiled function but may be the original ;; lambda-expression. (defun byte-compile-lambda (fun) (unless (eq 'lambda (car-safe fun)) (error "Not a lambda list: %S" fun)) + (byte-compile-check-lambda-list (nth 1 fun)) (let* ((arglist (nth 1 fun)) (byte-compile-bound-variables (nconc (and (memq 'free-vars byte-compile-warnings) @@ -3216,6 +3241,8 @@ If FORM is a lambda or a macro, byte-compile it as a function." (defun byte-compile-defun (form) ;; This is not used for file-level defuns with doc strings. + (unless (symbolp (car form)) + (error "defun name must be a symbol, not %s" (car form))) (byte-compile-two-args ; Use this to avoid byte-compile-fset's warning. (list 'fset (list 'quote (nth 1 form)) (byte-compile-byte-code-maker -- 2.39.2