diff options
Diffstat (limited to 'src/doc.c')
-rw-r--r-- | src/doc.c | 55 |
1 files changed, 29 insertions, 26 deletions
diff --git a/src/doc.c b/src/doc.c index 6f62a96b3ca..7234fb38bf9 100644 --- a/src/doc.c +++ b/src/doc.c @@ -22,7 +22,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ #include <config.h> #include <sys/types.h> -#include <sys/file.h> /* Must be after sys/types.h for USG*/ +#include <sys/file.h> /* Must be after sys/types.h for USG. */ #include <fcntl.h> #include <unistd.h> @@ -43,7 +43,7 @@ static ptrdiff_t get_doc_string_buffer_size; static unsigned char *read_bytecode_pointer; -/* readchar in lread.c calls back here to fetch the next byte. +/* `readchar' in lread.c calls back here to fetch the next byte. If UNREADFLAG is 1, we unread a byte. */ int @@ -84,24 +84,23 @@ get_doc_string (Lisp_Object filepos, bool unibyte, bool definition) ptrdiff_t minsize; int offset; EMACS_INT position; - Lisp_Object file, tem; + Lisp_Object file, tem, pos; USE_SAFE_ALLOCA; if (INTEGERP (filepos)) { file = Vdoc_file_name; - position = XINT (filepos); + pos = filepos; } else if (CONSP (filepos)) { file = XCAR (filepos); - position = XINT (XCDR (filepos)); + pos = XCDR (filepos); } else return Qnil; - if (position < 0) - position = - position; + position = eabs (XINT (pos)); if (!STRINGP (Vdoc_directory)) return Qnil; @@ -177,9 +176,9 @@ get_doc_string (Lisp_Object filepos, bool unibyte, bool definition) if (space_left <= 0) { 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); + 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 - 1 - (p - get_doc_string_buffer)); @@ -280,10 +279,10 @@ Invalid data in documentation file -- %c followed by code %03o", else { /* 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)); + 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)); @@ -348,6 +347,8 @@ string is passed through `substitute-command-keys'. */) } fun = Findirect_function (function, Qnil); + if (CONSP (fun) && EQ (XCAR (fun), Qmacro)) + fun = XCDR (fun); if (SUBRP (fun)) { if (XSUBR (fun)->doc == 0) @@ -401,8 +402,6 @@ string is passed through `substitute-command-keys'. */) else return Qnil; } - else if (EQ (funcar, Qmacro)) - return Fdocumentation (Fcdr (fun), raw); else goto oops; } @@ -412,16 +411,19 @@ string is passed through `substitute-command-keys'. */) xsignal1 (Qinvalid_function, fun); } - /* Check for an advised function. Its doc string - has an `ad-advice-info' text property. */ + /* Check for a dynamic docstring. These come with + a dynamic-docstring-function text property. */ if (STRINGP (doc)) { - Lisp_Object innerfunc; - innerfunc = Fget_text_property (make_number (0), - intern ("ad-advice-info"), + Lisp_Object func + = Fget_text_property (make_number (0), + intern ("dynamic-docstring-function"), doc); - if (! NILP (innerfunc)) - doc = call1 (intern ("ad-make-advised-docstring"), innerfunc); + if (!NILP (func)) + /* Pass both `doc' and `function' since `function' can be needed, and + finding `doc' can be annoying: calling `documentation' is not an + option because it would infloop. */ + doc = call2 (func, doc, function); } /* If DOC is 0, it's typically because of a dumped file missing @@ -529,6 +531,8 @@ store_function_docstring (Lisp_Object obj, ptrdiff_t offset) { tem = Fcdr (Fcdr (fun)); if (CONSP (tem) && INTEGERP (XCAR (tem))) + /* FIXME: This modifies typically pure hash-cons'd data, so its + correctness is quite delicate. */ XSETCAR (tem, make_number (offset)); } else if (EQ (tem, Qmacro)) @@ -626,11 +630,10 @@ the same file name is found in the `doc-directory'. */) break; buf[filled] = 0; - p = buf; end = buf + (filled < 512 ? filled : filled - 128); - while (p != end && *p != '\037') p++; + p = memchr (buf, '\037', end - buf); /* p points to ^_Ffunctionname\n or ^_Vvarname\n or ^_Sfilename\n. */ - if (p != end) + if (p) { end = strchr (p, '\n'); |