From d3c5debc5a1f2f5c1fe1269fbb76f7c9f669aa5b Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Fri, 24 Jan 2025 00:16:08 +0100 Subject: [PATCH] Don't use negative positions for docstrings These were used for user-variables (doc starts with a '*'), but we don't use that convention any more. On my machine, there are no docstrings starting with a '*' in etc/DOC. * src/doc.c (Fsnarf_documentation): Never use negative positions. (get_doc_string): Don't use eabs; position must now be positive, and all callers are verified to do that. (cherry picked from commit c7f6da7a4141a9f3492b8dbb0c1de710bd4757fa) --- src/doc.c | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/src/doc.c b/src/doc.c index d16d3d5186e..0ce1274fe12 100644 --- a/src/doc.c +++ b/src/doc.c @@ -96,9 +96,6 @@ close_file_unwind_android_fd (void *ptr) If it is an integer, use that position in the standard DOC file. If it is (FILE . INTEGER), use FILE as the file name and INTEGER as the position in that file. - But if INTEGER is negative, make it positive. - (A negative integer is used for user variables, so we can distinguish - them without actually fetching the doc string.) If the location does not point to the beginning of a docstring (e.g. because the file has been modified and the location is stale), @@ -130,7 +127,7 @@ get_doc_string (Lisp_Object filepos, bool unibyte) else return Qnil; - EMACS_INT position = eabs (XFIXNUM (pos)); + EMACS_INT position = XFIXNUM (pos); if (!STRINGP (dir)) return Qnil; @@ -192,7 +189,7 @@ get_doc_string (Lisp_Object filepos, bool unibyte) P points beyond the data just read. */ p = get_doc_string_buffer; - while (1) + while (true) { ptrdiff_t space_left = (get_doc_string_buffer_size - 1 - (p - get_doc_string_buffer)); @@ -508,10 +505,7 @@ That file is found in `../etc' now; later, when the dumped Emacs is run, the same file name is found in the `doc-directory'. */) (Lisp_Object filename) { - doc_fd fd; char buf[1024 + 1]; - int filled; - EMACS_INT pos; Lisp_Object sym; char *p, *name; char const *dirname; @@ -555,7 +549,7 @@ the same file name is found in the `doc-directory'. */) Vbuild_files = Fpurecopy (Vbuild_files); } - fd = doc_open (name, O_RDONLY, 0); + doc_fd fd = doc_open (name, O_RDONLY, 0); if (!doc_fd_p (fd)) { int open_errno = errno; @@ -568,8 +562,8 @@ the same file name is found in the `doc-directory'. */) record_unwind_protect_ptr (close_file_unwind_android_fd, &fd); #endif /* !USE_ANDROID_ASSETS */ Vdoc_file_name = filename; - filled = 0; - pos = 0; + int filled = 0; + EMACS_INT pos = 0; while (true) { if (filled < 512) @@ -609,15 +603,13 @@ the same file name is found in the `doc-directory'. */) /* Attach a docstring to a variable? */ if (p[1] == 'V') { - /* Install file-position as variable-documentation property - and make it negative for a user-variable - (doc starts with a `*'). */ + /* Install file-position as variable-documentation + property. */ if ((!NILP (Fboundp (sym)) || !NILP (Fmemq (sym, delayed_init))) && strncmp (end, "\nSKIP", 5)) Fput (sym, Qvariable_documentation, - make_fixnum ((pos + end + 1 - buf) - * (end[1] == '*' ? -1 : 1))); + make_fixnum (pos + end + 1 - buf)); } /* Attach a docstring to a function? */ -- 2.39.5