aboutsummaryrefslogtreecommitdiffstats
path: root/src/bytecode.c
diff options
context:
space:
mode:
authorMattias EngdegÄrd2023-07-14 18:05:32 +0200
committerMattias EngdegÄrd2023-07-14 19:25:16 +0200
commit8acd52bba40982b4f3cadc17fb35dc96143605fb (patch)
tree578b0cb80bfab146fe0e67603c6b99d6a4a5b611 /src/bytecode.c
parent2df086d121e8ebee872236d0436205144047c5c9 (diff)
downloademacs-8acd52bba40982b4f3cadc17fb35dc96143605fb.tar.gz
emacs-8acd52bba40982b4f3cadc17fb35dc96143605fb.zip
Provide backtrace for byte-ops car, cdr, setcar, setcdr, nth and elt
Include calls to these primitives from byte-compiled code in backtraces. For nth and elt, not all errors are covered. (Bug#64613) * src/bytecode.c (exec_byte_code): Add error backtrace records for car, cdr, setcar, setcdr, nth and elt. * src/data.c (syms_of_data): Add missing defsyms for car, setcar, setcdr, nth and elt. * test/lisp/emacs-lisp/bytecomp-tests.el (bytecomp-tests--error-frame, bytecomp-tests--byte-op-error-cases) (bytecomp--byte-op-error-backtrace): New test.
Diffstat (limited to 'src/bytecode.c')
-rw-r--r--src/bytecode.c42
1 files changed, 36 insertions, 6 deletions
diff --git a/src/bytecode.c b/src/bytecode.c
index 4207ff0b71f..2eb53b0428a 100644
--- a/src/bytecode.c
+++ b/src/bytecode.c
@@ -646,7 +646,10 @@ exec_byte_code (Lisp_Object fun, ptrdiff_t args_template,
646 if (CONSP (TOP)) 646 if (CONSP (TOP))
647 TOP = XCAR (TOP); 647 TOP = XCAR (TOP);
648 else if (!NILP (TOP)) 648 else if (!NILP (TOP))
649 wrong_type_argument (Qlistp, TOP); 649 {
650 record_in_backtrace (Qcar, &TOP, 1);
651 wrong_type_argument (Qlistp, TOP);
652 }
650 NEXT; 653 NEXT;
651 654
652 CASE (Beq): 655 CASE (Beq):
@@ -668,7 +671,10 @@ exec_byte_code (Lisp_Object fun, ptrdiff_t args_template,
668 if (CONSP (TOP)) 671 if (CONSP (TOP))
669 TOP = XCDR (TOP); 672 TOP = XCDR (TOP);
670 else if (!NILP (TOP)) 673 else if (!NILP (TOP))
671 wrong_type_argument (Qlistp, TOP); 674 {
675 record_in_backtrace (Qcdr, &TOP, 1);
676 wrong_type_argument (Qlistp, TOP);
677 }
672 NEXT; 678 NEXT;
673 } 679 }
674 680
@@ -1032,7 +1038,15 @@ exec_byte_code (Lisp_Object fun, ptrdiff_t args_template,
1032 { 1038 {
1033 for (EMACS_INT n = XFIXNUM (v1); 0 < n && CONSP (v2); n--) 1039 for (EMACS_INT n = XFIXNUM (v1); 0 < n && CONSP (v2); n--)
1034 v2 = XCDR (v2); 1040 v2 = XCDR (v2);
1035 TOP = CAR (v2); 1041 if (CONSP (v2))
1042 TOP = XCAR (v2);
1043 else if (NILP (v2))
1044 TOP = Qnil;
1045 else
1046 {
1047 record_in_backtrace (Qnth, &TOP, 2);
1048 wrong_type_argument (Qlistp, v2);
1049 }
1036 } 1050 }
1037 else 1051 else
1038 TOP = Fnth (v1, v2); 1052 TOP = Fnth (v1, v2);
@@ -1552,7 +1566,15 @@ exec_byte_code (Lisp_Object fun, ptrdiff_t args_template,
1552 /* Like the fast case for Bnth, but with args reversed. */ 1566 /* Like the fast case for Bnth, but with args reversed. */
1553 for (EMACS_INT n = XFIXNUM (v2); 0 < n && CONSP (v1); n--) 1567 for (EMACS_INT n = XFIXNUM (v2); 0 < n && CONSP (v1); n--)
1554 v1 = XCDR (v1); 1568 v1 = XCDR (v1);
1555 TOP = CAR (v1); 1569 if (CONSP (v1))
1570 TOP = XCAR (v1);
1571 else if (NILP (v1))
1572 TOP = Qnil;
1573 else
1574 {
1575 record_in_backtrace (Qelt, &TOP, 2);
1576 wrong_type_argument (Qlistp, v1);
1577 }
1556 } 1578 }
1557 else 1579 else
1558 TOP = Felt (v1, v2); 1580 TOP = Felt (v1, v2);
@@ -1581,7 +1603,11 @@ exec_byte_code (Lisp_Object fun, ptrdiff_t args_template,
1581 { 1603 {
1582 Lisp_Object newval = POP; 1604 Lisp_Object newval = POP;
1583 Lisp_Object cell = TOP; 1605 Lisp_Object cell = TOP;
1584 CHECK_CONS (cell); 1606 if (!CONSP (cell))
1607 {
1608 record_in_backtrace (Qsetcar, &TOP, 2);
1609 wrong_type_argument (Qconsp, cell);
1610 }
1585 CHECK_IMPURE (cell, XCONS (cell)); 1611 CHECK_IMPURE (cell, XCONS (cell));
1586 XSETCAR (cell, newval); 1612 XSETCAR (cell, newval);
1587 TOP = newval; 1613 TOP = newval;
@@ -1592,7 +1618,11 @@ exec_byte_code (Lisp_Object fun, ptrdiff_t args_template,
1592 { 1618 {
1593 Lisp_Object newval = POP; 1619 Lisp_Object newval = POP;
1594 Lisp_Object cell = TOP; 1620 Lisp_Object cell = TOP;
1595 CHECK_CONS (cell); 1621 if (!CONSP (cell))
1622 {
1623 record_in_backtrace (Qsetcdr, &TOP, 2);
1624 wrong_type_argument (Qconsp, cell);
1625 }
1596 CHECK_IMPURE (cell, XCONS (cell)); 1626 CHECK_IMPURE (cell, XCONS (cell));
1597 XSETCDR (cell, newval); 1627 XSETCDR (cell, newval);
1598 TOP = newval; 1628 TOP = newval;