summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGerd Moellmann <gerd@gnu.org>2000-09-25 15:41:30 +0000
committerGerd Moellmann <gerd@gnu.org>2000-09-25 15:41:30 +0000
commit1bc20d83cb040a51cad08b49b9e81d534fca57a5 (patch)
tree5b343c1dfefd1b060eaab5d6a35860adaf0f4b7b
parentd8b4516f4d03ce794d1caff62558b92de622083d (diff)
downloademacs-1bc20d83cb040a51cad08b49b9e81d534fca57a5.tar.gz
(byte-compile-defvar-or-defconst): Only cons onto
current-load-list in top-level forms. Else this leaks a cons cell every time a defun is called.
-rw-r--r--lisp/emacs-lisp/bytecomp.el45
1 files changed, 27 insertions, 18 deletions
diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el
index f0f24213d17..800df042a78 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: 1.1 $")
+(defconst byte-compile-version "$Revision: 2.76 $")
;; This file is part of GNU Emacs.
@@ -3213,26 +3213,35 @@ If FORM is a lambda or a macro, byte-compile it as a function."
(defun byte-compile-defvar (form)
;; This is not used for file-level defvar/consts with doc strings.
- (let ((var (nth 1 form))
+ (let ((fun (nth 0 form))
+ (var (nth 1 form))
(value (nth 2 form))
(string (nth 3 form)))
- (if (memq 'free-vars byte-compile-warnings)
- (setq byte-compile-bound-variables
- (cons var byte-compile-bound-variables)))
+ (when (> (length form) 4)
+ (byte-compile-warn
+ "%s %s called with %d arguments, but accepts only %s"
+ fun var (length (cdr form)) 3))
+ (when (memq 'free-vars byte-compile-warnings)
+ (setq byte-compile-bound-variables
+ (cons var byte-compile-bound-variables)))
(byte-compile-body-do-effect
- (list (if (cdr (cdr form))
- (if (eq (car form) 'defconst)
- (list 'setq var value)
- (list 'or (list 'boundp (list 'quote var))
- (list 'setq var value))))
- ;; Put the defined variable in this library's load-history entry
- ;; just as a real defvar would.
- (list 'setq 'current-load-list
- (list 'cons (list 'quote var)
- 'current-load-list))
- (if string
- (list 'put (list 'quote var) ''variable-documentation string))
- (list 'quote var)))))
+ (list
+ ;; Put the defined variable in this library's load-history entry
+ ;; just as a real defvar would, but only in top-level forms.
+ (when (null byte-compile-current-form)
+ `(push ',var current-load-list))
+ (when (> (length form) 3)
+ (when (and string (not (stringp string)))
+ (byte-compile-warn "Third arg to %s %s is not a string: %s"
+ fun var string))
+ `(put ',var 'variable-documentation ,string))
+ (if (cdr (cdr form)) ; `value' provided
+ (if (eq fun 'defconst)
+ ;; `defconst' sets `var' unconditionally.
+ `(setq ,var ,value)
+ ;; `defvar' sets `var' only when unbound.
+ `(if (not (boundp ',var)) (setq ,var ,value))))
+ `',var))))
(defun byte-compile-autoload (form)
(and (byte-compile-constp (nth 1 form))