diff options
| author | Paul Eggert | 2016-02-09 14:26:40 -0800 |
|---|---|---|
| committer | Paul Eggert | 2016-02-09 14:26:40 -0800 |
| commit | 8456ba1d493d5e5b46e450d0e8b2dd1577f246ab (patch) | |
| tree | 9b57b19f6591e3c8f673e6152bfb9828c1940967 /src | |
| parent | 0e7b901b905fb8db3c7e391661f1510e96ff3814 (diff) | |
| parent | 145a11e1a3417d0fef60148296f2e8f97e09d5e9 (diff) | |
| download | emacs-8456ba1d493d5e5b46e450d0e8b2dd1577f246ab.tar.gz emacs-8456ba1d493d5e5b46e450d0e8b2dd1577f246ab.zip | |
-
Diffstat (limited to 'src')
| -rw-r--r-- | src/alloc.c | 34 | ||||
| -rw-r--r-- | src/lisp.h | 4 |
2 files changed, 28 insertions, 10 deletions
diff --git a/src/alloc.c b/src/alloc.c index 81cfdb011dc..5ee1cc340a5 100644 --- a/src/alloc.c +++ b/src/alloc.c | |||
| @@ -1383,12 +1383,25 @@ lisp_align_free (void *block) | |||
| 1383 | static bool | 1383 | static bool |
| 1384 | laligned (void *p, size_t size) | 1384 | laligned (void *p, size_t size) |
| 1385 | { | 1385 | { |
| 1386 | return (MALLOC_IS_GC_ALIGNED || size % GCALIGNMENT != 0 | 1386 | return (MALLOC_IS_GC_ALIGNED || (intptr_t) p % GCALIGNMENT == 0 |
| 1387 | || (intptr_t) p % GCALIGNMENT == 0); | 1387 | || size % GCALIGNMENT != 0); |
| 1388 | } | 1388 | } |
| 1389 | 1389 | ||
| 1390 | /* Like malloc and realloc except that if SIZE is Lisp-aligned, make | 1390 | /* Like malloc and realloc except that if SIZE is Lisp-aligned, make |
| 1391 | sure the result is too. */ | 1391 | sure the result is too, if necessary by reallocating (typically |
| 1392 | with larger and larger sizes) until the allocator returns a | ||
| 1393 | Lisp-aligned pointer. Code that needs to allocate C heap memory | ||
| 1394 | for a Lisp object should use one of these functions to obtain a | ||
| 1395 | pointer P; that way, if T is an enum Lisp_Type value and L == | ||
| 1396 | make_lisp_ptr (P, T), then XPNTR (L) == P and XTYPE (L) == T. | ||
| 1397 | |||
| 1398 | On typical modern platforms these functions' loops do not iterate. | ||
| 1399 | On now-rare (and perhaps nonexistent) platforms, the loops in | ||
| 1400 | theory could repeat forever. If an infinite loop is possible on a | ||
| 1401 | platform, a build would surely loop and the builder can then send | ||
| 1402 | us a bug report. Adding a counter to try to detect any such loop | ||
| 1403 | would complicate the code (and possibly introduce bugs, in code | ||
| 1404 | that's never really exercised) for little benefit. */ | ||
| 1392 | 1405 | ||
| 1393 | static void * | 1406 | static void * |
| 1394 | lmalloc (size_t size) | 1407 | lmalloc (size_t size) |
| @@ -1405,6 +1418,9 @@ lmalloc (size_t size) | |||
| 1405 | if (laligned (p, size)) | 1418 | if (laligned (p, size)) |
| 1406 | break; | 1419 | break; |
| 1407 | free (p); | 1420 | free (p); |
| 1421 | size_t bigger; | ||
| 1422 | if (! INT_ADD_WRAPV (size, GCALIGNMENT, &bigger)) | ||
| 1423 | size = bigger; | ||
| 1408 | } | 1424 | } |
| 1409 | 1425 | ||
| 1410 | eassert ((intptr_t) p % GCALIGNMENT == 0); | 1426 | eassert ((intptr_t) p % GCALIGNMENT == 0); |
| @@ -1414,9 +1430,15 @@ lmalloc (size_t size) | |||
| 1414 | static void * | 1430 | static void * |
| 1415 | lrealloc (void *p, size_t size) | 1431 | lrealloc (void *p, size_t size) |
| 1416 | { | 1432 | { |
| 1417 | do | 1433 | while (true) |
| 1418 | p = realloc (p, size); | 1434 | { |
| 1419 | while (! laligned (p, size)); | 1435 | p = realloc (p, size); |
| 1436 | if (laligned (p, size)) | ||
| 1437 | break; | ||
| 1438 | size_t bigger; | ||
| 1439 | if (! INT_ADD_WRAPV (size, GCALIGNMENT, &bigger)) | ||
| 1440 | size = bigger; | ||
| 1441 | } | ||
| 1420 | 1442 | ||
| 1421 | eassert ((intptr_t) p % GCALIGNMENT == 0); | 1443 | eassert ((intptr_t) p % GCALIGNMENT == 0); |
| 1422 | return p; | 1444 | return p; |
diff --git a/src/lisp.h b/src/lisp.h index f71394e8784..2221acd5827 100644 --- a/src/lisp.h +++ b/src/lisp.h | |||
| @@ -262,10 +262,6 @@ DEFINE_GDB_SYMBOL_END (USE_LSB_TAG) | |||
| 262 | error !; | 262 | error !; |
| 263 | #endif | 263 | #endif |
| 264 | 264 | ||
| 265 | #ifndef alignas | ||
| 266 | # error "alignas not defined" | ||
| 267 | #endif | ||
| 268 | |||
| 269 | #ifdef HAVE_STRUCT_ATTRIBUTE_ALIGNED | 265 | #ifdef HAVE_STRUCT_ATTRIBUTE_ALIGNED |
| 270 | # define GCALIGNED __attribute__ ((aligned (GCALIGNMENT))) | 266 | # define GCALIGNED __attribute__ ((aligned (GCALIGNMENT))) |
| 271 | #else | 267 | #else |