aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Eggert2018-09-07 09:17:25 -0700
committerPaul Eggert2018-09-07 09:20:13 -0700
commitcab3ca9d3d9449867e9fe1f954fec386a3bb7d46 (patch)
tree667fe6fb7e2aeb6760a05069057056edd75ccfdb
parent752a05b17dfb1bfb27867f1cf3a7548dbb570d26 (diff)
downloademacs-cab3ca9d3d9449867e9fe1f954fec386a3bb7d46.tar.gz
emacs-cab3ca9d3d9449867e9fe1f954fec386a3bb7d46.zip
Fix overenthusiastic header size check
Problem reported by Eli Zaretskii in: https://lists.gnu.org/r/emacs-devel/2018-09/msg00222.html * doc/lispref/internals.texi (Garbage Collection): Document vector sizes and slot counts more accurately. * src/lisp.h: Omit header_size sanity check that was too picky. Add some less-picky checks.
-rw-r--r--doc/lispref/internals.texi4
-rw-r--r--src/lisp.h26
2 files changed, 22 insertions, 8 deletions
diff --git a/doc/lispref/internals.texi b/doc/lispref/internals.texi
index 3fe28446eaf..d42e2444e68 100644
--- a/doc/lispref/internals.texi
+++ b/doc/lispref/internals.texi
@@ -382,7 +382,7 @@ This is used for convenience and equals to @code{sizeof (char)}.
382The total size of all string data in bytes. 382The total size of all string data in bytes.
383 383
384@item vector-size 384@item vector-size
385Internal size of a vector header, i.e., @code{sizeof (struct Lisp_Vector)}. 385Size in bytes of a vector of length 1, including its header.
386 386
387@item used-vectors 387@item used-vectors
388The number of vector headers allocated from the vector blocks. 388The number of vector headers allocated from the vector blocks.
@@ -392,6 +392,8 @@ Internal size of a vector slot, always equal to @code{sizeof (Lisp_Object)}.
392 392
393@item used-slots 393@item used-slots
394The number of slots in all used vectors. 394The number of slots in all used vectors.
395Slot counts might include some or all overhead from vector headers,
396depending on the platform.
395 397
396@item free-slots 398@item free-slots
397The number of free slots in all vector blocks. 399The number of free slots in all vector blocks.
diff --git a/src/lisp.h b/src/lisp.h
index 7e365e8f478..56623a75f74 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -1619,7 +1619,16 @@ struct Lisp_Bool_Vector
1619 } GCALIGNED_STRUCT; 1619 } GCALIGNED_STRUCT;
1620 1620
1621/* Some handy constants for calculating sizes 1621/* Some handy constants for calculating sizes
1622 and offsets, mostly of vectorlike objects. */ 1622 and offsets, mostly of vectorlike objects.
1623
1624 The garbage collector assumes that the initial part of any struct
1625 that starts with a union vectorlike_header followed by N
1626 Lisp_Objects (some possibly in arrays and/or a trailing flexible
1627 array) will be laid out like a struct Lisp_Vector with N
1628 Lisp_Objects. This assumption is true in practice on known Emacs
1629 targets even though the C standard does not guarantee it. This
1630 header contains a few sanity checks that should suffice to detect
1631 violations of this assumption on plausible practical hosts. */
1623 1632
1624enum 1633enum
1625 { 1634 {
@@ -1627,7 +1636,6 @@ enum
1627 bool_header_size = offsetof (struct Lisp_Bool_Vector, data), 1636 bool_header_size = offsetof (struct Lisp_Bool_Vector, data),
1628 word_size = sizeof (Lisp_Object) 1637 word_size = sizeof (Lisp_Object)
1629 }; 1638 };
1630verify (header_size == sizeof (union vectorlike_header));
1631 1639
1632/* The number of data words and bytes in a bool vector with SIZE bits. */ 1640/* The number of data words and bytes in a bool vector with SIZE bits. */
1633 1641
@@ -1989,6 +1997,13 @@ enum char_table_specials
1989 SUB_CHAR_TABLE_OFFSET = PSEUDOVECSIZE (struct Lisp_Sub_Char_Table, contents) 1997 SUB_CHAR_TABLE_OFFSET = PSEUDOVECSIZE (struct Lisp_Sub_Char_Table, contents)
1990 }; 1998 };
1991 1999
2000/* Sanity-check pseudovector layout. */
2001verify (offsetof (struct Lisp_Char_Table, defalt) == header_size);
2002verify (offsetof (struct Lisp_Char_Table, extras)
2003 == header_size + CHAR_TABLE_STANDARD_SLOTS * sizeof (Lisp_Object));
2004verify (offsetof (struct Lisp_Sub_Char_Table, contents)
2005 == header_size + SUB_CHAR_TABLE_OFFSET * sizeof (Lisp_Object));
2006
1992/* Return the number of "extra" slots in the char table CT. */ 2007/* Return the number of "extra" slots in the char table CT. */
1993 2008
1994INLINE int 2009INLINE int
@@ -1998,11 +2013,6 @@ CHAR_TABLE_EXTRA_SLOTS (struct Lisp_Char_Table *ct)
1998 - CHAR_TABLE_STANDARD_SLOTS); 2013 - CHAR_TABLE_STANDARD_SLOTS);
1999} 2014}
2000 2015
2001/* Make sure that sub char-table contents slot is where we think it is. */
2002verify (offsetof (struct Lisp_Sub_Char_Table, contents)
2003 == (offsetof (struct Lisp_Vector, contents)
2004 + SUB_CHAR_TABLE_OFFSET * sizeof (Lisp_Object)));
2005
2006 2016
2007/* Save and restore the instruction and environment pointers, 2017/* Save and restore the instruction and environment pointers,
2008 without affecting the signal mask. */ 2018 without affecting the signal mask. */
@@ -2216,6 +2226,8 @@ struct Lisp_Hash_Table
2216 struct Lisp_Hash_Table *next_weak; 2226 struct Lisp_Hash_Table *next_weak;
2217} GCALIGNED_STRUCT; 2227} GCALIGNED_STRUCT;
2218 2228
2229/* Sanity-check pseudovector layout. */
2230verify (offsetof (struct Lisp_Hash_Table, weak) == header_size);
2219 2231
2220INLINE bool 2232INLINE bool
2221HASH_TABLE_P (Lisp_Object a) 2233HASH_TABLE_P (Lisp_Object a)