comparison lisp/emacs-lisp/unsafep.el @ 91085:880960b70474

Merge from emacs--devo--0 Revision: emacs@sv.gnu.org/emacs--unicode--0--patch-283
author Miles Bader <miles@gnu.org>
date Sun, 11 Nov 2007 00:56:44 +0000
parents 424b655804ca f095d282aea6
children 606f2d163a64
comparison
equal deleted inserted replaced
91084:a4347a111894 91085:880960b70474
114 play-sound-file)) 114 play-sound-file))
115 (put x 'safe-function t)) 115 (put x 'safe-function t))
116 116
117 ;;;###autoload 117 ;;;###autoload
118 (defun unsafep (form &optional unsafep-vars) 118 (defun unsafep (form &optional unsafep-vars)
119 "Return nil if evaluating FORM couldn't possibly do any harm; 119 "Return nil if evaluating FORM couldn't possibly do any harm.
120 otherwise result is a reason why FORM is unsafe. UNSAFEP-VARS is a list 120 Otherwise result is a reason why FORM is unsafe.
121 of symbols with local bindings." 121 UNSAFEP-VARS is a list of symbols with local bindings."
122 (catch 'unsafep 122 (catch 'unsafep
123 (if (or (eq safe-functions t) ;User turned off safety-checking 123 (if (or (eq safe-functions t) ;User turned off safety-checking
124 (atom form)) ;Atoms are never unsafe 124 (atom form)) ;Atoms are never unsafe
125 (throw 'unsafep nil)) 125 (throw 'unsafep nil))
126 (let* ((fun (car form)) 126 (let* ((fun (car form))
211 reason))))) 211 reason)))))
212 212
213 213
214 (defun unsafep-function (fun) 214 (defun unsafep-function (fun)
215 "Return nil if FUN is a safe function. 215 "Return nil if FUN is a safe function.
216 \(either a safe lambda or a symbol that names a safe function). Otherwise 216 \(Either a safe lambda or a symbol that names a safe function).
217 result is a reason code." 217 Otherwise result is a reason code."
218 (cond 218 (cond
219 ((eq (car-safe fun) 'lambda) 219 ((eq (car-safe fun) 'lambda)
220 (unsafep fun unsafep-vars)) 220 (unsafep fun unsafep-vars))
221 ((not (and (symbolp fun) 221 ((not (and (symbolp fun)
222 (or (get fun 'side-effect-free) 222 (or (get fun 'side-effect-free)
224 (eq safe-functions t) 224 (eq safe-functions t)
225 (memq fun safe-functions)))) 225 (memq fun safe-functions))))
226 `(function ,fun)))) 226 `(function ,fun))))
227 227
228 (defun unsafep-progn (list) 228 (defun unsafep-progn (list)
229 "Return nil if all forms in LIST are safe, or the reason 229 "Return nil if all forms in LIST are safe.
230 for the first unsafe form." 230 Else, return the reason for the first unsafe form."
231 (catch 'unsafep-progn 231 (catch 'unsafep-progn
232 (let (reason) 232 (let (reason)
233 (dolist (x list) 233 (dolist (x list)
234 (setq reason (unsafep x unsafep-vars)) 234 (setq reason (unsafep x unsafep-vars))
235 (if reason (throw 'unsafep-progn reason)))))) 235 (if reason (throw 'unsafep-progn reason))))))
236 236
237 (defun unsafep-let (clause) 237 (defun unsafep-let (clause)
238 "Check the safety of a let binding. 238 "Check the safety of a let binding.
239 CLAUSE is a let-binding, either SYM or (SYM) or (SYM VAL). Checks VAL 239 CLAUSE is a let-binding, either SYM or (SYM) or (SYM VAL).
240 and throws a reason to `unsafep' if unsafe. Returns SYM." 240 Check VAL and throw a reason to `unsafep' if unsafe.
241 Return SYM."
241 (let (reason sym) 242 (let (reason sym)
242 (if (atom clause) 243 (if (atom clause)
243 (setq sym clause) 244 (setq sym clause)
244 (setq sym (car clause) 245 (setq sym (car clause)
245 reason (unsafep (cadr clause) unsafep-vars))) 246 reason (unsafep (cadr clause) unsafep-vars)))