aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPip Cet2024-07-22 14:47:47 +0000
committerPip Cet2024-07-22 15:05:53 +0000
commitf330b6876ae482bc2780bb5d024ad6864a13d61c (patch)
treec7d6064cf37e0bb07046559b29f2cbce765ac7f6
parentf4a41b4c5d082f85a14d7b2dbe44f290d3ceda0b (diff)
downloademacs-f330b6876ae482bc2780bb5d024ad6864a13d61c.tar.gz
emacs-f330b6876ae482bc2780bb5d024ad6864a13d61c.zip
Correct for some incorrect pseudoheader sizes in igc.c
Arguably, these are bugs that should be fixed in lisp.h (along with the comment describing the pvec header for subrs) and thread.c, by initializing pseudovector headers so they actually describe the pseudovectors in static memory, but the traditional GC doesn't care. * src/alloc.c (make_pure_bignum): Call 'igc_init_header' after setting the pvec header, not before. * src/igc.c (gc_init_header): Catch PVEC_SUBR and PVEC_THREAD, which sometimes have incorrect headers * src/lisp.h (DEFUN) [HAVE_MPS]: Set pseudovector flag for subrs.
-rw-r--r--src/alloc.c2
-rw-r--r--src/igc.c22
-rw-r--r--src/lisp.h14
3 files changed, 33 insertions, 5 deletions
diff --git a/src/alloc.c b/src/alloc.c
index 34d4850ca32..320a5adaf0b 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -6128,8 +6128,8 @@ make_pure_bignum (Lisp_Object value)
6128 mp_size_t new_size; 6128 mp_size_t new_size;
6129 6129
6130 struct Lisp_Bignum *b = pure_alloc (sizeof *b, Lisp_Vectorlike); 6130 struct Lisp_Bignum *b = pure_alloc (sizeof *b, Lisp_Vectorlike);
6131 gc_init_header (&b->header.gc_header, IGC_OBJ_VECTOR);
6132 XSETPVECTYPESIZE (b, PVEC_BIGNUM, 0, VECSIZE (struct Lisp_Bignum)); 6131 XSETPVECTYPESIZE (b, PVEC_BIGNUM, 0, VECSIZE (struct Lisp_Bignum));
6132 gc_init_header (&b->header.gc_header, IGC_OBJ_VECTOR);
6133 6133
6134 int limb_alignment = alignof (mp_limb_t); 6134 int limb_alignment = alignof (mp_limb_t);
6135 pure_limbs = pure_alloc (nbytes, - limb_alignment); 6135 pure_limbs = pure_alloc (nbytes, - limb_alignment);
diff --git a/src/igc.c b/src/igc.c
index 21b5a42915d..ad5f7cc3e7a 100644
--- a/src/igc.c
+++ b/src/igc.c
@@ -641,11 +641,27 @@ void gc_init_header (union gc_header *header, enum igc_obj_type type)
641 break; 641 break;
642 case IGC_OBJ_VECTOR: 642 case IGC_OBJ_VECTOR:
643 { 643 {
644 ssize_t nbytes;
644 ptrdiff_t size = ((struct Lisp_Vector *)header)->header.size; 645 ptrdiff_t size = ((struct Lisp_Vector *)header)->header.size;
645 if (size & PSEUDOVECTOR_FLAG) 646 if (size & PSEUDOVECTOR_FLAG)
646 size &= PSEUDOVECTOR_SIZE_MASK; 647 {
647 set_header (h, IGC_OBJ_VECTOR, sizeof (struct Lisp_Vector) + 648 /* Correct some incorrect pseudovector headers:
648 size * sizeof (Lisp_Object), alloc_hash ()); 649 * - lisp.h sets the pseudovector tag of builtin subrs to
650 * PVEC_SUBR, but doesn't set the pseudovector flag or the
651 * lispsize/restsize fields.
652 * - thread.c uses VECSIZE (struct thread_state) for the
653 * restsize without subtracting the lispsize.
654 */
655 if (PSEUDOVECTOR_TYPE ((struct Lisp_Vector *)header) == PVEC_SUBR)
656 nbytes = sizeof (struct Lisp_Subr);
657 else if (PSEUDOVECTOR_TYPE ((struct Lisp_Vector *)header) == PVEC_THREAD)
658 nbytes = sizeof (struct thread_state);
659 else
660 nbytes = vectorlike_nbytes (&((struct Lisp_Vector *)header)->header);
661 }
662 else
663 nbytes = size * sizeof (Lisp_Object) + header_size;
664 set_header (h, IGC_OBJ_VECTOR, nbytes, alloc_hash ());
649 break; 665 break;
650 } 666 }
651 case IGC_OBJ_DUMPED_CHARSET_TABLE: 667 case IGC_OBJ_DUMPED_CHARSET_TABLE:
diff --git a/src/lisp.h b/src/lisp.h
index 5b555c62304..bb650111821 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -1,3 +1,4 @@
1
1/* Fundamental definitions for GNU Emacs Lisp interpreter. -*- coding: utf-8 -*- 2/* Fundamental definitions for GNU Emacs Lisp interpreter. -*- coding: utf-8 -*-
2 3
3Copyright (C) 1985-2024 Free Software Foundation, Inc. 4Copyright (C) 1985-2024 Free Software Foundation, Inc.
@@ -3696,13 +3697,24 @@ CHECK_SUBR (Lisp_Object x)
3696 3697
3697/* This version of DEFUN declares a function prototype with the right 3698/* This version of DEFUN declares a function prototype with the right
3698 arguments, so we can catch errors with maxargs at compile-time. */ 3699 arguments, so we can catch errors with maxargs at compile-time. */
3700#ifdef HAVE_MPS
3701#define DEFUN(lname, fnname, sname, minargs, maxargs, intspec, doc) \
3702 SUBR_SECTION_ATTRIBUTE \
3703 static union Aligned_Lisp_Subr sname = \
3704 { { { GC_HEADER_INIT \
3705 (PSEUDOVECTOR_FLAG | PVEC_SUBR << PSEUDOVECTOR_AREA_BITS) }, \
3706 { .a ## maxargs = fnname }, \
3707 minargs, maxargs, lname, {intspec}, lisp_h_Qnil}}; \
3708 Lisp_Object fnname
3709#else
3699#define DEFUN(lname, fnname, sname, minargs, maxargs, intspec, doc) \ 3710#define DEFUN(lname, fnname, sname, minargs, maxargs, intspec, doc) \
3700 SUBR_SECTION_ATTRIBUTE \ 3711 SUBR_SECTION_ATTRIBUTE \
3701 static union Aligned_Lisp_Subr sname = \ 3712 static union Aligned_Lisp_Subr sname = \
3702 { { { GC_HEADER_INIT PVEC_SUBR << PSEUDOVECTOR_AREA_BITS }, \ 3713 { { { GC_HEADER_INIT PVEC_SUBR << PSEUDOVECTOR_AREA_BITS }, \
3703 { .a ## maxargs = fnname }, \ 3714 { .a ## maxargs = fnname }, \
3704 minargs, maxargs, lname, {intspec}, lisp_h_Qnil}}; \ 3715 minargs, maxargs, lname, {intspec}, lisp_h_Qnil}}; \
3705 Lisp_Object fnname 3716 Lisp_Object fnname
3717#endif
3706 3718
3707/* defsubr (Sname); 3719/* defsubr (Sname);
3708 is how we define the symbol for function `name' at start-up time. */ 3720 is how we define the symbol for function `name' at start-up time. */