aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorStefan Monnier2024-02-01 11:06:51 -0500
committerStefan Monnier2024-02-01 11:06:51 -0500
commit886f4207ab71b2a3367566d013cbcb27eec25639 (patch)
treec5b694292c0542e6666c300eee294de13ba66762 /src
parentd0766c0999e1e78b2f63e1d97881e926e5e6f905 (diff)
downloademacs-886f4207ab71b2a3367566d013cbcb27eec25639.tar.gz
emacs-886f4207ab71b2a3367566d013cbcb27eec25639.zip
* src/lread.c (bytecode_from_rev_list): Re-group checks
Bring together all the conditions for well-formedness of the resulting bytecode object.
Diffstat (limited to 'src')
-rw-r--r--src/lread.c52
1 files changed, 27 insertions, 25 deletions
diff --git a/src/lread.c b/src/lread.c
index e77bfb8021d..a6bfdfcf626 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -3490,38 +3490,40 @@ bytecode_from_rev_list (Lisp_Object elems, Lisp_Object readcharfun)
3490 Lisp_Object *vec = XVECTOR (obj)->contents; 3490 Lisp_Object *vec = XVECTOR (obj)->contents;
3491 ptrdiff_t size = ASIZE (obj); 3491 ptrdiff_t size = ASIZE (obj);
3492 3492
3493 if (!(size >= COMPILED_CONSTANTS))
3494 {
3495 /* Always read 'lazily-loaded' bytecode (generated by the
3496 `byte-compile-dynamic' feature prior to Emacs 30) eagerly, to
3497 avoid code in the fast path during execution. */
3498 if (CONSP (vec[COMPILED_BYTECODE])
3499 && FIXNUMP (XCDR (vec[COMPILED_BYTECODE])))
3500 vec[COMPILED_BYTECODE] = get_lazy_string (vec[COMPILED_BYTECODE]);
3501
3502 /* Lazily-loaded bytecode is represented by the constant slot being nil
3503 and the bytecode slot a (lazily loaded) string containing the
3504 print representation of (BYTECODE . CONSTANTS). Unpack the
3505 pieces by coerceing the string to unibyte and reading the result. */
3506 if (NILP (vec[COMPILED_CONSTANTS]) && STRINGP (vec[COMPILED_BYTECODE]))
3507 {
3508 Lisp_Object enc = vec[COMPILED_BYTECODE];
3509 Lisp_Object pair = Fread (Fcons (enc, readcharfun));
3510 if (!CONSP (pair))
3511 invalid_syntax ("Invalid byte-code object", readcharfun);
3512
3513 vec[COMPILED_BYTECODE] = XCAR (pair);
3514 vec[COMPILED_CONSTANTS] = XCDR (pair);
3515 }
3516 }
3517
3493 if (!(size >= COMPILED_STACK_DEPTH + 1 && size <= COMPILED_INTERACTIVE + 1 3518 if (!(size >= COMPILED_STACK_DEPTH + 1 && size <= COMPILED_INTERACTIVE + 1
3494 && (FIXNUMP (vec[COMPILED_ARGLIST]) 3519 && (FIXNUMP (vec[COMPILED_ARGLIST])
3495 || CONSP (vec[COMPILED_ARGLIST]) 3520 || CONSP (vec[COMPILED_ARGLIST])
3496 || NILP (vec[COMPILED_ARGLIST])) 3521 || NILP (vec[COMPILED_ARGLIST]))
3522 && STRINGP (vec[COMPILED_BYTECODE])
3523 && VECTORP (vec[COMPILED_CONSTANTS])
3497 && FIXNATP (vec[COMPILED_STACK_DEPTH]))) 3524 && FIXNATP (vec[COMPILED_STACK_DEPTH])))
3498 invalid_syntax ("Invalid byte-code object", readcharfun); 3525 invalid_syntax ("Invalid byte-code object", readcharfun);
3499 3526
3500 /* Always read 'lazily-loaded' bytecode (generated by the
3501 `byte-compile-dynamic' feature prior to Emacs 30) eagerly, to
3502 avoid code in the fast path during execution. */
3503 if (CONSP (vec[COMPILED_BYTECODE]))
3504 vec[COMPILED_BYTECODE] = get_lazy_string (vec[COMPILED_BYTECODE]);
3505
3506 /* Lazily-loaded bytecode is represented by the constant slot being nil
3507 and the bytecode slot a (lazily loaded) string containing the
3508 print representation of (BYTECODE . CONSTANTS). Unpack the
3509 pieces by coerceing the string to unibyte and reading the result. */
3510 if (NILP (vec[COMPILED_CONSTANTS]))
3511 {
3512 Lisp_Object enc = vec[COMPILED_BYTECODE];
3513 Lisp_Object pair = Fread (Fcons (enc, readcharfun));
3514 if (!CONSP (pair))
3515 invalid_syntax ("Invalid byte-code object", readcharfun);
3516
3517 vec[COMPILED_BYTECODE] = XCAR (pair);
3518 vec[COMPILED_CONSTANTS] = XCDR (pair);
3519 }
3520
3521 if (!(STRINGP (vec[COMPILED_BYTECODE])
3522 && VECTORP (vec[COMPILED_CONSTANTS])))
3523 invalid_syntax ("Invalid byte-code object", readcharfun);
3524
3525 if (STRING_MULTIBYTE (vec[COMPILED_BYTECODE])) 3527 if (STRING_MULTIBYTE (vec[COMPILED_BYTECODE]))
3526 /* BYTESTR must have been produced by Emacs 20.2 or earlier 3528 /* BYTESTR must have been produced by Emacs 20.2 or earlier
3527 because it produced a raw 8-bit string for byte-code and 3529 because it produced a raw 8-bit string for byte-code and