aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert2016-02-08 20:24:55 -0800
committerPaul Eggert2016-02-08 20:25:23 -0800
commitb1079c0f86c218f016a6c2e84ea402f4e175fc53 (patch)
tree1103d4fb608cd77bb3b8a8b3cc33904a63906a61 /src
parenta3bf4a387fdc44e5631a6431a2e40e741c672359 (diff)
downloademacs-b1079c0f86c218f016a6c2e84ea402f4e175fc53.tar.gz
emacs-b1079c0f86c218f016a6c2e84ea402f4e175fc53.zip
Increase success rate of fallback lmalloc
* src/alloc.c (lmalloc, lrealloc): Reallocate with (typically) larger and larger sizes, to increase the probability that the allocator will return a Lisp-aligned pointer.
Diffstat (limited to 'src')
-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;