aboutsummaryrefslogtreecommitdiffstats
path: root/src/alloc.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/alloc.c')
-rw-r--r--src/alloc.c22
1 files changed, 18 insertions, 4 deletions
diff --git a/src/alloc.c b/src/alloc.c
index 8816411bcaf..668bbc75947 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -1380,7 +1380,12 @@ laligned (void *p, size_t size)
1380} 1380}
1381 1381
1382/* Like malloc and realloc except that if SIZE is Lisp-aligned, make 1382/* Like malloc and realloc except that if SIZE is Lisp-aligned, make
1383 sure the result is too. */ 1383 sure the result is too, if necessary by reallocating (typically
1384 with larger and larger sizes) until the allocator returns a
1385 Lisp-aligned pointer. Code that needs to allocate C heap memory
1386 for a Lisp object should use one of these functions to obtain a
1387 pointer P; that way, if T is an enum Lisp_Type value and L ==
1388 make_lisp_ptr (P, T), then XPNTR (L) == P and XTYPE (L) == T. */
1384 1389
1385static void * 1390static void *
1386lmalloc (size_t size) 1391lmalloc (size_t size)
@@ -1397,6 +1402,9 @@ lmalloc (size_t size)
1397 if (laligned (p, size)) 1402 if (laligned (p, size))
1398 break; 1403 break;
1399 free (p); 1404 free (p);
1405 size_t bigger;
1406 if (! INT_ADD_WRAPV (size, GCALIGNMENT, &bigger))
1407 size = bigger;
1400 } 1408 }
1401 1409
1402 eassert ((intptr_t) p % GCALIGNMENT == 0); 1410 eassert ((intptr_t) p % GCALIGNMENT == 0);
@@ -1406,9 +1414,15 @@ lmalloc (size_t size)
1406static void * 1414static void *
1407lrealloc (void *p, size_t size) 1415lrealloc (void *p, size_t size)
1408{ 1416{
1409 do 1417 while (true)
1410 p = realloc (p, size); 1418 {
1411 while (! laligned (p, size)); 1419 p = realloc (p, size);
1420 if (laligned (p, size))
1421 break;
1422 size_t bigger;
1423 if (! INT_ADD_WRAPV (size, GCALIGNMENT, &bigger))
1424 size = bigger;
1425 }
1412 1426
1413 eassert ((intptr_t) p % GCALIGNMENT == 0); 1427 eassert ((intptr_t) p % GCALIGNMENT == 0);
1414 return p; 1428 return p;