]> code.delx.au - gnu-emacs/blobdiff - src/lread.c
* lread.c (read1, init_obarray): Don't update size until alloc done.
[gnu-emacs] / src / lread.c
index c80ac430671725391bba21a983c58addee1a9f39..3703fdf5d3e36fcc00f441a34b3507853bf7d664 100644 (file)
@@ -2327,8 +2327,7 @@ read_integer (Lisp_Object readcharfun, EMACS_INT radix)
          c = READCHAR;
        }
 
-      if (c >= 0)
-       UNREAD (c);
+      UNREAD (c);
       *p = '\0';
     }
 
@@ -2583,8 +2582,7 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list)
              nskip *= 10;
              nskip += c - '0';
            }
-         if (c >= 0)
-           UNREAD (c);
+         UNREAD (c);
 
          if (load_force_doc_strings
              && (EQ (readcharfun, Qget_file_char)
@@ -2615,14 +2613,14 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list)
 
              if (saved_doc_string_size == 0)
                {
+                 saved_doc_string = (char *) xmalloc (nskip + extra);
                  saved_doc_string_size = nskip + extra;
-                 saved_doc_string = (char *) xmalloc (saved_doc_string_size);
                }
              if (nskip > saved_doc_string_size)
                {
-                 saved_doc_string_size = nskip + extra;
                  saved_doc_string = (char *) xrealloc (saved_doc_string,
-                                                       saved_doc_string_size);
+                                                       nskip + extra);
+                 saved_doc_string_size = nskip + extra;
                }
 
              saved_doc_string_position = file_tell (instream);
@@ -2660,7 +2658,17 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list)
        {
          uninterned_symbol = 1;
          c = READCHAR;
-         goto default_label;
+         if (!(c > 040
+               && c != 0x8a0
+               && (c >= 0200
+                   || strchr ("\"';()[]#`,", c) == NULL)))
+           {
+             /* No symbol character follows, this is the empty
+                symbol.  */
+             UNREAD (c);
+             return Fmake_symbol (build_string (""));
+           }
+         goto read_symbol;
        }
       /* Reader forms that can reuse previously read objects.  */
       if (c >= '0' && c <= '9')
@@ -2841,7 +2849,7 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list)
        next_char = READCHAR;
        ok = (next_char <= 040
              || (next_char < 0200
-                 && (strchr ("\"';()[]#?`,.", next_char))));
+                 && strchr ("\"';()[]#?`,.", next_char) != NULL));
        UNREAD (next_char);
        if (ok)
          return make_number (c);
@@ -2872,7 +2880,8 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list)
                if (min (PTRDIFF_MAX, SIZE_MAX) / 2 < read_buffer_size)
                  memory_full (SIZE_MAX);
                read_buffer = (char *) xrealloc (read_buffer,
-                                                read_buffer_size *= 2);
+                                                read_buffer_size * 2);
+               read_buffer_size *= 2;
                p = read_buffer + offset;
                end = read_buffer + read_buffer_size;
              }
@@ -2966,11 +2975,6 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list)
            /* 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
-          string.  ... But it doesn't seem to be necessary, because
-          READCHAR *does* read multibyte characters from buffers. */
-       /* readchar_count -= (p - read_buffer) - nchars; */
        if (read_pure)
          return make_pure_string (read_buffer, nchars, p - read_buffer,
                                   (force_multibyte
@@ -2987,7 +2991,7 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list)
 
        if (next_char <= 040
            || (next_char < 0200
-               && (strchr ("\"';([#?`,", next_char))))
+               && strchr ("\"';([#?`,", next_char) != NULL))
          {
            *pch = c;
            return Qnil;
@@ -3002,9 +3006,12 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list)
       if (c <= 040) goto retry;
       if (c == 0x8a0) /* NBSP */
        goto retry;
+
+    read_symbol:
       {
        char *p = read_buffer;
        int quoted = 0;
+       EMACS_INT start_position = readchar_count - 1;
 
        {
          char *end = read_buffer + read_buffer_size;
@@ -3017,7 +3024,8 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list)
                  if (min (PTRDIFF_MAX, SIZE_MAX) / 2 < read_buffer_size)
                    memory_full (SIZE_MAX);
                  read_buffer = (char *) xrealloc (read_buffer,
-                                                  read_buffer_size *= 2);
+                                                  read_buffer_size * 2);
+                 read_buffer_size *= 2;
                  p = read_buffer + offset;
                  end = read_buffer + read_buffer_size;
                }
@@ -3035,10 +3043,11 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list)
              else
                *p++ = c;
              c = READCHAR;
-           } while (c > 040
-                    && c != 0x8a0 /* NBSP */
-                    && (c >= 0200
-                        || !(strchr ("\"';()[]#`,", c))));
+           }
+         while (c > 040
+                && c != 0x8a0 /* NBSP */
+                && (c >= 0200
+                    || strchr ("\"';()[]#`,", c) == NULL));
 
          if (p == end)
            {
@@ -3046,13 +3055,13 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list)
              if (min (PTRDIFF_MAX, SIZE_MAX) / 2 < read_buffer_size)
                memory_full (SIZE_MAX);
              read_buffer = (char *) xrealloc (read_buffer,
-                                              read_buffer_size *= 2);
+                                              read_buffer_size * 2);
+             read_buffer_size *= 2;
              p = read_buffer + offset;
              end = read_buffer + read_buffer_size;
            }
          *p = 0;
-         if (c >= 0)
-           UNREAD (c);
+         UNREAD (c);
        }
 
        if (!quoted && !uninterned_symbol)
@@ -3080,12 +3089,7 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list)
          if (EQ (Vread_with_symbol_positions, Qt)
              || EQ (Vread_with_symbol_positions, readcharfun))
            Vread_symbol_positions_list =
-             /* Kind of a hack; this will probably fail if characters
-                in the symbol name were escaped.  Not really a big
-                deal, though.  */
-             Fcons (Fcons (result,
-                           make_number (readchar_count
-                                        - XFASTINT (Flength (Fsymbol_name (result))))),
+             Fcons (Fcons (result, make_number (start_position)),
                     Vread_symbol_positions_list);
          return result;
        }
@@ -3934,6 +3938,7 @@ void
 init_obarray (void)
 {
   Lisp_Object oblength;
+  ptrdiff_t size = 100 + MAX_MULTIBYTE_LENGTH;
 
   XSETFASTINT (oblength, OBARRAY_SIZE);
 
@@ -3966,8 +3971,8 @@ init_obarray (void)
 
   DEFSYM (Qvariable_documentation, "variable-documentation");
 
-  read_buffer_size = 100 + MAX_MULTIBYTE_LENGTH;
-  read_buffer = (char *) xmalloc (read_buffer_size);
+  read_buffer = (char *) xmalloc (size);
+  read_buffer_size = size;
 }
 \f
 void
@@ -4490,10 +4495,9 @@ to load.  See also `load-dangerous-libraries'.  */);
   Qlexical_binding = intern ("lexical-binding");
   staticpro (&Qlexical_binding);
   DEFVAR_LISP ("lexical-binding", Vlexical_binding,
-              doc: /* If non-nil, use lexical binding when evaluating code.
-This applies to code evaluated by `eval-buffer' and `eval-region' and
-other commands that call these functions, like `eval-defun' and
-the like.
+              doc: /* Whether to use lexical binding when evaluating code.
+Non-nil means that the code in the current buffer should be evaluated
+with lexical binding.
 This variable is automatically set from the file variables of an
 interpreted Lisp file read using `load'.  */);
   Fmake_variable_buffer_local (Qlexical_binding);