Make read-symbol-positions-list more accurate
[bpt/emacs.git] / src / lread.c
index b789457..ef1b1a8 100644 (file)
@@ -120,9 +120,9 @@ static EMACS_INT readchar_count;
 /* This contains the last string skipped with #@.  */
 static char *saved_doc_string;
 /* Length of buffer allocated in saved_doc_string.  */
-static int saved_doc_string_size;
+static ptrdiff_t saved_doc_string_size;
 /* Length of actual data in saved_doc_string.  */
-static int saved_doc_string_length;
+static ptrdiff_t saved_doc_string_length;
 /* This is the file position that string came from.  */
 static file_offset saved_doc_string_position;
 
@@ -131,9 +131,9 @@ static file_offset saved_doc_string_position;
    is put in saved_doc_string.  */
 static char *prev_saved_doc_string;
 /* Length of buffer allocated in prev_saved_doc_string.  */
-static int prev_saved_doc_string_size;
+static ptrdiff_t prev_saved_doc_string_size;
 /* Length of actual data in prev_saved_doc_string.  */
-static int prev_saved_doc_string_length;
+static ptrdiff_t prev_saved_doc_string_length;
 /* This is the file position that string came from.  */
 static file_offset prev_saved_doc_string_position;
 
@@ -158,7 +158,7 @@ static void readevalloop (Lisp_Object, FILE*, Lisp_Object, int,
 static Lisp_Object load_unwind (Lisp_Object);
 static Lisp_Object load_descriptor_unwind (Lisp_Object);
 
-static void invalid_syntax (const char *, int) NO_RETURN;
+static void invalid_syntax (const char *) NO_RETURN;
 static void end_of_file_error (void) NO_RETURN;
 
 \f
@@ -1069,9 +1069,9 @@ Return t if the file exists and loads successfully.  */)
 
   /* Avoid weird lossage with null string as arg,
      since it would try to load a directory as a Lisp file */
-  if (SCHARS (file) > 0)
+  if (SBYTES (file) > 0)
     {
-      int size = SBYTES (file);
+      ptrdiff_t size = SBYTES (file);
 
       found = Qnil;
       GCPRO2 (file, found);
@@ -1472,7 +1472,7 @@ openp (Lisp_Object path, Lisp_Object str, Lisp_Object suffixes, Lisp_Object *sto
       for (tail = NILP (suffixes) ? Fcons (empty_unibyte_string, Qnil) : suffixes;
           CONSP (tail); tail = XCDR (tail))
        {
-         int lsuffix = SBYTES (XCAR (tail));
+         ptrdiff_t lsuffix = SBYTES (XCAR (tail));
          Lisp_Object handler;
          int exists;
 
@@ -2014,11 +2014,9 @@ read_internal_start (Lisp_Object stream, Lisp_Object start, Lisp_Object end)
    S is error string of length N (if > 0)  */
 
 static void
-invalid_syntax (const char *s, int n)
+invalid_syntax (const char *s)
 {
-  if (!n)
-    n = strlen (s);
-  xsignal1 (Qinvalid_read_syntax, make_string (s, n));
+  xsignal1 (Qinvalid_read_syntax, build_string (s));
 }
 
 
@@ -2039,7 +2037,7 @@ read0 (Lisp_Object readcharfun)
            Fmake_string (make_number (1), make_number (c)));
 }
 \f
-static int read_buffer_size;
+static ptrdiff_t read_buffer_size;
 static char *read_buffer;
 
 /* Read a \-escape sequence, assuming we already read the `\'.
@@ -2210,7 +2208,9 @@ read_escape (Lisp_Object readcharfun, int stringp)
                UNREAD (c);
                break;
              }
-           count++;
+           if (MAX_CHAR < i)
+             error ("Hex character out of range: \\x%x...", i);
+           count += count < 3;
          }
 
        if (count < 3 && i >= 0x80)
@@ -2238,10 +2238,7 @@ read_escape (Lisp_Object readcharfun, int stringp)
            else if (c >= 'a' && c <= 'f')  i = (i << 4) + (c - 'a') + 10;
             else if (c >= 'A' && c <= 'F')  i = (i << 4) + (c - 'A') + 10;
            else
-             {
-               error ("Non-hex digit used for Unicode escape");
-               break;
-             }
+             error ("Non-hex digit used for Unicode escape");
          }
        if (i > 0x10FFFF)
          error ("Non-Unicode character: 0x%x", i);
@@ -2280,10 +2277,12 @@ digit_to_number (int character, int base)
    range.  */
 
 static Lisp_Object
-read_integer (Lisp_Object readcharfun, int radix)
+read_integer (Lisp_Object readcharfun, EMACS_INT radix)
 {
-  /* Room for sign, leading 0, other digits, trailing null byte.  */
-  char buf[1 + 1 + sizeof (uintmax_t) * CHAR_BIT + 1];
+  /* Room for sign, leading 0, other digits, trailing null byte.
+     Also, room for invalid syntax diagnostic.  */
+  char buf[max (1 + 1 + sizeof (uintmax_t) * CHAR_BIT + 1,
+               sizeof "integer, radix " + INT_STRLEN_BOUND (EMACS_INT))];
 
   int valid = -1; /* 1 if valid, 0 if not, -1 if incomplete.  */
 
@@ -2328,15 +2327,14 @@ read_integer (Lisp_Object readcharfun, int radix)
          c = READCHAR;
        }
 
-      if (c >= 0)
-       UNREAD (c);
+      UNREAD (c);
       *p = '\0';
     }
 
   if (! valid)
     {
-      sprintf (buf, "integer, radix %d", radix);
-      invalid_syntax (buf, 0);
+      sprintf (buf, "integer, radix %"pI"d", radix);
+      invalid_syntax (buf);
     }
 
   return string_to_number (buf, radix, 0);
@@ -2453,7 +2451,7 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list)
              return ht;
            }
          UNREAD (c);
-         invalid_syntax ("#", 1);
+         invalid_syntax ("#");
        }
       if (c == '^')
        {
@@ -2473,7 +2471,7 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list)
              if (c == '[')
                {
                  Lisp_Object tmp;
-                 int depth, size;
+                 EMACS_INT depth, size;
 
                  tmp = read_vector (readcharfun, 0);
                  if (!INTEGERP (AREF (tmp, 0)))
@@ -2487,9 +2485,9 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list)
                  XSETPVECTYPE (XVECTOR (tmp), PVEC_SUB_CHAR_TABLE);
                  return tmp;
                }
-             invalid_syntax ("#^^", 3);
+             invalid_syntax ("#^^");
            }
-         invalid_syntax ("#^", 2);
+         invalid_syntax ("#^");
        }
       if (c == '&')
        {
@@ -2499,7 +2497,7 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list)
          if (c == '"')
            {
              Lisp_Object tmp, val;
-             int size_in_chars
+             EMACS_INT size_in_chars
                = ((XFASTINT (length) + BOOL_VECTOR_BITS_PER_CHAR - 1)
                   / BOOL_VECTOR_BITS_PER_CHAR);
 
@@ -2513,7 +2511,7 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list)
                         version.  */
                      && ! (XFASTINT (length)
                            == (SCHARS (tmp) - 1) * BOOL_VECTOR_BITS_PER_CHAR)))
-               invalid_syntax ("#&...", 5);
+               invalid_syntax ("#&...");
 
              val = Fmake_bool_vector (length, Qnil);
              memcpy (XBOOL_VECTOR (val)->data, SDATA (tmp), size_in_chars);
@@ -2523,7 +2521,7 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list)
                  &= (1 << (XINT (length) % BOOL_VECTOR_BITS_PER_CHAR)) - 1;
              return val;
            }
-         invalid_syntax ("#&...", 5);
+         invalid_syntax ("#&...");
        }
       if (c == '[')
        {
@@ -2543,7 +2541,7 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list)
          /* Read the string itself.  */
          tmp = read1 (readcharfun, &ch, 0);
          if (ch != 0 || !STRINGP (tmp))
-           invalid_syntax ("#", 1);
+           invalid_syntax ("#");
          GCPRO1 (tmp);
          /* Read the intervals and their properties.  */
          while (1)
@@ -2559,7 +2557,7 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list)
              if (ch == 0)
                plist = read1 (readcharfun, &ch, 0);
              if (ch)
-               invalid_syntax ("Invalid string property list", 0);
+               invalid_syntax ("Invalid string property list");
              Fset_text_properties (beg, end, plist, tmp);
            }
          UNGCPRO;
@@ -2571,18 +2569,20 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list)
         and function definitions.  */
       if (c == '@')
        {
-         int i, nskip = 0;
+         enum { extra = 100 };
+         ptrdiff_t i, nskip = 0;
 
          load_each_byte = 1;
          /* Read a decimal integer.  */
          while ((c = READCHAR) >= 0
                 && c >= '0' && c <= '9')
            {
+             if ((STRING_BYTES_BOUND - extra) / 10 <= nskip)
+               string_overflow ();
              nskip *= 10;
              nskip += c - '0';
            }
-         if (c >= 0)
-           UNREAD (c);
+         UNREAD (c);
 
          if (load_force_doc_strings
              && (EQ (readcharfun, Qget_file_char)
@@ -2596,9 +2596,9 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list)
                 with prev_saved_doc_string, so we save two strings.  */
              {
                char *temp = saved_doc_string;
-               int temp_size = saved_doc_string_size;
+               ptrdiff_t temp_size = saved_doc_string_size;
                file_offset temp_pos = saved_doc_string_position;
-               int temp_len = saved_doc_string_length;
+               ptrdiff_t temp_len = saved_doc_string_length;
 
                saved_doc_string = prev_saved_doc_string;
                saved_doc_string_size = prev_saved_doc_string_size;
@@ -2613,12 +2613,12 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list)
 
              if (saved_doc_string_size == 0)
                {
-                 saved_doc_string_size = nskip + 100;
+                 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 + 100;
+                 saved_doc_string_size = nskip + extra;
                  saved_doc_string = (char *) xrealloc (saved_doc_string,
                                                        saved_doc_string_size);
                }
@@ -2658,54 +2658,75 @@ 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')
        {
-         int n = 0;
+         EMACS_INT n = 0;
          Lisp_Object tem;
 
          /* Read a non-negative integer.  */
          while (c >= '0' && c <= '9')
            {
-             n *= 10;
-             n += c - '0';
+             if (MOST_POSITIVE_FIXNUM / 10 < n
+                 || MOST_POSITIVE_FIXNUM < n * 10 + c - '0')
+               n = MOST_POSITIVE_FIXNUM + 1;
+             else
+               n = n * 10 + c - '0';
              c = READCHAR;
            }
-         /* #n=object returns object, but associates it with n for #n#.  */
-         if (c == '=' && !NILP (Vread_circle))
+
+         if (n <= MOST_POSITIVE_FIXNUM)
            {
-             /* Make a placeholder for #n# to use temporarily */
-             Lisp_Object placeholder;
-             Lisp_Object cell;
+             if (c == 'r' || c == 'R')
+               return read_integer (readcharfun, n);
 
-             placeholder = Fcons (Qnil, Qnil);
-             cell = Fcons (make_number (n), placeholder);
-             read_objects = Fcons (cell, read_objects);
+             if (! NILP (Vread_circle))
+               {
+                 /* #n=object returns object, but associates it with
+                      n for #n#.  */
+                 if (c == '=')
+                   {
+                     /* Make a placeholder for #n# to use temporarily */
+                     Lisp_Object placeholder;
+                     Lisp_Object cell;
 
-             /* Read the object itself. */
-             tem = read0 (readcharfun);
+                     placeholder = Fcons (Qnil, Qnil);
+                     cell = Fcons (make_number (n), placeholder);
+                     read_objects = Fcons (cell, read_objects);
 
-             /* Now put it everywhere the placeholder was... */
-             substitute_object_in_subtree (tem, placeholder);
+                     /* Read the object itself. */
+                     tem = read0 (readcharfun);
 
-             /* ...and #n# will use the real value from now on.  */
-             Fsetcdr (cell, tem);
+                     /* Now put it everywhere the placeholder was... */
+                     substitute_object_in_subtree (tem, placeholder);
 
-             return tem;
-           }
-         /* #n# returns a previously read object.  */
-         if (c == '#' && !NILP (Vread_circle))
-           {
-             tem = Fassq (make_number (n), read_objects);
-             if (CONSP (tem))
-               return XCDR (tem);
-             /* Fall through to error message.  */
-           }
-         else if (c == 'r' ||  c == 'R')
-           return read_integer (readcharfun, n);
+                     /* ...and #n# will use the real value from now on.  */
+                     Fsetcdr (cell, tem);
 
+                     return tem;
+                   }
+
+                 /* #n# returns a previously read object.  */
+                 if (c == '#')
+                   {
+                     tem = Fassq (make_number (n), read_objects);
+                     if (CONSP (tem))
+                       return XCDR (tem);
+                   }
+               }
+           }
          /* Fall through to error message.  */
        }
       else if (c == 'x' || c == 'X')
@@ -2716,7 +2737,7 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list)
        return read_integer (readcharfun, 2);
 
       UNREAD (c);
-      invalid_syntax ("#", 1);
+      invalid_syntax ("#");
 
     case ';':
       while ((c = READCHAR) >= 0 && c != '\n');
@@ -2828,12 +2849,12 @@ 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);
 
-       invalid_syntax ("?", 1);
+       invalid_syntax ("?");
       }
 
     case '"':
@@ -2848,14 +2869,16 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list)
           a single-byte character.  */
        int force_singlebyte = 0;
        int cancel = 0;
-       int nchars = 0;
+       ptrdiff_t nchars = 0;
 
        while ((ch = READCHAR) >= 0
               && ch != '\"')
          {
            if (end - p < MAX_MULTIBYTE_LENGTH)
              {
-               int offset = p - read_buffer;
+               ptrdiff_t offset = p - read_buffer;
+               if (min (PTRDIFF_MAX, SIZE_MAX) / 2 < read_buffer_size)
+                 memory_full (SIZE_MAX);
                read_buffer = (char *) xrealloc (read_buffer,
                                                 read_buffer_size *= 2);
                p = read_buffer + offset;
@@ -2951,11 +2974,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
@@ -2972,7 +2990,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;
@@ -2987,9 +3005,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;
+       int start_position = readchar_count - 1;
 
        {
          char *end = read_buffer + read_buffer_size;
@@ -2998,7 +3019,9 @@ read1 (register Lisp_Object readcharfun, int *pch, int first_in_list)
            {
              if (end - p < MAX_MULTIBYTE_LENGTH)
                {
-                 int offset = p - read_buffer;
+                 ptrdiff_t offset = p - read_buffer;
+                 if (min (PTRDIFF_MAX, SIZE_MAX) / 2 < read_buffer_size)
+                   memory_full (SIZE_MAX);
                  read_buffer = (char *) xrealloc (read_buffer,
                                                   read_buffer_size *= 2);
                  p = read_buffer + offset;
@@ -3018,22 +3041,24 @@ 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)
            {
-             int offset = p - read_buffer;
+             ptrdiff_t offset = p - read_buffer;
+             if (min (PTRDIFF_MAX, SIZE_MAX) / 2 < read_buffer_size)
+               memory_full (SIZE_MAX);
              read_buffer = (char *) xrealloc (read_buffer,
                                               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)
@@ -3061,12 +3086,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;
        }
@@ -3137,7 +3157,7 @@ substitute_object_recurse (Lisp_Object object, Lisp_Object placeholder, Lisp_Obj
     {
     case Lisp_Vectorlike:
       {
-       int i, length = 0;
+       ptrdiff_t i, length = 0;
        if (BOOL_VECTOR_P (subtree))
          return subtree;               /* No sub-objects anyway.  */
        else if (CHAR_TABLE_P (subtree) || SUB_CHAR_TABLE_P (subtree)
@@ -3335,7 +3355,7 @@ string_to_number (char const *string, int base, int ignore_trailing)
          /* Unfortunately there's no simple and accurate way to convert
             non-base-10 numbers that are out of C-language range.  */
          if (base != 10)
-           xsignal (Qoverflow_error, list1 (build_string (string)));
+           xsignal1 (Qoverflow_error, build_string (string));
        }
       else if (n <= (negative ? -MOST_NEGATIVE_FIXNUM : MOST_POSITIVE_FIXNUM))
        {
@@ -3360,8 +3380,7 @@ string_to_number (char const *string, int base, int ignore_trailing)
 static Lisp_Object
 read_vector (Lisp_Object readcharfun, int bytecodeflag)
 {
-  register int i;
-  register int size;
+  ptrdiff_t i, size;
   register Lisp_Object *ptr;
   register Lisp_Object tem, item, vector;
   register struct Lisp_Cons *otem;
@@ -3501,7 +3520,7 @@ read_list (int flag, register Lisp_Object readcharfun)
            {
              if (ch == ']')
                return val;
-             invalid_syntax (") or . in a vector", 18);
+             invalid_syntax (") or . in a vector");
            }
          if (ch == ')')
            return val;
@@ -3530,15 +3549,15 @@ read_list (int flag, register Lisp_Object readcharfun)
                         doc string, caller must make it
                         multibyte.  */
 
-                     int pos = XINT (XCDR (val));
+                     EMACS_INT pos = XINT (XCDR (val));
                      /* Position is negative for user variables.  */
                      if (pos < 0) pos = -pos;
                      if (pos >= saved_doc_string_position
                          && pos < (saved_doc_string_position
                                    + saved_doc_string_length))
                        {
-                         int start = pos - saved_doc_string_position;
-                         int from, to;
+                         ptrdiff_t start = pos - saved_doc_string_position;
+                         ptrdiff_t from, to;
 
                          /* Process quoting with ^A,
                             and find the end of the string,
@@ -3569,8 +3588,9 @@ read_list (int flag, register Lisp_Object readcharfun)
                               && pos < (prev_saved_doc_string_position
                                         + prev_saved_doc_string_length))
                        {
-                         int start = pos - prev_saved_doc_string_position;
-                         int from, to;
+                         ptrdiff_t start =
+                           pos - prev_saved_doc_string_position;
+                         ptrdiff_t from, to;
 
                          /* Process quoting with ^A,
                             and find the end of the string,
@@ -3603,9 +3623,9 @@ read_list (int flag, register Lisp_Object readcharfun)
 
                  return val;
                }
-             invalid_syntax (". in wrong context", 18);
+             invalid_syntax (". in wrong context");
            }
-         invalid_syntax ("] in a list", 11);
+         invalid_syntax ("] in a list");
        }
       tem = (read_pure && flag <= 0
             ? pure_cons (elt, Qnil)
@@ -3652,7 +3672,7 @@ Lisp_Object
 intern (const char *str)
 {
   Lisp_Object tem;
-  int len = strlen (str);
+  ptrdiff_t len = strlen (str);
   Lisp_Object obarray;
 
   obarray = Vobarray;
@@ -3668,7 +3688,7 @@ Lisp_Object
 intern_c_string (const char *str)
 {
   Lisp_Object tem;
-  int len = strlen (str);
+  ptrdiff_t len = strlen (str);
   Lisp_Object obarray;
 
   obarray = Vobarray;
@@ -3893,7 +3913,7 @@ hash_string (const char *ptr, size_t len)
 void
 map_obarray (Lisp_Object obarray, void (*fn) (Lisp_Object, Lisp_Object), Lisp_Object arg)
 {
-  register int i;
+  ptrdiff_t i;
   register Lisp_Object tail;
   CHECK_VECTOR (obarray);
   for (i = ASIZE (obarray) - 1; i >= 0; i--)
@@ -3964,8 +3984,7 @@ init_obarray (void)
   /* Qt is correct even if CANNOT_DUMP.  loadup.el will set to nil at end.  */
   Vpurify_flag = Qt;
 
-  Qvariable_documentation = intern_c_string ("variable-documentation");
-  staticpro (&Qvariable_documentation);
+  DEFSYM (Qvariable_documentation, "variable-documentation");
 
   read_buffer_size = 100 + MAX_MULTIBYTE_LENGTH;
   read_buffer = (char *) xmalloc (read_buffer_size);
@@ -3982,9 +4001,7 @@ defsubr (struct Lisp_Subr *sname)
 
 #ifdef NOTDEF /* use fset in subr.el now */
 void
-defalias (sname, string)
-     struct Lisp_Subr *sname;
-     char *string;
+defalias (struct Lisp_Subr *sname, char *string)
 {
   Lisp_Object sym;
   sym = intern (string);
@@ -3993,7 +4010,7 @@ defalias (sname, string)
 #endif /* NOTDEF */
 
 /* Define an "integer variable"; a symbol whose value is forwarded to a
-   C variable of type int.  Sample call (munged w "xx" to fool make-docfile):
+   C variable of type EMACS_INT.  Sample call (with "xx" to fool make-docfile):
    DEFxxVAR_INT ("emacs-priority", &emacs_priority, "Documentation");  */
 void
 defvar_int (struct Lisp_Intfwd *i_fwd,
@@ -4373,8 +4390,7 @@ customize `jka-compr-load-suffixes' rather than the present variable.  */);
 
   DEFVAR_BOOL ("load-in-progress", load_in_progress,
               doc: /* Non-nil if inside of `load'.  */);
-  Qload_in_progress = intern_c_string ("load-in-progress");
-  staticpro (&Qload_in_progress);
+  DEFSYM (Qload_in_progress, "load-in-progress");
 
   DEFVAR_LISP ("after-load-alist", Vafter_load_alist,
               doc: /* An alist of expressions to be evalled when particular files are loaded.
@@ -4403,9 +4419,11 @@ The remaining ENTRIES in the alist element describe the functions and
 variables defined in that file, the features provided, and the
 features required.  Each entry has the form `(provide . FEATURE)',
 `(require . FEATURE)', `(defun . FUNCTION)', `(autoload . SYMBOL)',
-`(defface . SYMBOL)', or `(t . SYMBOL)'.  In addition, an entry `(t
-. SYMBOL)' may precede an entry `(defun . FUNCTION)', and means that
-SYMBOL was an autoload before this file redefined it as a function.
+`(defface . SYMBOL)', or `(t . SYMBOL)'.  Entries like `(t . SYMBOL)'
+may precede a `(defun . FUNCTION)' entry, and means that SYMBOL was an
+autoload before this file redefined it as a function.  In addition,
+entries may also be single symbols, which means that SYMBOL was
+defined by `defvar' or `defconst'.
 
 During preloading, the file name recorded is relative to the main Lisp
 directory.  These file names are converted to absolute at startup.  */);
@@ -4493,9 +4511,11 @@ to load.  See also `load-dangerous-libraries'.  */);
   staticpro (&Qlexical_binding);
   DEFVAR_LISP ("lexical-binding", Vlexical_binding,
               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'.  */);
+This applies to code evaluated by `eval-buffer' and `eval-region' and
+other commands that call these functions, like `eval-defun' and
+the like.
+This variable is automatically set from the file variables of an
+interpreted Lisp file read using `load'.  */);
   Fmake_variable_buffer_local (Qlexical_binding);
 
   DEFVAR_LISP ("eval-buffer-list", Veval_buffer_list,
@@ -4505,67 +4525,34 @@ This variable is automatically set from the file variables of an interpreted
   DEFVAR_LISP ("old-style-backquotes", Vold_style_backquotes,
               doc: /* Set to non-nil when `read' encounters an old-style backquote.  */);
   Vold_style_backquotes = Qnil;
-  Qold_style_backquotes = intern_c_string ("old-style-backquotes");
-  staticpro (&Qold_style_backquotes);
+  DEFSYM (Qold_style_backquotes, "old-style-backquotes");
 
   /* Vsource_directory was initialized in init_lread.  */
 
   load_descriptor_list = Qnil;
   staticpro (&load_descriptor_list);
 
-  Qcurrent_load_list = intern_c_string ("current-load-list");
-  staticpro (&Qcurrent_load_list);
-
-  Qstandard_input = intern_c_string ("standard-input");
-  staticpro (&Qstandard_input);
-
-  Qread_char = intern_c_string ("read-char");
-  staticpro (&Qread_char);
-
-  Qget_file_char = intern_c_string ("get-file-char");
-  staticpro (&Qget_file_char);
-
-  Qget_emacs_mule_file_char = intern_c_string ("get-emacs-mule-file-char");
-  staticpro (&Qget_emacs_mule_file_char);
-
-  Qload_force_doc_strings = intern_c_string ("load-force-doc-strings");
-  staticpro (&Qload_force_doc_strings);
-
-  Qbackquote = intern_c_string ("`");
-  staticpro (&Qbackquote);
-  Qcomma = intern_c_string (",");
-  staticpro (&Qcomma);
-  Qcomma_at = intern_c_string (",@");
-  staticpro (&Qcomma_at);
-  Qcomma_dot = intern_c_string (",.");
-  staticpro (&Qcomma_dot);
-
-  Qinhibit_file_name_operation = intern_c_string ("inhibit-file-name-operation");
-  staticpro (&Qinhibit_file_name_operation);
-
-  Qascii_character = intern_c_string ("ascii-character");
-  staticpro (&Qascii_character);
-
-  Qfunction = intern_c_string ("function");
-  staticpro (&Qfunction);
-
-  Qload = intern_c_string ("load");
-  staticpro (&Qload);
-
-  Qload_file_name = intern_c_string ("load-file-name");
-  staticpro (&Qload_file_name);
-
-  Qeval_buffer_list = intern_c_string ("eval-buffer-list");
-  staticpro (&Qeval_buffer_list);
-
-  Qfile_truename = intern_c_string ("file-truename");
-  staticpro (&Qfile_truename) ;
-
-  Qdir_ok = intern_c_string ("dir-ok");
-  staticpro (&Qdir_ok);
-
-  Qdo_after_load_evaluation = intern_c_string ("do-after-load-evaluation");
-  staticpro (&Qdo_after_load_evaluation) ;
+  DEFSYM (Qcurrent_load_list, "current-load-list");
+  DEFSYM (Qstandard_input, "standard-input");
+  DEFSYM (Qread_char, "read-char");
+  DEFSYM (Qget_file_char, "get-file-char");
+  DEFSYM (Qget_emacs_mule_file_char, "get-emacs-mule-file-char");
+  DEFSYM (Qload_force_doc_strings, "load-force-doc-strings");
+
+  DEFSYM (Qbackquote, "`");
+  DEFSYM (Qcomma, ",");
+  DEFSYM (Qcomma_at, ",@");
+  DEFSYM (Qcomma_dot, ",.");
+
+  DEFSYM (Qinhibit_file_name_operation, "inhibit-file-name-operation");
+  DEFSYM (Qascii_character, "ascii-character");
+  DEFSYM (Qfunction, "function");
+  DEFSYM (Qload, "load");
+  DEFSYM (Qload_file_name, "load-file-name");
+  DEFSYM (Qeval_buffer_list, "eval-buffer-list");
+  DEFSYM (Qfile_truename, "file-truename");
+  DEFSYM (Qdir_ok, "dir-ok");
+  DEFSYM (Qdo_after_load_evaluation, "do-after-load-evaluation");
 
   staticpro (&dump_path);
 
@@ -4577,18 +4564,11 @@ This variable is automatically set from the file variables of an interpreted
   Vloads_in_progress = Qnil;
   staticpro (&Vloads_in_progress);
 
-  Qhash_table = intern_c_string ("hash-table");
-  staticpro (&Qhash_table);
-  Qdata = intern_c_string ("data");
-  staticpro (&Qdata);
-  Qtest = intern_c_string ("test");
-  staticpro (&Qtest);
-  Qsize = intern_c_string ("size");
-  staticpro (&Qsize);
-  Qweakness = intern_c_string ("weakness");
-  staticpro (&Qweakness);
-  Qrehash_size = intern_c_string ("rehash-size");
-  staticpro (&Qrehash_size);
-  Qrehash_threshold = intern_c_string ("rehash-threshold");
-  staticpro (&Qrehash_threshold);
+  DEFSYM (Qhash_table, "hash-table");
+  DEFSYM (Qdata, "data");
+  DEFSYM (Qtest, "test");
+  DEFSYM (Qsize, "size");
+  DEFSYM (Qweakness, "weakness");
+  DEFSYM (Qrehash_size, "rehash-size");
+  DEFSYM (Qrehash_threshold, "rehash-threshold");
 }