diff options
Diffstat (limited to 'src/alloc.c')
| -rw-r--r-- | src/alloc.c | 32 |
1 files changed, 13 insertions, 19 deletions
diff --git a/src/alloc.c b/src/alloc.c index 602282e5704..89fe96a2349 100644 --- a/src/alloc.c +++ b/src/alloc.c | |||
| @@ -655,26 +655,20 @@ buffer_memory_full (ptrdiff_t nbytes) | |||
| 655 | #define COMMON_MULTIPLE(a, b) \ | 655 | #define COMMON_MULTIPLE(a, b) \ |
| 656 | ((a) % (b) == 0 ? (a) : (b) % (a) == 0 ? (b) : (a) * (b)) | 656 | ((a) % (b) == 0 ? (a) : (b) % (a) == 0 ? (b) : (a) * (b)) |
| 657 | 657 | ||
| 658 | /* A lower bound on the alignment of malloc. For better performance | 658 | /* A lower bound on the alignment of malloc. Although this bound is |
| 659 | this bound should be tighter. For glibc 2.26 and later a tighter | 659 | incorrect for some buggy malloc implementations (e.g., MinGW circa |
| 660 | bound is known. */ | 660 | 2020), the bugs should not matter for the way this bound is used |
| 661 | #if 2 < __GLIBC__ + (26 <= __GLIBC_MINOR__) | 661 | since the correct bound is also a multiple of LISP_ALIGNMENT on the |
| 662 | enum { MALLOC_ALIGNMENT_BOUND = MALLOC_ALIGNMENT }; | 662 | buggy platforms. */ |
| 663 | #else | 663 | enum { MALLOC_ALIGNMENT_BOUND = alignof (max_align_t) }; |
| 664 | /* A bound known to work for all Emacs porting targets. Tightening | 664 | |
| 665 | this looser bound by using max_align_t instead of long long int | 665 | /* A lower bound on the alignment of Lisp objects allocated on the heap. |
| 666 | would break buggy malloc implementations like MinGW circa 2020. */ | 666 | All such objects must have an address that is a multiple of LISP_ALIGNMENT; |
| 667 | enum { MALLOC_ALIGNMENT_BOUND = alignof (long long int) }; | ||
| 668 | #endif | ||
| 669 | |||
| 670 | /* A lower bound on the alignment of Lisp objects. All Lisp objects | ||
| 671 | must have an address that is a multiple of LISP_ALIGNMENT; | ||
| 672 | otherwise maybe_lisp_pointer can issue false negatives, causing crashes. | 667 | otherwise maybe_lisp_pointer can issue false negatives, causing crashes. |
| 673 | It's good to make this bound tight: if Lisp objects are always | 668 | On all practical Emacs targets, sizeof (struct Lisp_Float) == 8 and |
| 674 | aligned more strictly than LISP_ALIGNMENT, maybe_lisp_pointer will | 669 | since GCALIGNMENT also equals 8 there's little point to optimizing |
| 675 | issue more false positives, hurting performance. */ | 670 | for impractical targets. */ |
| 676 | enum { LISP_ALIGNMENT = max (max (GCALIGNMENT, MALLOC_ALIGNMENT_BOUND), | 671 | enum { LISP_ALIGNMENT = GCALIGNMENT }; |
| 677 | alignof (union emacs_align_type)) }; | ||
| 678 | 672 | ||
| 679 | /* True if malloc (N) is known to return storage suitably aligned for | 673 | /* True if malloc (N) is known to return storage suitably aligned for |
| 680 | Lisp objects whenever N is a multiple of LISP_ALIGNMENT. */ | 674 | Lisp objects whenever N is a multiple of LISP_ALIGNMENT. */ |