]> git.eshelyaron.com Git - emacs.git/commitdiff
* src/lread.c (bytecode_from_rev_list): Re-group checks
authorStefan Monnier <monnier@iro.umontreal.ca>
Thu, 1 Feb 2024 16:06:51 +0000 (11:06 -0500)
committerEshel Yaron <me@eshelyaron.com>
Sun, 4 Feb 2024 11:02:09 +0000 (12:02 +0100)
Bring together all the conditions for well-formedness of the resulting
bytecode object.

(cherry picked from commit 886f4207ab71b2a3367566d013cbcb27eec25639)

src/lread.c

index e77bfb8021d84c560f75e6b4d10dcce89ee68e62..a6bfdfcf626746c630e4e4a2822507e82bc026cb 100644 (file)
@@ -3490,38 +3490,40 @@ bytecode_from_rev_list (Lisp_Object elems, Lisp_Object readcharfun)
   Lisp_Object *vec = XVECTOR (obj)->contents;
   ptrdiff_t size = ASIZE (obj);
 
+  if (!(size >= COMPILED_CONSTANTS))
+    {
+      /* Always read 'lazily-loaded' bytecode (generated by the
+         `byte-compile-dynamic' feature prior to Emacs 30) eagerly, to
+         avoid code in the fast path during execution.  */
+      if (CONSP (vec[COMPILED_BYTECODE])
+          && FIXNUMP (XCDR (vec[COMPILED_BYTECODE])))
+        vec[COMPILED_BYTECODE] = get_lazy_string (vec[COMPILED_BYTECODE]);
+
+      /* Lazily-loaded bytecode is represented by the constant slot being nil
+         and the bytecode slot a (lazily loaded) string containing the
+         print representation of (BYTECODE . CONSTANTS).  Unpack the
+         pieces by coerceing the string to unibyte and reading the result.  */
+      if (NILP (vec[COMPILED_CONSTANTS]) && STRINGP (vec[COMPILED_BYTECODE]))
+        {
+          Lisp_Object enc = vec[COMPILED_BYTECODE];
+          Lisp_Object pair = Fread (Fcons (enc, readcharfun));
+          if (!CONSP (pair))
+           invalid_syntax ("Invalid byte-code object", readcharfun);
+
+          vec[COMPILED_BYTECODE] = XCAR (pair);
+          vec[COMPILED_CONSTANTS] = XCDR (pair);
+        }
+    }
+
   if (!(size >= COMPILED_STACK_DEPTH + 1 && size <= COMPILED_INTERACTIVE + 1
        && (FIXNUMP (vec[COMPILED_ARGLIST])
            || CONSP (vec[COMPILED_ARGLIST])
            || NILP (vec[COMPILED_ARGLIST]))
+       && STRINGP (vec[COMPILED_BYTECODE])
+       && VECTORP (vec[COMPILED_CONSTANTS])
        && FIXNATP (vec[COMPILED_STACK_DEPTH])))
     invalid_syntax ("Invalid byte-code object", readcharfun);
 
-  /* Always read 'lazily-loaded' bytecode (generated by the
-     `byte-compile-dynamic' feature prior to Emacs 30) eagerly, to
-     avoid code in the fast path during execution.  */
-  if (CONSP (vec[COMPILED_BYTECODE]))
-    vec[COMPILED_BYTECODE] = get_lazy_string (vec[COMPILED_BYTECODE]);
-
-  /* Lazily-loaded bytecode is represented by the constant slot being nil
-     and the bytecode slot a (lazily loaded) string containing the
-     print representation of (BYTECODE . CONSTANTS).  Unpack the
-     pieces by coerceing the string to unibyte and reading the result.  */
-  if (NILP (vec[COMPILED_CONSTANTS]))
-    {
-      Lisp_Object enc = vec[COMPILED_BYTECODE];
-      Lisp_Object pair = Fread (Fcons (enc, readcharfun));
-      if (!CONSP (pair))
-       invalid_syntax ("Invalid byte-code object", readcharfun);
-
-      vec[COMPILED_BYTECODE] = XCAR (pair);
-      vec[COMPILED_CONSTANTS] = XCDR (pair);
-    }
-
-  if (!(STRINGP (vec[COMPILED_BYTECODE])
-       && VECTORP (vec[COMPILED_CONSTANTS])))
-    invalid_syntax ("Invalid byte-code object", readcharfun);
-
   if (STRING_MULTIBYTE (vec[COMPILED_BYTECODE]))
     /* BYTESTR must have been produced by Emacs 20.2 or earlier
        because it produced a raw 8-bit string for byte-code and