diff options
| author | Vibhav Pant | 2023-06-06 19:30:27 +0530 |
|---|---|---|
| committer | Vibhav Pant | 2023-06-06 19:30:27 +0530 |
| commit | 49ffcbf86a32a8a217538d4df3736fe069ccf35d (patch) | |
| tree | a5f16157cc20fb19a844473a6fbd2b434f4c8260 /src/alloc.c | |
| parent | af569fa3d90a717983b743eb97adbf869c6d1736 (diff) | |
| parent | 7ca1d782f5910d0c3978c6798a45c6854ec668c7 (diff) | |
| download | emacs-49ffcbf86a32a8a217538d4df3736fe069ccf35d.tar.gz emacs-49ffcbf86a32a8a217538d4df3736fe069ccf35d.zip | |
Merge branch 'master' into scratch/comp-static-data
Diffstat (limited to 'src/alloc.c')
| -rw-r--r-- | src/alloc.c | 27 |
1 files changed, 9 insertions, 18 deletions
diff --git a/src/alloc.c b/src/alloc.c index 9969ace5fef..773bc03fffa 100644 --- a/src/alloc.c +++ b/src/alloc.c | |||
| @@ -400,7 +400,7 @@ static ptrdiff_t pure_bytes_used_non_lisp; | |||
| 400 | 400 | ||
| 401 | /* If positive, garbage collection is inhibited. Otherwise, zero. */ | 401 | /* If positive, garbage collection is inhibited. Otherwise, zero. */ |
| 402 | 402 | ||
| 403 | static intptr_t garbage_collection_inhibited; | 403 | intptr_t garbage_collection_inhibited; |
| 404 | 404 | ||
| 405 | /* The GC threshold in bytes, the last time it was calculated | 405 | /* The GC threshold in bytes, the last time it was calculated |
| 406 | from gc-cons-threshold and gc-cons-percentage. */ | 406 | from gc-cons-threshold and gc-cons-percentage. */ |
| @@ -865,7 +865,7 @@ xnmalloc (ptrdiff_t nitems, ptrdiff_t item_size) | |||
| 865 | { | 865 | { |
| 866 | eassert (0 <= nitems && 0 < item_size); | 866 | eassert (0 <= nitems && 0 < item_size); |
| 867 | ptrdiff_t nbytes; | 867 | ptrdiff_t nbytes; |
| 868 | if (INT_MULTIPLY_WRAPV (nitems, item_size, &nbytes) || SIZE_MAX < nbytes) | 868 | if (ckd_mul (&nbytes, nitems, item_size) || SIZE_MAX < nbytes) |
| 869 | memory_full (SIZE_MAX); | 869 | memory_full (SIZE_MAX); |
| 870 | return xmalloc (nbytes); | 870 | return xmalloc (nbytes); |
| 871 | } | 871 | } |
| @@ -879,7 +879,7 @@ xnrealloc (void *pa, ptrdiff_t nitems, ptrdiff_t item_size) | |||
| 879 | { | 879 | { |
| 880 | eassert (0 <= nitems && 0 < item_size); | 880 | eassert (0 <= nitems && 0 < item_size); |
| 881 | ptrdiff_t nbytes; | 881 | ptrdiff_t nbytes; |
| 882 | if (INT_MULTIPLY_WRAPV (nitems, item_size, &nbytes) || SIZE_MAX < nbytes) | 882 | if (ckd_mul (&nbytes, nitems, item_size) || SIZE_MAX < nbytes) |
| 883 | memory_full (SIZE_MAX); | 883 | memory_full (SIZE_MAX); |
| 884 | return xrealloc (pa, nbytes); | 884 | return xrealloc (pa, nbytes); |
| 885 | } | 885 | } |
| @@ -926,13 +926,13 @@ xpalloc (void *pa, ptrdiff_t *nitems, ptrdiff_t nitems_incr_min, | |||
| 926 | NITEMS_MAX, and what the C language can represent safely. */ | 926 | NITEMS_MAX, and what the C language can represent safely. */ |
| 927 | 927 | ||
| 928 | ptrdiff_t n, nbytes; | 928 | ptrdiff_t n, nbytes; |
| 929 | if (INT_ADD_WRAPV (n0, n0 >> 1, &n)) | 929 | if (ckd_add (&n, n0, n0 >> 1)) |
| 930 | n = PTRDIFF_MAX; | 930 | n = PTRDIFF_MAX; |
| 931 | if (0 <= nitems_max && nitems_max < n) | 931 | if (0 <= nitems_max && nitems_max < n) |
| 932 | n = nitems_max; | 932 | n = nitems_max; |
| 933 | 933 | ||
| 934 | ptrdiff_t adjusted_nbytes | 934 | ptrdiff_t adjusted_nbytes |
| 935 | = ((INT_MULTIPLY_WRAPV (n, item_size, &nbytes) || SIZE_MAX < nbytes) | 935 | = ((ckd_mul (&nbytes, n, item_size) || SIZE_MAX < nbytes) |
| 936 | ? min (PTRDIFF_MAX, SIZE_MAX) | 936 | ? min (PTRDIFF_MAX, SIZE_MAX) |
| 937 | : nbytes < DEFAULT_MXFAST ? DEFAULT_MXFAST : 0); | 937 | : nbytes < DEFAULT_MXFAST ? DEFAULT_MXFAST : 0); |
| 938 | if (adjusted_nbytes) | 938 | if (adjusted_nbytes) |
| @@ -944,9 +944,9 @@ xpalloc (void *pa, ptrdiff_t *nitems, ptrdiff_t nitems_incr_min, | |||
| 944 | if (! pa) | 944 | if (! pa) |
| 945 | *nitems = 0; | 945 | *nitems = 0; |
| 946 | if (n - n0 < nitems_incr_min | 946 | if (n - n0 < nitems_incr_min |
| 947 | && (INT_ADD_WRAPV (n0, nitems_incr_min, &n) | 947 | && (ckd_add (&n, n0, nitems_incr_min) |
| 948 | || (0 <= nitems_max && nitems_max < n) | 948 | || (0 <= nitems_max && nitems_max < n) |
| 949 | || INT_MULTIPLY_WRAPV (n, item_size, &nbytes))) | 949 | || ckd_mul (&nbytes, n, item_size))) |
| 950 | memory_full (SIZE_MAX); | 950 | memory_full (SIZE_MAX); |
| 951 | pa = xrealloc (pa, nbytes); | 951 | pa = xrealloc (pa, nbytes); |
| 952 | *nitems = n; | 952 | *nitems = n; |
| @@ -2381,7 +2381,7 @@ a multibyte string even if INIT is an ASCII character. */) | |||
| 2381 | ptrdiff_t len = CHAR_STRING (c, str); | 2381 | ptrdiff_t len = CHAR_STRING (c, str); |
| 2382 | EMACS_INT string_len = XFIXNUM (length); | 2382 | EMACS_INT string_len = XFIXNUM (length); |
| 2383 | 2383 | ||
| 2384 | if (INT_MULTIPLY_WRAPV (len, string_len, &nbytes)) | 2384 | if (ckd_mul (&nbytes, len, string_len)) |
| 2385 | string_overflow (); | 2385 | string_overflow (); |
| 2386 | val = make_clear_multibyte_string (string_len, nbytes, clearit); | 2386 | val = make_clear_multibyte_string (string_len, nbytes, clearit); |
| 2387 | if (!clearit) | 2387 | if (!clearit) |
| @@ -5312,7 +5312,7 @@ mark_memory (void const *start, void const *end) | |||
| 5312 | a Lisp_Object might be split into registers saved into | 5312 | a Lisp_Object might be split into registers saved into |
| 5313 | non-adjacent words and P might be the low-order word's value. */ | 5313 | non-adjacent words and P might be the low-order word's value. */ |
| 5314 | intptr_t ip; | 5314 | intptr_t ip; |
| 5315 | INT_ADD_WRAPV ((intptr_t) p, (intptr_t) lispsym, &ip); | 5315 | ckd_add (&ip, (intptr_t) p, (intptr_t) lispsym); |
| 5316 | mark_maybe_pointer ((void *) ip, true); | 5316 | mark_maybe_pointer ((void *) ip, true); |
| 5317 | } | 5317 | } |
| 5318 | } | 5318 | } |
| @@ -5424,15 +5424,6 @@ typedef union | |||
| 5424 | #endif | 5424 | #endif |
| 5425 | } stacktop_sentry; | 5425 | } stacktop_sentry; |
| 5426 | 5426 | ||
| 5427 | /* Yield an address close enough to the top of the stack that the | ||
| 5428 | garbage collector need not scan above it. Callers should be | ||
| 5429 | declared NO_INLINE. */ | ||
| 5430 | #ifdef HAVE___BUILTIN_FRAME_ADDRESS | ||
| 5431 | # define NEAR_STACK_TOP(addr) ((void) (addr), __builtin_frame_address (0)) | ||
| 5432 | #else | ||
| 5433 | # define NEAR_STACK_TOP(addr) (addr) | ||
| 5434 | #endif | ||
| 5435 | |||
| 5436 | /* Set *P to the address of the top of the stack. This must be a | 5427 | /* Set *P to the address of the top of the stack. This must be a |
| 5437 | macro, not a function, so that it is executed in the caller's | 5428 | macro, not a function, so that it is executed in the caller's |
| 5438 | environment. It is not inside a do-while so that its storage | 5429 | environment. It is not inside a do-while so that its storage |