X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/6eabc4c2f76441f11cc344891d3849ad3631ab15..0d9f702fd085bc8ad560a3e1f08d5e93054a5d33:/lisp/emacs-lisp/unsafep.el diff --git a/lisp/emacs-lisp/unsafep.el b/lisp/emacs-lisp/unsafep.el index 00e51f09ba..fb3163455b 100644 --- a/lisp/emacs-lisp/unsafep.el +++ b/lisp/emacs-lisp/unsafep.el @@ -1,6 +1,6 @@ ;;;; unsafep.el -- Determine whether a Lisp form is safe to evaluate -;; Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc. +;; Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc. ;; Author: Jonathan Yavner ;; Maintainer: Jonathan Yavner @@ -8,10 +8,10 @@ ;; This file is part of GNU Emacs. -;; GNU Emacs is free software; you can redistribute it and/or modify +;; GNU Emacs is free software: you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by -;; the Free Software Foundation; either version 2, or (at your option) -;; any later version. +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. ;; GNU Emacs is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -19,9 +19,7 @@ ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License -;; along with GNU Emacs; see the file COPYING. If not, write to the -;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, -;; Boston, MA 02110-1301, USA. +;; along with GNU Emacs. If not, see . ;;; Commentary: @@ -103,22 +101,20 @@ in the parse.") (dolist (x '(;;Special forms and catch if or prog1 prog2 progn while unwind-protect ;;Safe subrs that have some side-effects - ding error message minibuffer-message random read-minibuffer - signal sleep-for string-match throw y-or-n-p yes-or-no-p + ding error random signal sleep-for string-match throw ;;Defsubst functions from subr.el caar cadr cdar cddr ;;Macros from subr.el - save-match-data unless when with-temp-message + save-match-data unless when ;;Functions from subr.el that have side effects - read-passwd split-string replace-regexp-in-string - play-sound-file)) + split-string replace-regexp-in-string play-sound-file)) (put x 'safe-function t)) ;;;###autoload (defun unsafep (form &optional unsafep-vars) - "Return nil if evaluating FORM couldn't possibly do any harm; -otherwise result is a reason why FORM is unsafe. UNSAFEP-VARS is a list -of symbols with local bindings." + "Return nil if evaluating FORM couldn't possibly do any harm. +Otherwise result is a reason why FORM is unsafe. +UNSAFEP-VARS is a list of symbols with local bindings." (catch 'unsafep (if (or (eq safe-functions t) ;User turned off safety-checking (atom form)) ;Atoms are never unsafe @@ -206,15 +202,18 @@ of symbols with local bindings." (dolist (x (nthcdr 3 form)) (setq reason (unsafep-progn (cdr x))) (if reason (throw 'unsafep reason)))))) + ((eq fun '\`) + ;; Backquoted form - safe if its expansion is. + (unsafep (cdr (backquote-process (cadr form))))) (t ;;First unsafep-function call above wasn't nil, no special case applies reason))))) (defun unsafep-function (fun) - "Return nil iff FUN is a safe function. -\(either a safe lambda or a symbol that names a safe function). Otherwise -result is a reason code." + "Return nil if FUN is a safe function. +\(Either a safe lambda or a symbol that names a safe function). +Otherwise result is a reason code." (cond ((eq (car-safe fun) 'lambda) (unsafep fun unsafep-vars)) @@ -226,8 +225,8 @@ result is a reason code." `(function ,fun)))) (defun unsafep-progn (list) - "Return nil if all forms in LIST are safe, or the reason -for the first unsafe form." + "Return nil if all forms in LIST are safe. +Else, return the reason for the first unsafe form." (catch 'unsafep-progn (let (reason) (dolist (x list) @@ -236,8 +235,9 @@ for the first unsafe form." (defun unsafep-let (clause) "Check the safety of a let binding. -CLAUSE is a let-binding, either SYM or (SYM) or (SYM VAL). Checks VAL -and throws a reason to `unsafep' if unsafe. Returns SYM." +CLAUSE is a let-binding, either SYM or (SYM) or (SYM VAL). +Check VAL and throw a reason to `unsafep' if unsafe. +Return SYM." (let (reason sym) (if (atom clause) (setq sym clause) @@ -261,5 +261,4 @@ If TO-BIND is t, check whether SYM is safe to bind." (local-variable-p sym))) `(global-variable ,sym)))) -;; arch-tag: 6216f98b-eb8f-467a-9c33-7a7644f50658 ;;; unsafep.el ends here