aboutsummaryrefslogtreecommitdiffstats
path: root/lispref
diff options
context:
space:
mode:
authorRichard M. Stallman2003-06-30 10:40:27 +0000
committerRichard M. Stallman2003-06-30 10:40:27 +0000
commita68defffdafbe7e61b8db90d534c04e147b14f91 (patch)
tree7c883e0c494bfaabe41bffeb831fa7eca14ac9a0 /lispref
parent6a4803ec738ba800eab12bf776c38f1b5345c2d7 (diff)
downloademacs-a68defffdafbe7e61b8db90d534c04e147b14f91.tar.gz
emacs-a68defffdafbe7e61b8db90d534c04e147b14f91.zip
(Defining Functions): Explain about redefining primitives.
(Function Safety): Renamed. Minor changes. Comment out the detailed criteria for what is safe.
Diffstat (limited to 'lispref')
-rw-r--r--lispref/functions.texi89
1 files changed, 48 insertions, 41 deletions
diff --git a/lispref/functions.texi b/lispref/functions.texi
index 576ad51b006..9ffb6561b23 100644
--- a/lispref/functions.texi
+++ b/lispref/functions.texi
@@ -22,7 +22,7 @@ define them.
22* Function Cells:: Accessing or setting the function definition 22* Function Cells:: Accessing or setting the function definition
23 of a symbol. 23 of a symbol.
24* Inline Functions:: Defining functions that the compiler will open code. 24* Inline Functions:: Defining functions that the compiler will open code.
25* Function safety:: Determining whether a function is safe to call. 25* Function Safety:: Determining whether a function is safe to call.
26* Related Topics:: Cross-references to specific Lisp primitives 26* Related Topics:: Cross-references to specific Lisp primitives
27 that have a special bearing on how functions work. 27 that have a special bearing on how functions work.
28@end menu 28@end menu
@@ -57,10 +57,10 @@ such as @code{car} or @code{append}. These functions are also called
57considered primitives.) 57considered primitives.)
58 58
59Usually the reason we implement a function as a primitive is either 59Usually the reason we implement a function as a primitive is either
60because it is fundamental, because it provides a low-level interface to 60because it is fundamental, because it provides a low-level interface
61operating system services, or because it needs to run fast. Primitives 61to operating system services, or because it needs to run fast.
62can be modified or added only by changing the C sources and recompiling 62Primitives can be modified or added only by changing the C sources and
63the editor. See @ref{Writing Emacs Primitives}. 63recompiling the editor. See @ref{Writing Emacs Primitives}.
64 64
65@item lambda expression 65@item lambda expression
66A @dfn{lambda expression} is a function written in Lisp. 66A @dfn{lambda expression} is a function written in Lisp.
@@ -573,6 +573,17 @@ purposes, it is better to use @code{fset}, which does not keep such
573records. 573records.
574@end defun 574@end defun
575 575
576 You cannot create a new primitive function with @code{defun} or
577@code{defalias}, but you use them to change the function definition of
578any symbol, even one such as @code{car} or @code{x-popup-menu} whose
579normal definition is a primitive. However, this is risky: for
580instance, it is next to impossible to redefine @code{car} without
581breaking Lisp completely. Redefining an obscure function such as
582@code{x-popup-menu} is less dangerous, but it still may not work as
583you expect. If there are calls to the primitive from C code, they
584call the primitive's C definition directly, so changing the symbol's
585definition will have no effect on them.
586
576 See also @code{defsubst}, which defines a function like @code{defun} 587 See also @code{defsubst}, which defines a function like @code{defun}
577and tells the Lisp compiler to open-code it. @xref{Inline Functions}. 588and tells the Lisp compiler to open-code it. @xref{Inline Functions}.
578 589
@@ -1158,27 +1169,21 @@ do for macros. (@xref{Argument Evaluation}.)
1158Inline functions can be used and open-coded later on in the same file, 1169Inline functions can be used and open-coded later on in the same file,
1159following the definition, just like macros. 1170following the definition, just like macros.
1160 1171
1161@node Function safety 1172@node Function Safety
1162@section Determining whether a function is safe to call 1173@section Determining whether a function is safe to call
1163@cindex function safety 1174@cindex function safety
1164@cindex safety of functions 1175@cindex safety of functions
1165@cindex virus detection 1176
1166@cindex Trojan-horse detection 1177Some major modes such as SES (@pxref{Top,,,ses}) call functions that
1167@cindex DDoS attacks 1178are stored in user files. User files sometimes have poor
1168 1179pedigrees---you can get a spreadsheet from someone you've just met, or
1169Some major modes such as SES (see @pxref{Top,,,ses}) will call 1180you can get one through email from someone you've never met. So it is
1170functions that are stored in user files. User files sometimes have 1181risky to call a function whose source code is stored in a user file
1171poor pedigrees---you can get a spreadsheet from someone you've just 1182until you have determined that it is safe.
1172met, or you can get one through email from someone you've never met.
1173Such files can contain viruses and other Trojan horses that could
1174corrupt your operating system environment, delete your files, or even
1175turn your computer into a DDoS zombie! To avoid this terrible fate,
1176you should not call a function whose source code is stored in a user
1177file until you have determined that it is safe.
1178 1183
1179@defun unsafep form &optional unsafep-vars 1184@defun unsafep form &optional unsafep-vars
1180Returns nil if @var{form} is a @dfn{safe} lisp expression, or returns 1185Returns @code{nil} if @var{form} is a @dfn{safe} lisp expression, or
1181a list that describes why it might be unsafe. The argument 1186returns a list that describes why it might be unsafe. The argument
1182@var{unsafep-vars} is a list of symbols known to have temporary 1187@var{unsafep-vars} is a list of symbols known to have temporary
1183bindings at this point; it is mainly used for internal recursive 1188bindings at this point; it is mainly used for internal recursive
1184calls. The current buffer is an implicit argument, which provides a 1189calls. The current buffer is an implicit argument, which provides a
@@ -1187,14 +1192,15 @@ list of buffer-local bindings.
1187 1192
1188Being quick and simple, @code{unsafep} does a very light analysis and 1193Being quick and simple, @code{unsafep} does a very light analysis and
1189rejects many Lisp expressions that are actually safe. There are no 1194rejects many Lisp expressions that are actually safe. There are no
1190known cases where @code{unsafep} returns nil for an unsafe expression. 1195known cases where @code{unsafep} returns @code{nil} for an unsafe
1191However, a ``safe'' Lisp expression can return a string with a 1196expression. However, a ``safe'' Lisp expression can return a string
1192@code{display} property, containing an associated Lisp expression to 1197with a @code{display} property, containing an associated Lisp
1193be executed after the string is inserted into a buffer. This 1198expression to be executed after the string is inserted into a buffer.
1194associated expression can be a virus. In order to be safe, you must 1199This associated expression can be a virus. In order to be safe, you
1195delete properties from all strings calculated by user code before 1200must delete properties from all strings calculated by user code before
1196inserting them into buffers. 1201inserting them into buffers.
1197 1202
1203@ignore
1198What is a safe Lisp expression? Basically, it's an expression that 1204What is a safe Lisp expression? Basically, it's an expression that
1199calls only built-in functions with no side effects (or only innocuous 1205calls only built-in functions with no side effects (or only innocuous
1200ones). Innocuous side effects include displaying messages and 1206ones). Innocuous side effects include displaying messages and
@@ -1209,16 +1215,20 @@ An atom or quoted thing.
1209A call to a safe function (see below), if all its arguments are 1215A call to a safe function (see below), if all its arguments are
1210safe expressions. 1216safe expressions.
1211@item 1217@item
1212One of the special forms [and, catch, cond, if, or, prog1, prog2, 1218One of the special forms @code{and}, @code{catch}, @code{cond},
1213progn, while, unwind-protect], if all its arguments are safe. 1219@code{if}, @code{or}, @code{prog1}, @code{prog2}, @code{progn},
1220@code{while}, and @code{unwind-protect}], if all its arguments are
1221safe.
1214@item 1222@item
1215A form that creates temporary bindings [condition-case, dolist, 1223A form that creates temporary bindings (@code{condition-case},
1216dotimes, lambda, let, let*], if all args are safe and the symbols to 1224@code{dolist}, @code{dotimes}, @code{lambda}, @code{let}, or
1217be bound are not explicitly risky (see @pxref{File Local Variables}). 1225@code{let*}), if all args are safe and the symbols to be bound are not
1226explicitly risky (see @pxref{File Local Variables}).
1218@item 1227@item
1219An assignment [add-to-list, setq, push, pop], if all args are safe and 1228An assignment using @code{add-to-list}, @code{setq}, @code{push}, or
1220the symbols to be assigned are not explicitly risky and they already 1229@code{pop}, if all args are safe and the symbols to be assigned are
1221have temporary or buffer-local bindings. 1230not explicitly risky and they already have temporary or buffer-local
1231bindings.
1222@item 1232@item
1223One of [apply, mapc, mapcar, mapconcat] if the first argument is a 1233One of [apply, mapc, mapcar, mapconcat] if the first argument is a
1224safe explicit lambda and the other args are safe expressions. 1234safe explicit lambda and the other args are safe expressions.
@@ -1231,9 +1241,9 @@ A lambda containing safe expressions.
1231@item 1241@item
1232A symbol on the list @code{safe-functions}, so the user says it's safe. 1242A symbol on the list @code{safe-functions}, so the user says it's safe.
1233@item 1243@item
1234A symbol with a non-nil @code{side-effect-free} property. 1244A symbol with a non-@code{nil} @code{side-effect-free} property.
1235@item 1245@item
1236A symbol with a non-nil @code{safe-function} property. Value t 1246A symbol with a non-@code{nil} @code{safe-function} property. Value t
1237indicates a function that is safe but has innocuous side effects. 1247indicates a function that is safe but has innocuous side effects.
1238Other values will someday indicate functions with classes of side 1248Other values will someday indicate functions with classes of side
1239effects that are not always safe. 1249effects that are not always safe.
@@ -1243,11 +1253,8 @@ The @code{side-effect-free} and @code{safe-function} properties are
1243provided for built-in functions and for low-level functions and macros 1253provided for built-in functions and for low-level functions and macros
1244defined in @file{subr.el}. You can assign these properties for the 1254defined in @file{subr.el}. You can assign these properties for the
1245functions you write. 1255functions you write.
1246
1247@end table 1256@end table
1248 1257@end ignore
1249
1250@c Emacs versions prior to 19 did not have inline functions.
1251 1258
1252@node Related Topics 1259@node Related Topics
1253@section Other Topics Related to Functions 1260@section Other Topics Related to Functions