aboutsummaryrefslogtreecommitdiffstats
path: root/src/doc.c
diff options
context:
space:
mode:
authorStefan Monnier2012-03-25 16:37:21 -0400
committerStefan Monnier2012-03-25 16:37:21 -0400
commit699c782b7668c44d0fa4446331b0590a6d5dac82 (patch)
tree5dcce364741d0761920a3d274b0fc8aba4103d45 /src/doc.c
parent98fb480ee31bf74cf554044f60f21df16566dd7f (diff)
parente99a9b8bdccadded1f6fae88ee7a2a93dfd4eacf (diff)
downloademacs-pending.tar.gz
emacs-pending.zip
Merge from trunkpending
Diffstat (limited to 'src/doc.c')
-rw-r--r--src/doc.c53
1 files changed, 30 insertions, 23 deletions
diff --git a/src/doc.c b/src/doc.c
index 69646f5af51..02db4dde072 100644
--- a/src/doc.c
+++ b/src/doc.c
@@ -1,5 +1,5 @@
1/* Record indices of function doc strings stored in a file. 1/* Record indices of function doc strings stored in a file.
2 Copyright (C) 1985-1986, 1993-1995, 1997-2011 2 Copyright (C) 1985-1986, 1993-1995, 1997-2012
3 Free Software Foundation, Inc. 3 Free Software Foundation, Inc.
4 4
5This file is part of GNU Emacs. 5This file is part of GNU Emacs.
@@ -39,7 +39,7 @@ Lisp_Object Qfunction_documentation;
39extern Lisp_Object Qclosure; 39extern Lisp_Object Qclosure;
40/* Buffer used for reading from documentation file. */ 40/* Buffer used for reading from documentation file. */
41static char *get_doc_string_buffer; 41static char *get_doc_string_buffer;
42static int get_doc_string_buffer_size; 42static ptrdiff_t get_doc_string_buffer_size;
43 43
44static unsigned char *read_bytecode_pointer; 44static unsigned char *read_bytecode_pointer;
45static Lisp_Object Fdocumentation_property (Lisp_Object, Lisp_Object, 45static Lisp_Object Fdocumentation_property (Lisp_Object, Lisp_Object,
@@ -116,14 +116,16 @@ get_doc_string (Lisp_Object filepos, int unibyte, int definition)
116 If it is relative, combine it with Vdoc_directory. */ 116 If it is relative, combine it with Vdoc_directory. */
117 117
118 tem = Ffile_name_absolute_p (file); 118 tem = Ffile_name_absolute_p (file);
119 file = ENCODE_FILE (file);
119 if (NILP (tem)) 120 if (NILP (tem))
120 { 121 {
121 minsize = SCHARS (Vdoc_directory); 122 Lisp_Object docdir = ENCODE_FILE (Vdoc_directory);
123 minsize = SCHARS (docdir);
122 /* sizeof ("../etc/") == 8 */ 124 /* sizeof ("../etc/") == 8 */
123 if (minsize < 8) 125 if (minsize < 8)
124 minsize = 8; 126 minsize = 8;
125 name = (char *) alloca (minsize + SCHARS (file) + 8); 127 name = (char *) alloca (minsize + SCHARS (file) + 8);
126 strcpy (name, SSDATA (Vdoc_directory)); 128 strcpy (name, SSDATA (docdir));
127 strcat (name, SSDATA (file)); 129 strcat (name, SSDATA (file));
128 } 130 }
129 else 131 else
@@ -138,7 +140,7 @@ get_doc_string (Lisp_Object filepos, int unibyte, int definition)
138 if (!NILP (Vpurify_flag)) 140 if (!NILP (Vpurify_flag))
139 { 141 {
140 /* Preparing to dump; DOC file is probably not installed. 142 /* Preparing to dump; DOC file is probably not installed.
141 So check in ../etc. */ 143 So check in ../etc. */
142 strcpy (name, "../etc/"); 144 strcpy (name, "../etc/");
143 strcat (name, SSDATA (file)); 145 strcat (name, SSDATA (file));
144 146
@@ -166,20 +168,19 @@ get_doc_string (Lisp_Object filepos, int unibyte, int definition)
166 p = get_doc_string_buffer; 168 p = get_doc_string_buffer;
167 while (1) 169 while (1)
168 { 170 {
169 EMACS_INT space_left = (get_doc_string_buffer_size 171 ptrdiff_t space_left = (get_doc_string_buffer_size - 1
170 - (p - get_doc_string_buffer)); 172 - (p - get_doc_string_buffer));
171 int nread; 173 int nread;
172 174
173 /* Allocate or grow the buffer if we need to. */ 175 /* Allocate or grow the buffer if we need to. */
174 if (space_left == 0) 176 if (space_left <= 0)
175 { 177 {
176 EMACS_INT in_buffer = p - get_doc_string_buffer; 178 ptrdiff_t in_buffer = p - get_doc_string_buffer;
177 get_doc_string_buffer_size += 16 * 1024; 179 get_doc_string_buffer =
178 get_doc_string_buffer 180 xpalloc (get_doc_string_buffer, &get_doc_string_buffer_size,
179 = (char *) xrealloc (get_doc_string_buffer, 181 16 * 1024, -1, 1);
180 get_doc_string_buffer_size + 1);
181 p = get_doc_string_buffer + in_buffer; 182 p = get_doc_string_buffer + in_buffer;
182 space_left = (get_doc_string_buffer_size 183 space_left = (get_doc_string_buffer_size - 1
183 - (p - get_doc_string_buffer)); 184 - (p - get_doc_string_buffer));
184 } 185 }
185 186
@@ -501,10 +502,12 @@ aren't strings. */)
501/* Scanning the DOC files and placing docstring offsets into functions. */ 502/* Scanning the DOC files and placing docstring offsets into functions. */
502 503
503static void 504static void
504store_function_docstring (Lisp_Object fun, EMACS_INT offset) 505store_function_docstring (Lisp_Object obj, EMACS_INT offset)
505/* Use EMACS_INT because we get offset from pointer subtraction. */ 506/* Use EMACS_INT because we get offset from pointer subtraction. */
506{ 507{
507 fun = indirect_function (fun); 508 /* Don't use indirect_function here, or defaliases will apply their
509 docstrings to the base functions (Bug#2603). */
510 Lisp_Object fun = SYMBOLP (obj) ? XSYMBOL (obj)->function : obj;
508 511
509 /* The type determines where the docstring is stored. */ 512 /* The type determines where the docstring is stored. */
510 513
@@ -713,16 +716,16 @@ a new string, without any text properties, is returned. */)
713 int changed = 0; 716 int changed = 0;
714 register unsigned char *strp; 717 register unsigned char *strp;
715 register char *bufp; 718 register char *bufp;
716 EMACS_INT idx; 719 ptrdiff_t idx;
717 EMACS_INT bsize; 720 ptrdiff_t bsize;
718 Lisp_Object tem; 721 Lisp_Object tem;
719 Lisp_Object keymap; 722 Lisp_Object keymap;
720 unsigned char *start; 723 unsigned char *start;
721 EMACS_INT length, length_byte; 724 ptrdiff_t length, length_byte;
722 Lisp_Object name; 725 Lisp_Object name;
723 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; 726 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
724 int multibyte; 727 int multibyte;
725 EMACS_INT nchars; 728 ptrdiff_t nchars;
726 729
727 if (NILP (string)) 730 if (NILP (string))
728 return Qnil; 731 return Qnil;
@@ -774,7 +777,7 @@ a new string, without any text properties, is returned. */)
774 } 777 }
775 else if (strp[0] == '\\' && strp[1] == '[') 778 else if (strp[0] == '\\' && strp[1] == '[')
776 { 779 {
777 EMACS_INT start_idx; 780 ptrdiff_t start_idx;
778 int follow_remap = 1; 781 int follow_remap = 1;
779 782
780 changed = 1; 783 changed = 1;
@@ -813,7 +816,9 @@ a new string, without any text properties, is returned. */)
813 816
814 if (NILP (tem)) /* but not on any keys */ 817 if (NILP (tem)) /* but not on any keys */
815 { 818 {
816 EMACS_INT offset = bufp - buf; 819 ptrdiff_t offset = bufp - buf;
820 if (STRING_BYTES_BOUND - 4 < bsize)
821 string_overflow ();
817 buf = (char *) xrealloc (buf, bsize += 4); 822 buf = (char *) xrealloc (buf, bsize += 4);
818 bufp = buf + offset; 823 bufp = buf + offset;
819 memcpy (bufp, "M-x ", 4); 824 memcpy (bufp, "M-x ", 4);
@@ -836,7 +841,7 @@ a new string, without any text properties, is returned. */)
836 else if (strp[0] == '\\' && (strp[1] == '{' || strp[1] == '<')) 841 else if (strp[0] == '\\' && (strp[1] == '{' || strp[1] == '<'))
837 { 842 {
838 struct buffer *oldbuf; 843 struct buffer *oldbuf;
839 EMACS_INT start_idx; 844 ptrdiff_t start_idx;
840 /* This is for computing the SHADOWS arg for describe_map_tree. */ 845 /* This is for computing the SHADOWS arg for describe_map_tree. */
841 Lisp_Object active_maps = Fcurrent_active_maps (Qnil, Qnil); 846 Lisp_Object active_maps = Fcurrent_active_maps (Qnil, Qnil);
842 Lisp_Object earlier_maps; 847 Lisp_Object earlier_maps;
@@ -907,7 +912,9 @@ a new string, without any text properties, is returned. */)
907 length_byte = SBYTES (tem); 912 length_byte = SBYTES (tem);
908 subst: 913 subst:
909 { 914 {
910 EMACS_INT offset = bufp - buf; 915 ptrdiff_t offset = bufp - buf;
916 if (STRING_BYTES_BOUND - length_byte < bsize)
917 string_overflow ();
911 buf = (char *) xrealloc (buf, bsize += length_byte); 918 buf = (char *) xrealloc (buf, bsize += length_byte);
912 bufp = buf + offset; 919 bufp = buf + offset;
913 memcpy (bufp, start, length_byte); 920 memcpy (bufp, start, length_byte);