* buffer.h (FETCH_MULTIBYTE_CHAR): Define as inline.
[bpt/emacs.git] / src / doc.c
index 2db1ec3..223741c 100644 (file)
--- a/src/doc.c
+++ b/src/doc.c
@@ -1,7 +1,6 @@
 /* Record indices of function doc strings stored in a file.
-   Copyright (C) 1985, 1986, 1993, 1994, 1995, 1997, 1998, 1999, 2000, 2001,
-                 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
-                 Free Software Foundation, Inc.
+
+Copyright (C) 1985-1986, 1993-1995, 1997-2012 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -25,54 +24,33 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #include <sys/file.h>  /* Must be after sys/types.h for USG*/
 #include <ctype.h>
 #include <setjmp.h>
-
-#ifdef HAVE_FCNTL_H
 #include <fcntl.h>
-#endif
-
-#ifdef HAVE_UNISTD_H
 #include <unistd.h>
-#endif
-
-#ifndef O_RDONLY
-#define O_RDONLY 0
-#endif
 
 #include "lisp.h"
+#include "character.h"
 #include "buffer.h"
 #include "keyboard.h"
-#include "character.h"
 #include "keymap.h"
 #include "buildobj.h"
 
-#ifdef HAVE_INDEX
-extern char *index P_ ((const char *, int));
-#endif
-
-Lisp_Object Vdoc_file_name;
-
 Lisp_Object Qfunction_documentation;
 
-/* A list of files used to build this Emacs binary.  */
-static Lisp_Object Vbuild_files;
-
-extern Lisp_Object Voverriding_local_map;
-
-extern Lisp_Object Qremap;
-
+extern Lisp_Object Qclosure;
 /* Buffer used for reading from documentation file.  */
 static char *get_doc_string_buffer;
-static int get_doc_string_buffer_size;
+static ptrdiff_t get_doc_string_buffer_size;
 
 static unsigned char *read_bytecode_pointer;
-Lisp_Object Fsnarf_documentation P_ ((Lisp_Object));
+static Lisp_Object Fdocumentation_property (Lisp_Object, Lisp_Object,
+                                           Lisp_Object);
+static Lisp_Object Fsnarf_documentation (Lisp_Object);
 
 /* readchar in lread.c calls back here to fetch the next byte.
    If UNREADFLAG is 1, we unread a byte.  */
 
 int
-read_bytecode_char (unreadflag)
-     int unreadflag;
+read_bytecode_char (int unreadflag)
 {
   if (unreadflag)
     {
@@ -102,17 +80,17 @@ read_bytecode_char (unreadflag)
    and return a cons cell.  */
 
 Lisp_Object
-get_doc_string (filepos, unibyte, definition)
-     Lisp_Object filepos;
-     int unibyte, definition;
+get_doc_string (Lisp_Object filepos, int unibyte, int definition)
 {
   char *from, *to;
   register int fd;
   register char *name;
   register char *p, *p1;
-  int minsize;
-  int offset, position;
+  ptrdiff_t minsize;
+  int offset;
+  EMACS_INT position;
   Lisp_Object file, tem;
+  USE_SAFE_ALLOCA;
 
   if (INTEGERP (filepos))
     {
@@ -140,19 +118,21 @@ get_doc_string (filepos, unibyte, definition)
      If it is relative, combine it with Vdoc_directory.  */
 
   tem = Ffile_name_absolute_p (file);
+  file = ENCODE_FILE (file);
   if (NILP (tem))
     {
-      minsize = SCHARS (Vdoc_directory);
+      Lisp_Object docdir = ENCODE_FILE (Vdoc_directory);
+      minsize = SCHARS (docdir);
       /* sizeof ("../etc/") == 8 */
       if (minsize < 8)
        minsize = 8;
-      name = (char *) alloca (minsize + SCHARS (file) + 8);
-      strcpy (name, SDATA (Vdoc_directory));
-      strcat (name, SDATA (file));
+      SAFE_ALLOCA (name, char *, minsize + SCHARS (file) + 8);
+      strcpy (name, SSDATA (docdir));
+      strcat (name, SSDATA (file));
     }
   else
     {
-      name = (char *) SDATA (file);
+      name = SSDATA (file);
     }
 
   fd = emacs_open (name, O_RDONLY, 0);
@@ -162,9 +142,9 @@ get_doc_string (filepos, unibyte, definition)
       if (!NILP (Vpurify_flag))
        {
          /* Preparing to dump; DOC file is probably not installed.
-            So check in ../etc. */
+            So check in ../etc.  */
          strcpy (name, "../etc/");
-         strcat (name, SDATA (file));
+         strcat (name, SSDATA (file));
 
          fd = emacs_open (name, O_RDONLY, 0);
        }
@@ -177,33 +157,35 @@ get_doc_string (filepos, unibyte, definition)
   /* Make sure we read at least 1024 bytes before `position'
      so we can check the leading text for consistency.  */
   offset = min (position, max (1024, position % (8 * 1024)));
-  if (0 > lseek (fd, position - offset, 0))
+  if (TYPE_MAXIMUM (off_t) < position
+      || lseek (fd, position - offset, 0) < 0)
     {
       emacs_close (fd);
-      error ("Position %ld out of range in doc string file \"%s\"",
+      error ("Position %"pI"d out of range in doc string file \"%s\"",
             position, name);
     }
 
+  SAFE_FREE ();
+
   /* Read the doc string into get_doc_string_buffer.
      P points beyond the data just read.  */
 
   p = get_doc_string_buffer;
   while (1)
     {
-      int space_left = (get_doc_string_buffer_size
-                       - (p - get_doc_string_buffer));
+      ptrdiff_t space_left = (get_doc_string_buffer_size - 1
+                             - (p - get_doc_string_buffer));
       int nread;
 
       /* Allocate or grow the buffer if we need to.  */
-      if (space_left == 0)
+      if (space_left <= 0)
        {
-         int in_buffer = p - get_doc_string_buffer;
-         get_doc_string_buffer_size += 16 * 1024;
-         get_doc_string_buffer
-           = (char *) xrealloc (get_doc_string_buffer,
-                                get_doc_string_buffer_size + 1);
+         ptrdiff_t in_buffer = p - get_doc_string_buffer;
+         get_doc_string_buffer =
+           xpalloc (get_doc_string_buffer, &get_doc_string_buffer_size,
+                    16 * 1024, -1, 1);
          p = get_doc_string_buffer + in_buffer;
-         space_left = (get_doc_string_buffer_size
+         space_left = (get_doc_string_buffer_size - 1
                        - (p - get_doc_string_buffer));
        }
 
@@ -221,9 +203,9 @@ get_doc_string (filepos, unibyte, definition)
       if (!nread)
        break;
       if (p == get_doc_string_buffer)
-       p1 = (char *) index (p + offset, '\037');
+       p1 = strchr (p + offset, '\037');
       else
-       p1 = (char *) index (p, '\037');
+       p1 = strchr (p, '\037');
       if (p1)
        {
          *p1 = 0;
@@ -277,7 +259,12 @@ get_doc_string (filepos, unibyte, definition)
          else if (c == '_')
            *to++ = 037;
          else
-           error ("Invalid data in documentation file -- ^A followed by code 0%o", c);
+           {
+             unsigned char uc = c;
+             error ("\
+Invalid data in documentation file -- %c followed by code %03o",
+                    1, uc);
+           }
        }
       else
        *to++ = *from++;
@@ -287,7 +274,7 @@ get_doc_string (filepos, unibyte, definition)
      the same way we would read bytes from a file.  */
   if (definition)
     {
-      read_bytecode_pointer = get_doc_string_buffer + offset;
+      read_bytecode_pointer = (unsigned char *) get_doc_string_buffer + offset;
       return Fread (Qlambda);
     }
 
@@ -296,10 +283,11 @@ get_doc_string (filepos, unibyte, definition)
                                to - (get_doc_string_buffer + offset));
   else
     {
-      /* Let the data determine whether the string is multibyte,
-        even if Emacs is running in --unibyte mode.  */
-      int nchars = multibyte_chars_in_text (get_doc_string_buffer + offset,
-                                           to - (get_doc_string_buffer + offset));
+      /* The data determines whether the string is multibyte.  */
+      ptrdiff_t nchars =
+       multibyte_chars_in_text (((unsigned char *) get_doc_string_buffer
+                                 + offset),
+                                to - (get_doc_string_buffer + offset));
       return make_string_from_bytes (get_doc_string_buffer + offset,
                                     nchars,
                                     to - (get_doc_string_buffer + offset));
@@ -311,15 +299,13 @@ get_doc_string (filepos, unibyte, definition)
    of a compiled function from the .elc file.  */
 
 Lisp_Object
-read_doc_string (filepos)
-     Lisp_Object filepos;
+read_doc_string (Lisp_Object filepos)
 {
   return get_doc_string (filepos, 0, 1);
 }
 
 static int
-reread_doc_file (file)
-     Lisp_Object file;
+reread_doc_file (Lisp_Object file)
 {
 #if 0
   Lisp_Object reply, prompt[3];
@@ -346,44 +332,51 @@ DEFUN ("documentation", Fdocumentation, Sdocumentation, 1, 2, 0,
        doc: /* Return the documentation string of FUNCTION.
 Unless a non-nil second argument RAW is given, the
 string is passed through `substitute-command-keys'.  */)
-     (function, raw)
-     Lisp_Object function, raw;
+  (Lisp_Object function, Lisp_Object raw)
 {
   Lisp_Object fun;
   Lisp_Object funcar;
-  Lisp_Object tem, doc;
+  Lisp_Object doc;
   int try_reload = 1;
 
  documentation:
 
   doc = Qnil;
 
-  if (SYMBOLP (function)
-      && (tem = Fget (function, Qfunction_documentation),
-         !NILP (tem)))
-    return Fdocumentation_property (function, Qfunction_documentation, raw);
+  if (SYMBOLP (function))
+    {
+      Lisp_Object tem = Fget (function, Qfunction_documentation);
+      if (!NILP (tem))
+       return Fdocumentation_property (function, Qfunction_documentation,
+                                       raw);
+    }
 
   fun = Findirect_function (function, Qnil);
   if (SUBRP (fun))
     {
       if (XSUBR (fun)->doc == 0)
        return Qnil;
-      else if ((EMACS_INT) XSUBR (fun)->doc >= 0)
+      /* FIXME: This is not portable, as it assumes that string
+        pointers have the top bit clear.  */
+      else if ((intptr_t) XSUBR (fun)->doc >= 0)
        doc = build_string (XSUBR (fun)->doc);
       else
-       doc = make_number ((EMACS_INT) XSUBR (fun)->doc);
+       doc = make_number ((intptr_t) XSUBR (fun)->doc);
     }
   else if (COMPILEDP (fun))
     {
       if ((ASIZE (fun) & PSEUDOVECTOR_SIZE_MASK) <= COMPILED_DOC_STRING)
        return Qnil;
-      tem = AREF (fun, COMPILED_DOC_STRING);
-      if (STRINGP (tem))
-       doc = tem;
-      else if (NATNUMP (tem) || CONSP (tem))
-       doc = tem;
       else
-       return Qnil;
+       {
+         Lisp_Object tem = AREF (fun, COMPILED_DOC_STRING);
+         if (STRINGP (tem))
+           doc = tem;
+         else if (NATNUMP (tem) || CONSP (tem))
+           doc = tem;
+         else
+           return Qnil;
+       }
     }
   else if (STRINGP (fun) || VECTORP (fun))
     {
@@ -397,11 +390,11 @@ string is passed through `substitute-command-keys'.  */)
       else if (EQ (funcar, Qkeymap))
        return build_string ("Prefix command (definition is a keymap associating keystrokes with commands).");
       else if (EQ (funcar, Qlambda)
+              || (EQ (funcar, Qclosure) && (fun = XCDR (fun), 1))
               || EQ (funcar, Qautoload))
        {
-         Lisp_Object tem1;
-         tem1 = Fcdr (Fcdr (fun));
-         tem = Fcar (tem1);
+         Lisp_Object tem1 = Fcdr (Fcdr (fun));
+         Lisp_Object tem = Fcar (tem1);
          if (STRINGP (tem))
            doc = tem;
          /* Handle a doc reference--but these never come last
@@ -474,8 +467,7 @@ Third argument RAW omitted or nil means pass the result through
 This differs from `get' in that it can refer to strings stored in the
 `etc/DOC' file; and that it evaluates documentation properties that
 aren't strings.  */)
-  (symbol, prop, raw)
-     Lisp_Object symbol, prop, raw;
+  (Lisp_Object symbol, Lisp_Object prop, Lisp_Object raw)
 {
   int try_reload = 1;
   Lisp_Object tem;
@@ -505,7 +497,7 @@ aren't strings.  */)
     }
   else if (!STRINGP (tem))
     /* Feval protects its argument.  */
-    tem = Feval (tem);
+    tem = Feval (tem, Qnil);
 
   if (NILP (raw) && STRINGP (tem))
     tem = Fsubstitute_command_keys (tem);
@@ -515,18 +507,20 @@ aren't strings.  */)
 /* Scanning the DOC files and placing docstring offsets into functions.  */
 
 static void
-store_function_docstring (fun, offset)
-     Lisp_Object fun;
-     /* Use EMACS_INT because we get this from pointer subtraction.  */
-     EMACS_INT offset;
+store_function_docstring (Lisp_Object obj, ptrdiff_t offset)
 {
-  fun = indirect_function (fun);
+  /* Don't use indirect_function here, or defaliases will apply their
+     docstrings to the base functions (Bug#2603).  */
+  Lisp_Object fun = SYMBOLP (obj) ? XSYMBOL (obj)->function : obj;
 
   /* The type determines where the docstring is stored.  */
 
   /* Lisp_Subrs have a slot for it.  */
   if (SUBRP (fun))
-    XSUBR (fun)->doc = (char *) - offset;
+    {
+      intptr_t negative_offset = - offset;
+      XSUBR (fun)->doc = (char *) negative_offset;
+    }
 
   /* If it's a lisp form, stick it in the form.  */
   else if (CONSP (fun))
@@ -534,11 +528,12 @@ store_function_docstring (fun, offset)
       Lisp_Object tem;
 
       tem = XCAR (fun);
-      if (EQ (tem, Qlambda) || EQ (tem, Qautoload))
+      if (EQ (tem, Qlambda) || EQ (tem, Qautoload)
+         || (EQ (tem, Qclosure) && (fun = XCDR (fun), 1)))
        {
          tem = Fcdr (Fcdr (fun));
          if (CONSP (tem) && INTEGERP (XCAR (tem)))
-           XSETCARFASTINT (tem, offset);
+           XSETCAR (tem, make_number (offset));
        }
       else if (EQ (tem, Qmacro))
        store_function_docstring (XCDR (fun), offset);
@@ -565,14 +560,13 @@ The function takes one argument, FILENAME, a string;
 it specifies the file name (without a directory) of the DOC file.
 That file is found in `../etc' now; later, when the dumped Emacs is run,
 the same file name is found in the `doc-directory'.  */)
-     (filename)
-     Lisp_Object filename;
+  (Lisp_Object filename)
 {
   int fd;
   char buf[1024 + 1];
   register int filled;
-  register int pos;
-  register char *p, *end;
+  register EMACS_INT pos;
+  register char *p;
   Lisp_Object sym;
   char *name;
   int skip_file = 0;
@@ -594,9 +588,9 @@ the same file name is found in the `doc-directory'.  */)
       CHECK_STRING (Vdoc_directory);
       name = (char *) alloca (SCHARS (filename)
                          + SCHARS (Vdoc_directory) + 1);
-      strcpy (name, SDATA (Vdoc_directory));
+      strcpy (name, SSDATA (Vdoc_directory));
     }
-  strcat (name, SDATA (filename));     /*** Add this line ***/
+  strcat (name, SSDATA (filename));    /*** Add this line ***/
 
   /* Vbuild_files is nil when temacs is run, and non-nil after that.  */
   if (NILP (Vbuild_files))
@@ -605,7 +599,7 @@ the same file name is found in the `doc-directory'.  */)
 
     for (beg = buildobj; *beg; beg = end)
       {
-        int len;
+        ptrdiff_t len;
 
         while (*beg && isspace (*beg)) ++beg;
 
@@ -631,6 +625,7 @@ the same file name is found in the `doc-directory'.  */)
   pos = 0;
   while (1)
     {
+      register char *end;
       if (filled < 512)
        filled += emacs_read (fd, &buf[filled], sizeof buf - 1 - filled);
       if (!filled)
@@ -643,7 +638,7 @@ the same file name is found in the `doc-directory'.  */)
       /* p points to ^_Ffunctionname\n or ^_Vvarname\n or ^_Sfilename\n.  */
       if (p != end)
        {
-         end = (char *) index (p, '\n');
+         end = strchr (p, '\n');
 
           /* See if this is a file name, and if it is a file in build-files.  */
           if (p[1] == 'S')
@@ -652,7 +647,7 @@ the same file name is found in the `doc-directory'.  */)
               if (end - p > 4 && end[-2] == '.'
                   && (end[-1] == 'o' || end[-1] == 'c'))
                 {
-                  int len = end - p - 2;
+                  ptrdiff_t len = end - p - 2;
                   char *fromfile = alloca (len + 1);
                   strncpy (fromfile, &p[2], len);
                   fromfile[len] = 0;
@@ -665,7 +660,8 @@ the same file name is found in the `doc-directory'.  */)
             }
 
          sym = oblookup (Vobarray, p + 2,
-                         multibyte_chars_in_text (p + 2, end - p - 2),
+                         multibyte_chars_in_text ((unsigned char *) p + 2,
+                                                  end - p - 2),
                          end - p - 2);
          /* Check skip_file so that when a function is defined several
             times in different files (typically, once in xterm, once in
@@ -679,25 +675,28 @@ the same file name is found in the `doc-directory'.  */)
                  /* Install file-position as variable-documentation property
                     and make it negative for a user-variable
                     (doc starts with a `*').  */
-                 Fput (sym, Qvariable_documentation,
-                       make_number ((pos + end + 1 - buf)
-                                    * (end[1] == '*' ? -1 : 1)));
+                  if (!NILP (Fboundp (sym)))
+                    Fput (sym, Qvariable_documentation,
+                          make_number ((pos + end + 1 - buf)
+                                       * (end[1] == '*' ? -1 : 1)));
                }
 
              /* Attach a docstring to a function?  */
              else if (p[1] == 'F')
-               store_function_docstring (sym, pos + end + 1 - buf);
-
+                {
+                  if (!NILP (Ffboundp (sym)))
+                    store_function_docstring (sym, pos + end + 1 - buf);
+                }
              else if (p[1] == 'S')
                ; /* Just a source file name boundary marker.  Ignore it.  */
 
              else
-               error ("DOC file invalid at position %d", pos);
+               error ("DOC file invalid at position %"pI"d", pos);
            }
        }
       pos += end - buf;
       filled -= end - buf;
-      bcopy (end, buf, filled);
+      memmove (buf, end, filled);
     }
   emacs_close (fd);
   return Qnil;
@@ -706,35 +705,39 @@ the same file name is found in the `doc-directory'.  */)
 DEFUN ("substitute-command-keys", Fsubstitute_command_keys,
        Ssubstitute_command_keys, 1, 1, 0,
        doc: /* Substitute key descriptions for command names in STRING.
-Substrings of the form \\=\\[COMMAND] replaced by either: a keystroke
-sequence that will invoke COMMAND, or "M-x COMMAND" if COMMAND is not
-on any keys.
-Substrings of the form \\=\\{MAPVAR} are replaced by summaries
-\(made by `describe-bindings') of the value of MAPVAR, taken as a keymap.
-Substrings of the form \\=\\<MAPVAR> specify to use the value of MAPVAR
+Each substring of the form \\=\\[COMMAND] is replaced by either a
+keystroke sequence that invokes COMMAND, or "M-x COMMAND" if COMMAND
+is not on any keys.
+
+Each substring of the form \\=\\{MAPVAR} is replaced by a summary of
+the value of MAPVAR as a keymap.  This summary is similar to the one
+produced by `describe-bindings'.  The summary ends in two newlines
+\(used by the helper function `help-make-xrefs' to find the end of the
+summary).
+
+Each substring of the form \\=\\<MAPVAR> specifies the use of MAPVAR
 as the keymap for future \\=\\[COMMAND] substrings.
 \\=\\= quotes the following character and is discarded;
 thus, \\=\\=\\=\\= puts \\=\\= into the output, and \\=\\=\\=\\[ puts \\=\\[ into the output.
 
-Returns original STRING if no substitutions were made.  Otherwise,
-a new string, without any text properties, is returned.  */)
-     (string)
-     Lisp_Object string;
+Return the original STRING if no substitutions are made.
+Otherwise, return a new string, without any text properties.  */)
+  (Lisp_Object string)
 {
-  unsigned char *buf;
+  char *buf;
   int changed = 0;
   register unsigned char *strp;
-  register unsigned char *bufp;
-  int idx;
-  int bsize;
+  register char *bufp;
+  ptrdiff_t idx;
+  ptrdiff_t bsize;
   Lisp_Object tem;
   Lisp_Object keymap;
   unsigned char *start;
-  int length, length_byte;
+  ptrdiff_t length, length_byte;
   Lisp_Object name;
   struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
   int multibyte;
-  int nchars;
+  ptrdiff_t nchars;
 
   if (NILP (string))
     return Qnil;
@@ -752,12 +755,12 @@ a new string, without any text properties, is returned.  */)
      or a specified local map (which means search just that and the
      global map).  If non-nil, it might come from Voverriding_local_map,
      or from a \\<mapname> construct in STRING itself..  */
-  keymap = current_kboard->Voverriding_terminal_local_map;
+  keymap = KVAR (current_kboard, Voverriding_terminal_local_map);
   if (NILP (keymap))
     keymap = Voverriding_local_map;
 
   bsize = SBYTES (string);
-  bufp = buf = (unsigned char *) xmalloc (bsize);
+  bufp = buf = (char *) xmalloc (bsize);
 
   strp = SDATA (string);
   while (strp < SDATA (string) + SBYTES (string))
@@ -776,7 +779,7 @@ a new string, without any text properties, is returned.  */)
              if (len == 1)
                *bufp = *strp;
              else
-               bcopy (strp, bufp, len);
+               memcpy (bufp, strp, len);
              strp += len;
              bufp += len;
              nchars++;
@@ -786,7 +789,7 @@ a new string, without any text properties, is returned.  */)
        }
       else if (strp[0] == '\\' && strp[1] == '[')
        {
-         int start_idx;
+         ptrdiff_t start_idx;
          int follow_remap = 1;
 
          changed = 1;
@@ -804,12 +807,12 @@ a new string, without any text properties, is returned.  */)
 
          /* Save STRP in IDX.  */
          idx = strp - SDATA (string);
-         name = Fintern (make_string (start, length_byte), Qnil);
+         name = Fintern (make_string ((char *) start, length_byte), Qnil);
 
        do_remap:
          tem = Fwhere_is_internal (name, keymap, Qt, Qnil, Qnil);
 
-         if (VECTORP (tem) && XVECTOR_SIZE (tem) > 1
+         if (VECTORP (tem) && ASIZE (tem) > 1
              && EQ (AREF (tem, 0), Qremap) && SYMBOLP (AREF (tem, 1))
              && follow_remap)
            {
@@ -825,10 +828,12 @@ a new string, without any text properties, is returned.  */)
 
          if (NILP (tem))       /* but not on any keys */
            {
-             int offset = bufp - buf;
-             buf = (unsigned char *) xrealloc (buf, bsize += 4);
+             ptrdiff_t offset = bufp - buf;
+             if (STRING_BYTES_BOUND - 4 < bsize)
+               string_overflow ();
+             buf = (char *) xrealloc (buf, bsize += 4);
              bufp = buf + offset;
-             bcopy ("M-x ", bufp, 4);
+             memcpy (bufp, "M-x ", 4);
              bufp += 4;
              nchars += 4;
              if (multibyte)
@@ -848,7 +853,7 @@ a new string, without any text properties, is returned.  */)
       else if (strp[0] == '\\' && (strp[1] == '{' || strp[1] == '<'))
        {
          struct buffer *oldbuf;
-         int start_idx;
+         ptrdiff_t start_idx;
          /* This is for computing the SHADOWS arg for describe_map_tree.  */
          Lisp_Object active_maps = Fcurrent_active_maps (Qnil, Qnil);
          Lisp_Object earlier_maps;
@@ -871,7 +876,7 @@ a new string, without any text properties, is returned.  */)
          /* Get the value of the keymap in TEM, or nil if undefined.
             Do this while still in the user's current buffer
             in case it is a local variable.  */
-         name = Fintern (make_string (start, length_byte), Qnil);
+         name = Fintern (make_string ((char *) start, length_byte), Qnil);
          tem = Fboundp (name);
          if (! NILP (tem))
            {
@@ -919,14 +924,16 @@ a new string, without any text properties, is returned.  */)
          length_byte = SBYTES (tem);
        subst:
          {
-           int offset = bufp - buf;
-           buf = (unsigned char *) xrealloc (buf, bsize += length_byte);
+           ptrdiff_t offset = bufp - buf;
+           if (STRING_BYTES_BOUND - length_byte < bsize)
+             string_overflow ();
+           buf = (char *) xrealloc (buf, bsize += length_byte);
            bufp = buf + offset;
-           bcopy (start, bufp, length_byte);
+           memcpy (bufp, start, length_byte);
            bufp += length_byte;
            nchars += length;
            /* Check STRING again in case gc relocated it.  */
-           strp = (unsigned char *) SDATA (string) + idx;
+           strp = SDATA (string) + idx;
          }
        }
       else if (! multibyte)            /* just copy other chars */
@@ -939,7 +946,7 @@ a new string, without any text properties, is returned.  */)
          if (len == 1)
            *bufp = *strp;
          else
-           bcopy (strp, bufp, len);
+           memcpy (bufp, strp, len);
          strp += len;
          bufp += len;
          nchars++;
@@ -955,16 +962,15 @@ a new string, without any text properties, is returned.  */)
 }
 \f
 void
-syms_of_doc ()
+syms_of_doc (void)
 {
-  Qfunction_documentation = intern_c_string ("function-documentation");
-  staticpro (&Qfunction_documentation);
+  DEFSYM (Qfunction_documentation, "function-documentation");
 
-  DEFVAR_LISP ("internal-doc-file-name", &Vdoc_file_name,
+  DEFVAR_LISP ("internal-doc-file-name", Vdoc_file_name,
               doc: /* Name of file containing documentation strings of built-in symbols.  */);
   Vdoc_file_name = Qnil;
 
-  DEFVAR_LISP ("build-files", &Vbuild_files,
+  DEFVAR_LISP ("build-files", Vbuild_files,
                doc: /* A list of files used to build this Emacs binary.  */);
   Vbuild_files = Qnil;
 
@@ -973,6 +979,3 @@ syms_of_doc ()
   defsubr (&Ssnarf_documentation);
   defsubr (&Ssubstitute_command_keys);
 }
-
-/* arch-tag: 56281d4d-6949-43e2-be2e-f6517de744ba
-   (do not change this comment) */