aboutsummaryrefslogtreecommitdiffstats
path: root/src/alloc.c
diff options
context:
space:
mode:
authorPaul Eggert2019-05-13 12:43:13 -0700
committerPaul Eggert2019-05-13 12:43:39 -0700
commit967711995ecedc0ed79602ad71af57f45d6a3720 (patch)
tree09b3995b7607de222bc22dc3511bde137cb940c5 /src/alloc.c
parent3de3452014e8c8dade2cd62aa6c6a701692aa3f9 (diff)
downloademacs-967711995ecedc0ed79602ad71af57f45d6a3720.tar.gz
emacs-967711995ecedc0ed79602ad71af57f45d6a3720.zip
Fix broken build on m68k
The GCC + valgrind fix caused the m68k build to fail (Bug#35711). Simplify string allocation a bit to make similar problems less likely in the future. * src/alloc.c (sdata, SDATA_NBYTES, SDATA_DATA) [GC_CHECK_STRING_BYTES]: Use the same implementation as with !GC_CHECK_STRING_BYTES, as the special case is no longer needed. (SDATA_ALIGN): New constant. (SDATA_SIZE): Remove this macro, replacing with ... (sdata_size): ... this new function. All uses changed. Properly account for sizes and alignments even in the m68k case, and even if GC_CHECK_STRING_BYTES is not defined.
Diffstat (limited to 'src/alloc.c')
-rw-r--r--src/alloc.c77
1 files changed, 25 insertions, 52 deletions
diff --git a/src/alloc.c b/src/alloc.c
index 948a0e8a2dc..af4adb3856e 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -1447,9 +1447,7 @@ mark_interval_tree (INTERVAL i)
1447 1447
1448#define LARGE_STRING_BYTES 1024 1448#define LARGE_STRING_BYTES 1024
1449 1449
1450/* The SDATA typedef is a struct or union describing string memory 1450/* The layout of a nonnull string. */
1451 sub-allocated from an sblock. This is where the contents of Lisp
1452 strings are stored. */
1453 1451
1454struct sdata 1452struct sdata
1455{ 1453{
@@ -1468,13 +1466,8 @@ struct sdata
1468 unsigned char data[FLEXIBLE_ARRAY_MEMBER]; 1466 unsigned char data[FLEXIBLE_ARRAY_MEMBER];
1469}; 1467};
1470 1468
1471#ifdef GC_CHECK_STRING_BYTES 1469/* A union describing string memory sub-allocated from an sblock.
1472 1470 This is where the contents of Lisp strings are stored. */
1473typedef struct sdata sdata;
1474#define SDATA_NBYTES(S) (S)->nbytes
1475#define SDATA_DATA(S) (S)->data
1476
1477#else
1478 1471
1479typedef union 1472typedef union
1480{ 1473{
@@ -1502,8 +1495,6 @@ typedef union
1502#define SDATA_NBYTES(S) (S)->n.nbytes 1495#define SDATA_NBYTES(S) (S)->n.nbytes
1503#define SDATA_DATA(S) ((struct sdata *) (S))->data 1496#define SDATA_DATA(S) ((struct sdata *) (S))->data
1504 1497
1505#endif /* not GC_CHECK_STRING_BYTES */
1506
1507enum { SDATA_DATA_OFFSET = offsetof (struct sdata, data) }; 1498enum { SDATA_DATA_OFFSET = offsetof (struct sdata, data) };
1508 1499
1509/* Structure describing a block of memory which is sub-allocated to 1500/* Structure describing a block of memory which is sub-allocated to
@@ -1586,31 +1577,20 @@ static char const string_overrun_cookie[GC_STRING_OVERRUN_COOKIE_SIZE] =
1586# define GC_STRING_OVERRUN_COOKIE_SIZE 0 1577# define GC_STRING_OVERRUN_COOKIE_SIZE 0
1587#endif 1578#endif
1588 1579
1589/* Value is the size of an sdata structure large enough to hold NBYTES 1580/* Return the size of an sdata structure large enough to hold N bytes
1590 bytes of string data. The value returned includes a terminating 1581 of string data. This counts the sdata structure, the N bytes, a
1591 NUL byte, the size of the sdata structure, and padding. */ 1582 terminating NUL byte, and alignment padding. */
1592
1593#ifdef GC_CHECK_STRING_BYTES
1594
1595#define SDATA_SIZE(NBYTES) FLEXSIZEOF (struct sdata, data, (NBYTES) + 1)
1596 1583
1597#else /* not GC_CHECK_STRING_BYTES */ 1584static ptrdiff_t
1598 1585sdata_size (ptrdiff_t n)
1599/* The 'max' reserves space for the nbytes union member even when NBYTES + 1 is 1586{
1600 less than the size of that member. The 'max' is not needed when 1587 /* Reserve space for the nbytes union member even when N + 1 is less
1601 SDATA_DATA_OFFSET is a multiple of FLEXALIGNOF (struct sdata), 1588 than the size of that member. */
1602 because then the alignment code reserves enough space. */ 1589 ptrdiff_t unaligned_size = max (SDATA_DATA_OFFSET + n + 1,
1603 1590 sizeof (sdata));
1604#define SDATA_SIZE(NBYTES) \ 1591 int sdata_align = max (FLEXALIGNOF (struct sdata), alignof (sdata));
1605 ((SDATA_DATA_OFFSET \ 1592 return (unaligned_size + sdata_align - 1) & ~(sdata_align - 1);
1606 + (SDATA_DATA_OFFSET % FLEXALIGNOF (struct sdata) == 0 \ 1593}
1607 ? NBYTES \
1608 : max (NBYTES, FLEXALIGNOF (struct sdata) - 1)) \
1609 + 1 \
1610 + FLEXALIGNOF (struct sdata) - 1) \
1611 & ~(FLEXALIGNOF (struct sdata) - 1))
1612
1613#endif /* not GC_CHECK_STRING_BYTES */
1614 1594
1615/* Extra bytes to allocate for each string. */ 1595/* Extra bytes to allocate for each string. */
1616#define GC_STRING_EXTRA GC_STRING_OVERRUN_COOKIE_SIZE 1596#define GC_STRING_EXTRA GC_STRING_OVERRUN_COOKIE_SIZE
@@ -1664,21 +1644,14 @@ string_bytes (struct Lisp_String *s)
1664static void 1644static void
1665check_sblock (struct sblock *b) 1645check_sblock (struct sblock *b)
1666{ 1646{
1667 sdata *from, *end, *from_end; 1647 sdata *end = b->next_free;
1668
1669 end = b->next_free;
1670 1648
1671 for (from = b->data; from < end; from = from_end) 1649 for (sdata *from = b->data; from < end; )
1672 { 1650 {
1673 /* Compute the next FROM here because copying below may 1651 ptrdiff_t nbytes = sdata_size (from->string
1674 overwrite data we need to compute it. */ 1652 ? string_bytes (from->string)
1675 ptrdiff_t nbytes; 1653 : SDATA_NBYTES (from));
1676 1654 from = (sdata *) ((char *) from + nbytes + GC_STRING_EXTRA);
1677 /* Check that the string size recorded in the string is the
1678 same as the one recorded in the sdata structure. */
1679 nbytes = SDATA_SIZE (from->string ? string_bytes (from->string)
1680 : SDATA_NBYTES (from));
1681 from_end = (sdata *) ((char *) from + nbytes + GC_STRING_EXTRA);
1682 } 1655 }
1683} 1656}
1684 1657
@@ -1810,14 +1783,14 @@ allocate_string_data (struct Lisp_String *s,
1810{ 1783{
1811 sdata *data, *old_data; 1784 sdata *data, *old_data;
1812 struct sblock *b; 1785 struct sblock *b;
1813 ptrdiff_t needed, old_nbytes; 1786 ptrdiff_t old_nbytes;
1814 1787
1815 if (STRING_BYTES_MAX < nbytes) 1788 if (STRING_BYTES_MAX < nbytes)
1816 string_overflow (); 1789 string_overflow ();
1817 1790
1818 /* Determine the number of bytes needed to store NBYTES bytes 1791 /* Determine the number of bytes needed to store NBYTES bytes
1819 of string data. */ 1792 of string data. */
1820 needed = SDATA_SIZE (nbytes); 1793 ptrdiff_t needed = sdata_size (nbytes);
1821 if (s->u.s.data) 1794 if (s->u.s.data)
1822 { 1795 {
1823 old_data = SDATA_OF_STRING (s); 1796 old_data = SDATA_OF_STRING (s);
@@ -2068,7 +2041,7 @@ compact_small_strings (void)
2068 nbytes = s ? STRING_BYTES (s) : SDATA_NBYTES (from); 2041 nbytes = s ? STRING_BYTES (s) : SDATA_NBYTES (from);
2069 eassert (nbytes <= LARGE_STRING_BYTES); 2042 eassert (nbytes <= LARGE_STRING_BYTES);
2070 2043
2071 ptrdiff_t size = SDATA_SIZE (nbytes); 2044 ptrdiff_t size = sdata_size (nbytes);
2072 sdata *from_end = (sdata *) ((char *) from 2045 sdata *from_end = (sdata *) ((char *) from
2073 + size + GC_STRING_EXTRA); 2046 + size + GC_STRING_EXTRA);
2074 2047