/[emacs]/emacs/lispref/functions.texi
ViewVC logotype

Diff of /emacs/lispref/functions.texi

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.21 by lektu, Tue Feb 4 14:47:53 2003 UTC revision 1.22 by rms, Mon Jun 30 10:40:27 2003 UTC
# Line 22  define them. Line 22  define them.
22  * Function Cells::        Accessing or setting the function definition  * Function Cells::        Accessing or setting the function definition
23                              of a symbol.                              of a symbol.
24  * Inline Functions::      Defining functions that the compiler will open code.  * Inline Functions::      Defining functions that the compiler will open code.
25  * Function safety::       Determining whether a function is safe to call.  * Function Safety::       Determining whether a function is safe to call.
26  * Related Topics::        Cross-references to specific Lisp primitives  * Related Topics::        Cross-references to specific Lisp primitives
27                              that have a special bearing on how functions work.                              that have a special bearing on how functions work.
28  @end menu  @end menu
# Line 57  such as @code{car} or @code{append}.  Th Line 57  such as @code{car} or @code{append}.  Th
57  considered primitives.)  considered primitives.)
58    
59  Usually the reason we implement a function as a primitive is either  Usually the reason we implement a function as a primitive is either
60  because it is fundamental, because it provides a low-level interface to  because it is fundamental, because it provides a low-level interface
61  operating system services, or because it needs to run fast.  Primitives  to operating system services, or because it needs to run fast.
62  can be modified or added only by changing the C sources and recompiling  Primitives can be modified or added only by changing the C sources and
63  the editor.  See @ref{Writing Emacs Primitives}.  recompiling the editor.  See @ref{Writing Emacs Primitives}.
64    
65  @item lambda expression  @item lambda expression
66  A @dfn{lambda expression} is a function written in Lisp.  A @dfn{lambda expression} is a function written in Lisp.
# Line 573  purposes, it is better to use @code{fset Line 573  purposes, it is better to use @code{fset
573  records.  records.
574  @end defun  @end defun
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
578    any symbol, even one such as @code{car} or @code{x-popup-menu} whose
579    normal definition is a primitive.  However, this is risky: for
580    instance, it is next to impossible to redefine @code{car} without
581    breaking Lisp completely.  Redefining an obscure function such as
582    @code{x-popup-menu} is less dangerous, but it still may not work as
583    you expect.  If there are calls to the primitive from C code, they
584    call the primitive's C definition directly, so changing the symbol's
585    definition will have no effect on them.
586    
587    See also @code{defsubst}, which defines a function like @code{defun}    See also @code{defsubst}, which defines a function like @code{defun}
588  and tells the Lisp compiler to open-code it.  @xref{Inline Functions}.  and tells the Lisp compiler to open-code it.  @xref{Inline Functions}.
589    
# Line 1158  do for macros.  (@xref{Argument Evaluati Line 1169  do for macros.  (@xref{Argument Evaluati
1169  Inline functions can be used and open-coded later on in the same file,  Inline functions can be used and open-coded later on in the same file,
1170  following the definition, just like macros.  following the definition, just like macros.
1171    
1172  @node Function safety  @node Function Safety
1173  @section Determining whether a function is safe to call  @section Determining whether a function is safe to call
1174  @cindex function safety  @cindex function safety
1175  @cindex safety of functions  @cindex safety of functions
1176  @cindex virus detection  
1177  @cindex Trojan-horse detection  Some major modes such as SES (@pxref{Top,,,ses}) call functions that
1178  @cindex DDoS attacks  are stored in user files.  User files sometimes have poor
1179    pedigrees---you can get a spreadsheet from someone you've just met, or
1180  Some major modes such as SES (see @pxref{Top,,,ses}) will call  you can get one through email from someone you've never met.  So it is
1181  functions that are stored in user files.  User files sometimes have  risky to call a function whose source code is stored in a user file
1182  poor pedigrees---you can get a spreadsheet from someone you've just  until you have determined that it is safe.
 met, or you can get one through email from someone you've never met.  
 Such files can contain viruses and other Trojan horses that could  
 corrupt your operating system environment, delete your files, or even  
 turn your computer into a DDoS zombie!  To avoid this terrible fate,  
 you should not call a function whose source code is stored in a user  
 file until you have determined that it is safe.  
1183    
1184  @defun unsafep form &optional unsafep-vars  @defun unsafep form &optional unsafep-vars
1185  Returns nil if @var{form} is a @dfn{safe} lisp expression, or returns  Returns @code{nil} if @var{form} is a @dfn{safe} lisp expression, or
1186  a list that describes why it might be unsafe.  The argument  returns a list that describes why it might be unsafe.  The argument
1187  @var{unsafep-vars} is a list of symbols known to have temporary  @var{unsafep-vars} is a list of symbols known to have temporary
1188  bindings at this point; it is mainly used for internal recursive  bindings at this point; it is mainly used for internal recursive
1189  calls.  The current buffer is an implicit argument, which provides a  calls.  The current buffer is an implicit argument, which provides a
# Line 1187  list of buffer-local bindings. Line 1192  list of buffer-local bindings.
1192    
1193  Being quick and simple, @code{unsafep} does a very light analysis and  Being quick and simple, @code{unsafep} does a very light analysis and
1194  rejects many Lisp expressions that are actually safe.  There are no  rejects many Lisp expressions that are actually safe.  There are no
1195  known cases where @code{unsafep} returns nil for an unsafe expression.  known cases where @code{unsafep} returns @code{nil} for an unsafe
1196  However, a ``safe'' Lisp expression can return a string with a  expression.  However, a ``safe'' Lisp expression can return a string
1197  @code{display} property, containing an associated Lisp expression to  with a @code{display} property, containing an associated Lisp
1198  be executed after the string is inserted into a buffer.  This  expression to be executed after the string is inserted into a buffer.
1199  associated expression can be a virus.  In order to be safe, you must  This associated expression can be a virus.  In order to be safe, you
1200  delete properties from all strings calculated by user code before  must delete properties from all strings calculated by user code before
1201  inserting them into buffers.  inserting them into buffers.
1202    
1203    @ignore
1204  What is a safe Lisp expression?  Basically, it's an expression that  What is a safe Lisp expression?  Basically, it's an expression that
1205  calls only built-in functions with no side effects (or only innocuous  calls only built-in functions with no side effects (or only innocuous
1206  ones).  Innocuous side effects include displaying messages and  ones).  Innocuous side effects include displaying messages and
# Line 1209  An atom or quoted thing. Line 1215  An atom or quoted thing.
1215  A call to a safe function (see below), if all its arguments are  A call to a safe function (see below), if all its arguments are
1216  safe expressions.  safe expressions.
1217  @item  @item
1218  One of the special forms [and, catch, cond, if, or, prog1, prog2,  One of the special forms @code{and}, @code{catch}, @code{cond},
1219  progn, while, unwind-protect], if all its arguments are safe.  @code{if}, @code{or}, @code{prog1}, @code{prog2}, @code{progn},
1220    @code{while}, and @code{unwind-protect}], if all its arguments are
1221    safe.
1222  @item  @item
1223  A form that creates temporary bindings [condition-case, dolist,  A form that creates temporary bindings (@code{condition-case},
1224  dotimes, lambda, let, let*], if all args are safe and the symbols to  @code{dolist}, @code{dotimes}, @code{lambda}, @code{let}, or
1225  be bound are not explicitly risky (see @pxref{File Local Variables}).  @code{let*}), if all args are safe and the symbols to be bound are not
1226    explicitly risky (see @pxref{File Local Variables}).
1227  @item  @item
1228  An assignment [add-to-list, setq, push, pop], if all args are safe and  An assignment using @code{add-to-list}, @code{setq}, @code{push}, or
1229  the symbols to be assigned are not explicitly risky and they already  @code{pop}, if all args are safe and the symbols to be assigned are
1230  have temporary or buffer-local bindings.  not explicitly risky and they already have temporary or buffer-local
1231    bindings.
1232  @item  @item
1233  One of [apply, mapc, mapcar, mapconcat] if the first argument is a  One of [apply, mapc, mapcar, mapconcat] if the first argument is a
1234  safe explicit lambda and the other args are safe expressions.  safe explicit lambda and the other args are safe expressions.
# Line 1231  A lambda containing safe expressions. Line 1241  A lambda containing safe expressions.
1241  @item  @item
1242  A symbol on the list @code{safe-functions}, so the user says it's safe.  A symbol on the list @code{safe-functions}, so the user says it's safe.
1243  @item  @item
1244  A symbol with a non-nil @code{side-effect-free} property.  A symbol with a non-@code{nil} @code{side-effect-free} property.
1245  @item  @item
1246  A symbol with a non-nil @code{safe-function} property.  Value t  A symbol with a non-@code{nil} @code{safe-function} property.  Value t
1247  indicates a function that is safe but has innocuous side effects.  indicates a function that is safe but has innocuous side effects.
1248  Other values will someday indicate functions with classes of side  Other values will someday indicate functions with classes of side
1249  effects that are not always safe.  effects that are not always safe.
# Line 1243  The @code{side-effect-free} and @code{sa Line 1253  The @code{side-effect-free} and @code{sa
1253  provided for built-in functions and for low-level functions and macros  provided for built-in functions and for low-level functions and macros
1254  defined in @file{subr.el}.  You can assign these properties for the  defined in @file{subr.el}.  You can assign these properties for the
1255  functions you write.  functions you write.
   
1256  @end table  @end table
1257    @end ignore
   
 @c Emacs versions prior to 19 did not have inline functions.  
1258    
1259  @node Related Topics  @node Related Topics
1260  @section Other Topics Related to Functions  @section Other Topics Related to Functions

Legend:
Removed from v.1.21  
changed lines
  Added in v.1.22

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26