]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix store_function_docstring for native subrs (Bug#74966)
authorPip Cet <pipcet@protonmail.com>
Wed, 8 Jan 2025 12:15:30 +0000 (12:15 +0000)
committerEshel Yaron <me@eshelyaron.com>
Sat, 11 Jan 2025 11:15:35 +0000 (12:15 +0100)
Since native subrs can have either etc/DOC indexes or vector indexes,
we use the sign bit of the 'doc' field to distinguish the two cases.

* src/comp.c (native_function_doc, make_subr): Use one's complement of
doc index for native subrs.
* src/doc.c (store_function_docstring): Add assertion.
* src/lisp.h (struct Lisp_Subr): Document 'doc' sign bit.

(cherry picked from commit ac52993b996927031a6913927e1028de47be4312)

src/comp.c
src/doc.c
src/lisp.h

index 70a9a64a714ecd6199bfbf97bfee1ac47c835368..b96fae4ae955fb48e05ef0ea78198718b3ccde07 100644 (file)
@@ -5488,7 +5488,10 @@ native_function_doc (Lisp_Object function)
   if (!VECTORP (cu->data_fdoc_v))
     xsignal2 (Qnative_lisp_file_inconsistent, cu->file,
              build_string ("missing documentation vector"));
-  return AREF (cu->data_fdoc_v, XSUBR (function)->doc);
+  EMACS_INT doc = XSUBR (function)->doc;
+  if (doc < 0)
+    return AREF (cu->data_fdoc_v, -doc - 1);
+  return make_fixnum (doc);
 }
 
 static Lisp_Object
@@ -5529,7 +5532,8 @@ make_subr (Lisp_Object symbol_name, Lisp_Object minarg, Lisp_Object maxarg,
   x->s.symbol_name = xstrdup (SSDATA (symbol_name));
   x->s.intspec.native = intspec;
   x->s.command_modes = command_modes;
-  x->s.doc = XFIXNUM (doc_idx);
+  x->s.doc = -XFIXNUM (doc_idx) - 1;
+  eassert (x->s.doc < 0);
 #ifdef HAVE_NATIVE_COMP
   x->s.native_comp_u = comp_u;
   x->s.native_c_name = xstrdup (SSDATA (c_name));
index 88be9121dab8bf2fcd118b32e2994cf511add9d5..04afe50d3dd23d046c20b1bbbcd1f9f93b8b0950 100644 (file)
--- a/src/doc.c
+++ b/src/doc.c
@@ -479,7 +479,10 @@ store_function_docstring (Lisp_Object obj, EMACS_INT offset)
     fun = XCDR (fun);
   /* Lisp_Subrs have a slot for it.  */
   if (SUBRP (fun))
-    XSUBR (fun)->doc = offset;
+    {
+      XSUBR (fun)->doc = offset;
+      eassert (XSUBR (fun)->doc >= 0);
+    }
   else if (CLOSUREP (fun))
     {
       /* This bytecode object must have a slot for the docstring, since
index 4217dd9e347a4b50bc48402ff9ab89669354da7e..4c09afc77e2328951c309be8fdbce320962f5c49 100644 (file)
@@ -2228,6 +2228,9 @@ struct Lisp_Subr
       Lisp_Object native;
     } intspec;
     Lisp_Object command_modes;
+    /* positive values: offset into etc/DOC.  Negative values: one's
+       complement of index into the native comp unit's function
+       documentation vector.  */
     EMACS_INT doc;
 #ifdef HAVE_NATIVE_COMP
     Lisp_Object native_comp_u;