Make Emacs functions such as Fatom 'static' by default.
[bpt/emacs.git] / src / lread.c
index c8c07be..7d12f5a 100644 (file)
@@ -370,15 +370,15 @@ unreadchar (Lisp_Object readcharfun, int c)
   else if (BUFFERP (readcharfun))
     {
       struct buffer *b = XBUFFER (readcharfun);
+      EMACS_INT charpos = BUF_PT (b);
       EMACS_INT bytepos = BUF_PT_BYTE (b);
 
-      BUF_PT (b)--;
       if (! NILP (BVAR (b, enable_multibyte_characters)))
        BUF_DEC_POS (b, bytepos);
       else
        bytepos--;
 
-      BUF_PT_BYTE (b) = bytepos;
+      SET_BUF_PT_BOTH (b, charpos - 1, bytepos);
     }
   else if (MARKERP (readcharfun))
     {
@@ -681,7 +681,7 @@ read_filtered_event (int no_switch_frame, int ascii_required,
   return val;
 }
 
-DEFUN ("read-char", Fread_char, Sread_char, 0, 3, 0,
+DEFUE ("read-char", Fread_char, Sread_char, 0, 3, 0,
        doc: /* Read a character from the command input (keyboard or macro).
 It is returned as a number.
 If the character has modifiers, they are resolved and reflected to the
@@ -714,7 +714,7 @@ floating-point value.  */)
          : make_number (char_resolve_modifier_mask (XINT (val))));
 }
 
-DEFUN ("read-event", Fread_event, Sread_event, 0, 3, 0,
+DEFUE ("read-event", Fread_event, Sread_event, 0, 3, 0,
        doc: /* Read an event object from the input stream.
 If the optional argument PROMPT is non-nil, display that as a prompt.
 If the optional argument INHERIT-INPUT-METHOD is non-nil and some
@@ -796,16 +796,16 @@ lisp_file_lexically_bound_p (Lisp_Object readcharfun)
       } beg_end_state = NOMINAL;
       int in_file_vars = 0;
 
-#define UPDATE_BEG_END_STATE(ch)                                             \
-  if (beg_end_state == NOMINAL)                                                      \
-    beg_end_state = (ch == '-' ? AFTER_FIRST_DASH : NOMINAL);                \
-  else if (beg_end_state == AFTER_FIRST_DASH)                                \
-    beg_end_state = (ch == '*' ? AFTER_ASTERIX : NOMINAL);                   \
-  else if (beg_end_state == AFTER_ASTERIX)                                   \
-    {                                                                        \
-      if (ch == '-')                                                         \
-       in_file_vars = !in_file_vars;                                         \
-      beg_end_state = NOMINAL;                                               \
+#define UPDATE_BEG_END_STATE(ch)                               \
+  if (beg_end_state == NOMINAL)                                        \
+    beg_end_state = (ch == '-' ? AFTER_FIRST_DASH : NOMINAL);  \
+  else if (beg_end_state == AFTER_FIRST_DASH)                  \
+    beg_end_state = (ch == '*' ? AFTER_ASTERIX : NOMINAL);     \
+  else if (beg_end_state == AFTER_ASTERIX)                     \
+    {                                                          \
+      if (ch == '-')                                           \
+       in_file_vars = !in_file_vars;                           \
+      beg_end_state = NOMINAL;                                 \
     }
 
       /* Skip until we get to the file vars, if any.  */
@@ -818,7 +818,8 @@ lisp_file_lexically_bound_p (Lisp_Object readcharfun)
 
       while (in_file_vars)
        {
-         char var[100], *var_end, val[100], *val_end;
+         char var[100], val[100];
+         unsigned i;
 
          ch = READCHAR;
 
@@ -826,19 +827,18 @@ lisp_file_lexically_bound_p (Lisp_Object readcharfun)
          while (ch == ' ' || ch == '\t')
            ch = READCHAR;
 
-         var_end = var;
+         i = 0;
          while (ch != ':' && ch != '\n' && ch != EOF)
            {
-             if (var_end < var + sizeof var - 1)
-               *var_end++ = ch;
+             if (i < sizeof var - 1)
+               var[i++] = ch;
              UPDATE_BEG_END_STATE (ch);
              ch = READCHAR;
            }
-         
-         while (var_end > var
-                && (var_end[-1] == ' ' || var_end[-1] == '\t'))
-           var_end--;
-         *var_end = '\0';
+
+         while (i > 0 && (var[i - 1] == ' ' || var[i - 1] == '\t'))
+           i--;
+         var[i] = '\0';
 
          if (ch == ':')
            {
@@ -848,22 +848,21 @@ lisp_file_lexically_bound_p (Lisp_Object readcharfun)
              while (ch == ' ' || ch == '\t')
                ch = READCHAR;
 
-             val_end = val;
+             i = 0;
              while (ch != ';' && ch != '\n' && ch != EOF && in_file_vars)
                {
-                 if (val_end < val + sizeof val - 1)
-                   *val_end++ = ch;
+                 if (i < sizeof val - 1)
+                   val[i++] = ch;
                  UPDATE_BEG_END_STATE (ch);
                  ch = READCHAR;
                }
              if (! in_file_vars)
                /* The value was terminated by an end-marker, which
                   remove.  */
-               val_end -= 3;
-             while (val_end > val
-                    && (val_end[-1] == ' ' || val_end[-1] == '\t'))
-               val_end--;
-             *val_end = '\0';
+               i -= 3;
+             while (i > 0 && (val[i - 1] == ' ' || val[i - 1] == '\t'))
+               i--;
+             val[i] = '\0';
 
              if (strcmp (var, "lexical-binding") == 0)
                /* This is it...  */
@@ -880,7 +879,6 @@ lisp_file_lexically_bound_p (Lisp_Object readcharfun)
       return rv;
     }
 }
-
 \f
 /* Value is a version number of byte compiled code if the file
    associated with file descriptor FD is a compiled Lisp file that's
@@ -909,7 +907,7 @@ safe_to_load_p (int fd)
        if (i == 4)
          version = buf[i];
 
-      if (i == nbytes
+      if (i >= nbytes
          || fast_c_string_match_ignore_case (Vbytecomp_version_regexp,
                                              buf + i) < 0)
        safe_p = 0;
@@ -952,7 +950,7 @@ load_warn_old_style_backquotes (Lisp_Object file)
   return Qnil;
 }
 
-DEFUN ("get-load-suffixes", Fget_load_suffixes, Sget_load_suffixes, 0, 0, 0,
+DEFUE ("get-load-suffixes", Fget_load_suffixes, Sget_load_suffixes, 0, 0, 0,
        doc: /* Return the suffixes that `load' should try if a suffix is \
 required.
 This uses the variables `load-suffixes' and `load-file-rep-suffixes'.  */)
@@ -974,7 +972,7 @@ This uses the variables `load-suffixes' and `load-file-rep-suffixes'.  */)
   return Fnreverse (lst);
 }
 
-DEFUN ("load", Fload, Sload, 1, 5, 0,
+DEFUE ("load", Fload, Sload, 1, 5, 0,
        doc: /* Execute a file of Lisp code named FILE.
 First try FILE with `.elc' appended, then try with `.el',
 then try FILE unmodified (the exact suffixes in the exact order are
@@ -1133,10 +1131,10 @@ Return t if the file exists and loads successfully.  */)
      Also, just loading a file recursively is not always an error in
      the general case; the second load may do something different.  */
   {
-    int count = 0;
+    int load_count = 0;
     Lisp_Object tem;
     for (tem = Vloads_in_progress; CONSP (tem); tem = XCDR (tem))
-      if (!NILP (Fequal (found, XCAR (tem))) && (++count > 3))
+      if (!NILP (Fequal (found, XCAR (tem))) && (++load_count > 3))
        {
          if (fd >= 0)
            emacs_close (fd);
@@ -1275,7 +1273,6 @@ Return t if the file exists and loads successfully.  */)
   specbind (Qinhibit_file_name_operation, Qnil);
   load_descriptor_list
     = Fcons (make_number (fileno (stream)), load_descriptor_list);
-
   specbind (Qload_in_progress, Qt);
 
   instream = stream;
@@ -1787,8 +1784,8 @@ readevalloop (Lisp_Object readcharfun,
                 to a different value when evaluated.  */
              if (BUFFERP (readcharfun))
                {
-                 struct buffer *b = XBUFFER (readcharfun);
-                 if (BUF_PT (b) == BUF_ZV (b))
+                 struct buffer *buf = XBUFFER (readcharfun);
+                 if (BUF_PT (buf) == BUF_ZV (buf))
                    continue_reading_p = 0;
                }
            }
@@ -1863,11 +1860,9 @@ This function preserves the position of point.  */)
 
   specbind (Qeval_buffer_list, Fcons (buf, Veval_buffer_list));
   specbind (Qstandard_output, tem);
-  specbind (Qlexical_binding, Qnil);
   record_unwind_protect (save_excursion_restore, save_excursion_save ());
   BUF_TEMP_SET_PT (XBUFFER (buf), BUF_BEGV (XBUFFER (buf)));
-  if (lisp_file_lexically_bound_p (buf))
-    Fset (Qlexical_binding, Qt);
+  specbind (Qlexical_binding, lisp_file_lexically_bound_p (buf) ? Qt : Qnil);
   readevalloop (buf, 0, filename,
                !NILP (printflag), unibyte, Qnil, Qnil, Qnil);
   unbind_to (count, Qnil);
@@ -1889,6 +1884,7 @@ which is the input stream for reading characters.
 This function does not move point.  */)
   (Lisp_Object start, Lisp_Object end, Lisp_Object printflag, Lisp_Object read_function)
 {
+  /* FIXME: Do the eval-sexp-add-defvars danse!  */
   int count = SPECPDL_INDEX ();
   Lisp_Object tem, cbuf;
 
@@ -1910,7 +1906,7 @@ This function does not move point.  */)
 }
 
 \f
-DEFUN ("read", Fread, Sread, 0, 1, 0,
+DEFUE ("read", Fread, Sread, 0, 1, 0,
        doc: /* Read one Lisp expression as text from STREAM, return as Lisp object.
 If STREAM is nil, use the value of `standard-input' (which see).
 STREAM or the value of `standard-input' may be:
@@ -1933,7 +1929,7 @@ STREAM or the value of `standard-input' may be:
   return read_internal_start (stream, Qnil, Qnil);
 }
 
-DEFUN ("read-from-string", Fread_from_string, Sread_from_string, 1, 3, 0,
+DEFUE ("read-from-string", Fread_from_string, Sread_from_string, 1, 3, 0,
        doc: /* Read one Lisp expression which is represented as text by STRING.
 Returns a cons: (OBJECT-READ . FINAL-STRING-INDEX).
 START and END optionally delimit a substring of STRING from which to read;
@@ -2323,7 +2319,7 @@ static Lisp_Object
 read1 (register Lisp_Object readcharfun, int *pch, int first_in_list)
 {
   register int c;
-  int uninterned_symbol = 0;
+  unsigned uninterned_symbol = 0;
   int multibyte;
 
   *pch = 0;
@@ -2810,7 +2806,7 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list)
       {
        char *p = read_buffer;
        char *end = read_buffer + read_buffer_size;
-       register int c;
+       register int ch;
        /* Nonzero if we saw an escape sequence specifying
           a multibyte character.  */
        int force_multibyte = 0;
@@ -2820,8 +2816,8 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list)
        int cancel = 0;
        int nchars = 0;
 
-       while ((c = READCHAR) >= 0
-              && c != '\"')
+       while ((ch = READCHAR) >= 0
+              && ch != '\"')
          {
            if (end - p < MAX_MULTIBYTE_LENGTH)
              {
@@ -2832,44 +2828,44 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list)
                end = read_buffer + read_buffer_size;
              }
 
-           if (c == '\\')
+           if (ch == '\\')
              {
                int modifiers;
 
-               c = read_escape (readcharfun, 1);
+               ch = read_escape (readcharfun, 1);
 
-               /* C is -1 if \ newline has just been seen */
-               if (c == -1)
+               /* CH is -1 if \ newline has just been seen */
+               if (ch == -1)
                  {
                    if (p == read_buffer)
                      cancel = 1;
                    continue;
                  }
 
-               modifiers = c & CHAR_MODIFIER_MASK;
-               c = c & ~CHAR_MODIFIER_MASK;
+               modifiers = ch & CHAR_MODIFIER_MASK;
+               ch = ch & ~CHAR_MODIFIER_MASK;
 
-               if (CHAR_BYTE8_P (c))
+               if (CHAR_BYTE8_P (ch))
                  force_singlebyte = 1;
-               else if (! ASCII_CHAR_P (c))
+               else if (! ASCII_CHAR_P (ch))
                  force_multibyte = 1;
-               else            /* i.e. ASCII_CHAR_P (c) */
+               else            /* i.e. ASCII_CHAR_P (ch) */
                  {
                    /* Allow `\C- ' and `\C-?'.  */
                    if (modifiers == CHAR_CTL)
                      {
-                       if (c == ' ')
-                         c = 0, modifiers = 0;
-                       else if (c == '?')
-                         c = 127, modifiers = 0;
+                       if (ch == ' ')
+                         ch = 0, modifiers = 0;
+                       else if (ch == '?')
+                         ch = 127, modifiers = 0;
                      }
                    if (modifiers & CHAR_SHIFT)
                      {
                        /* Shift modifier is valid only with [A-Za-z].  */
-                       if (c >= 'A' && c <= 'Z')
+                       if (ch >= 'A' && ch <= 'Z')
                          modifiers &= ~CHAR_SHIFT;
-                       else if (c >= 'a' && c <= 'z')
-                         c -= ('a' - 'A'), modifiers &= ~CHAR_SHIFT;
+                       else if (ch >= 'a' && ch <= 'z')
+                         ch -= ('a' - 'A'), modifiers &= ~CHAR_SHIFT;
                      }
 
                    if (modifiers & CHAR_META)
@@ -2877,7 +2873,7 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list)
                        /* Move the meta bit to the right place for a
                           string.  */
                        modifiers &= ~CHAR_META;
-                       c = BYTE8_TO_CHAR (c | 0x80);
+                       ch = BYTE8_TO_CHAR (ch | 0x80);
                        force_singlebyte = 1;
                      }
                  }
@@ -2885,20 +2881,20 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list)
                /* Any modifiers remaining are invalid.  */
                if (modifiers)
                  error ("Invalid modifier in string");
-               p += CHAR_STRING (c, (unsigned char *) p);
+               p += CHAR_STRING (ch, (unsigned char *) p);
              }
            else
              {
-               p += CHAR_STRING (c, (unsigned char *) p);
-               if (CHAR_BYTE8_P (c))
+               p += CHAR_STRING (ch, (unsigned char *) p);
+               if (CHAR_BYTE8_P (ch))
                  force_singlebyte = 1;
-               else if (! ASCII_CHAR_P (c))
+               else if (! ASCII_CHAR_P (ch))
                  force_multibyte = 1;
              }
            nchars++;
          }
 
-       if (c < 0)
+       if (ch < 0)
          end_of_file_error ();
 
        /* If purifying, and string starts with \ newline,
@@ -2917,8 +2913,9 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list)
            p = read_buffer + nchars;
          }
        else
-         /* Otherwise, READ_BUFFER contains only ASCII.  */
-         ;
+         {
+           /* Otherwise, READ_BUFFER contains only ASCII.  */
+         }
 
        /* We want readchar_count to be the number of characters, not
           bytes.  Hence we adjust for multibyte characters in the
@@ -3334,7 +3331,6 @@ read_vector (Lisp_Object readcharfun, int bytecodeflag)
   for (i = 0; i < size; i++)
     {
       item = Fcar (tem);
-
       /* If `load-force-doc-strings' is t when reading a lazily-loaded
         bytecode object, the docstring containing the bytecode and
         constants values must be treated as unibyte and passed to
@@ -3392,7 +3388,6 @@ read_vector (Lisp_Object readcharfun, int bytecodeflag)
       tem = Fcdr (tem);
       free_cons (otem);
     }
-
   return vector;
 }
 
@@ -3659,7 +3654,7 @@ make_symbol (const char *str)
                       : make_string (str, len));
 }
 \f
-DEFUN ("intern", Fintern, Sintern, 1, 2, 0,
+DEFUE ("intern", Fintern, Sintern, 1, 2, 0,
        doc: /* Return the canonical symbol whose name is STRING.
 If there is none, one is created by this function and returned.
 A second optional argument specifies the obarray to use;
@@ -3705,7 +3700,7 @@ it defaults to the value of `obarray'.  */)
   return sym;
 }
 
-DEFUN ("intern-soft", Fintern_soft, Sintern_soft, 1, 2, 0,
+DEFUE ("intern-soft", Fintern_soft, Sintern_soft, 1, 2, 0,
        doc: /* Return the canonical symbol named NAME, or nil if none exists.
 NAME may be a string or a symbol.  If it is a symbol, that exact
 symbol is searched for.
@@ -3733,7 +3728,7 @@ it defaults to the value of `obarray'.  */)
     return tem;
 }
 \f
-DEFUN ("unintern", Funintern, Sunintern, 1, 2, 0,
+DEFUE ("unintern", Funintern, Sunintern, 1, 2, 0,
        doc: /* Delete the symbol named NAME, if any, from OBARRAY.
 The value is t if a symbol was found and deleted, nil otherwise.
 NAME may be a string or a symbol.  If it is a symbol, that symbol
@@ -4022,7 +4017,6 @@ defvar_lisp (struct Lisp_Objfwd *o_fwd,
   staticpro (address);
 }
 
-
 /* Similar but define a variable whose value is the Lisp Object stored
    at a particular offset in the current kboard object.  */
 
@@ -4468,7 +4462,7 @@ to load.  See also `load-dangerous-libraries'.  */);
               doc: /* If non-nil, use lexical binding when evaluating code.
 This only applies to code evaluated by `eval-buffer' and `eval-region'.
 This variable is automatically set from the file variables of an interpreted
-  lisp file read using `load'.  */);
+  Lisp file read using `load'.  */);
   Fmake_variable_buffer_local (Qlexical_binding);
 
   DEFVAR_LISP ("eval-buffer-list", Veval_buffer_list,