aboutsummaryrefslogtreecommitdiffstats
path: root/src/alloc.c
diff options
context:
space:
mode:
authorYuuki Harano2021-11-11 00:39:53 +0900
committerYuuki Harano2021-11-11 00:39:53 +0900
commit4dd1f56f29fc598a8339a345c2f8945250600602 (patch)
treeaf341efedffe027e533b1bcc0dbf270532e48285 /src/alloc.c
parent4c49ec7f865bdad1629d2f125f71f4e506b258f2 (diff)
parent810fa21d26453f898de9747ece7205dfe6de9d08 (diff)
downloademacs-4dd1f56f29fc598a8339a345c2f8945250600602.tar.gz
emacs-4dd1f56f29fc598a8339a345c2f8945250600602.zip
Merge branch 'master' of git.savannah.gnu.org:/srv/git/emacs into feature/pgtk
Diffstat (limited to 'src/alloc.c')
-rw-r--r--src/alloc.c46
1 files changed, 27 insertions, 19 deletions
diff --git a/src/alloc.c b/src/alloc.c
index ff3670eeb1d..2d25f8205ae 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -765,7 +765,7 @@ xmalloc (size_t size)
765 val = lmalloc (size, false); 765 val = lmalloc (size, false);
766 MALLOC_UNBLOCK_INPUT; 766 MALLOC_UNBLOCK_INPUT;
767 767
768 if (!val && size) 768 if (!val)
769 memory_full (size); 769 memory_full (size);
770 MALLOC_PROBE (size); 770 MALLOC_PROBE (size);
771 return val; 771 return val;
@@ -782,7 +782,7 @@ xzalloc (size_t size)
782 val = lmalloc (size, true); 782 val = lmalloc (size, true);
783 MALLOC_UNBLOCK_INPUT; 783 MALLOC_UNBLOCK_INPUT;
784 784
785 if (!val && size) 785 if (!val)
786 memory_full (size); 786 memory_full (size);
787 MALLOC_PROBE (size); 787 MALLOC_PROBE (size);
788 return val; 788 return val;
@@ -796,15 +796,15 @@ xrealloc (void *block, size_t size)
796 void *val; 796 void *val;
797 797
798 MALLOC_BLOCK_INPUT; 798 MALLOC_BLOCK_INPUT;
799 /* We must call malloc explicitly when BLOCK is 0, since some 799 /* Call lmalloc when BLOCK is null, for the benefit of long-obsolete
800 reallocs don't do this. */ 800 platforms lacking support for realloc (NULL, size). */
801 if (! block) 801 if (! block)
802 val = lmalloc (size, false); 802 val = lmalloc (size, false);
803 else 803 else
804 val = lrealloc (block, size); 804 val = lrealloc (block, size);
805 MALLOC_UNBLOCK_INPUT; 805 MALLOC_UNBLOCK_INPUT;
806 806
807 if (!val && size) 807 if (!val)
808 memory_full (size); 808 memory_full (size);
809 MALLOC_PROBE (size); 809 MALLOC_PROBE (size);
810 return val; 810 return val;
@@ -1030,7 +1030,7 @@ lisp_malloc (size_t nbytes, bool clearit, enum mem_type type)
1030#endif 1030#endif
1031 1031
1032 MALLOC_UNBLOCK_INPUT; 1032 MALLOC_UNBLOCK_INPUT;
1033 if (!val && nbytes) 1033 if (!val)
1034 memory_full (nbytes); 1034 memory_full (nbytes);
1035 MALLOC_PROBE (nbytes); 1035 MALLOC_PROBE (nbytes);
1036 return val; 1036 return val;
@@ -1329,16 +1329,20 @@ laligned (void *p, size_t size)
1329 || size % LISP_ALIGNMENT != 0); 1329 || size % LISP_ALIGNMENT != 0);
1330} 1330}
1331 1331
1332/* Like malloc and realloc except that if SIZE is Lisp-aligned, make 1332/* Like malloc and realloc except return null only on failure,
1333 sure the result is too, if necessary by reallocating (typically 1333 the result is Lisp-aligned if SIZE is, and lrealloc's pointer
1334 with larger and larger sizes) until the allocator returns a 1334 argument must be nonnull. Code allocating C heap memory
1335 Lisp-aligned pointer. Code that needs to allocate C heap memory
1336 for a Lisp object should use one of these functions to obtain a 1335 for a Lisp object should use one of these functions to obtain a
1337 pointer P; that way, if T is an enum Lisp_Type value and L == 1336 pointer P; that way, if T is an enum Lisp_Type value and L ==
1338 make_lisp_ptr (P, T), then XPNTR (L) == P and XTYPE (L) == T. 1337 make_lisp_ptr (P, T), then XPNTR (L) == P and XTYPE (L) == T.
1339 1338
1339 If CLEARIT, arrange for the allocated memory to be cleared.
1340 This might use calloc, as calloc can be faster than malloc+memset.
1341
1340 On typical modern platforms these functions' loops do not iterate. 1342 On typical modern platforms these functions' loops do not iterate.
1341 On now-rare (and perhaps nonexistent) platforms, the loops in 1343 On now-rare (and perhaps nonexistent) platforms, the code can loop,
1344 reallocating (typically with larger and larger sizes) until the
1345 allocator returns a Lisp-aligned pointer. This loop in
1342 theory could repeat forever. If an infinite loop is possible on a 1346 theory could repeat forever. If an infinite loop is possible on a
1343 platform, a build would surely loop and the builder can then send 1347 platform, a build would surely loop and the builder can then send
1344 us a bug report. Adding a counter to try to detect any such loop 1348 us a bug report. Adding a counter to try to detect any such loop
@@ -1352,8 +1356,13 @@ lmalloc (size_t size, bool clearit)
1352 if (! MALLOC_IS_LISP_ALIGNED && size % LISP_ALIGNMENT == 0) 1356 if (! MALLOC_IS_LISP_ALIGNED && size % LISP_ALIGNMENT == 0)
1353 { 1357 {
1354 void *p = aligned_alloc (LISP_ALIGNMENT, size); 1358 void *p = aligned_alloc (LISP_ALIGNMENT, size);
1355 if (clearit && p) 1359 if (p)
1356 memclear (p, size); 1360 {
1361 if (clearit)
1362 memclear (p, size);
1363 }
1364 else if (! (MALLOC_0_IS_NONNULL || size))
1365 return aligned_alloc (LISP_ALIGNMENT, LISP_ALIGNMENT);
1357 return p; 1366 return p;
1358 } 1367 }
1359#endif 1368#endif
@@ -1361,7 +1370,7 @@ lmalloc (size_t size, bool clearit)
1361 while (true) 1370 while (true)
1362 { 1371 {
1363 void *p = clearit ? calloc (1, size) : malloc (size); 1372 void *p = clearit ? calloc (1, size) : malloc (size);
1364 if (laligned (p, size)) 1373 if (laligned (p, size) && (MALLOC_0_IS_NONNULL || size || p))
1365 return p; 1374 return p;
1366 free (p); 1375 free (p);
1367 size_t bigger = size + LISP_ALIGNMENT; 1376 size_t bigger = size + LISP_ALIGNMENT;
@@ -1376,7 +1385,7 @@ lrealloc (void *p, size_t size)
1376 while (true) 1385 while (true)
1377 { 1386 {
1378 p = realloc (p, size); 1387 p = realloc (p, size);
1379 if (laligned (p, size)) 1388 if (laligned (p, size) && (size || p))
1380 return p; 1389 return p;
1381 size_t bigger = size + LISP_ALIGNMENT; 1390 size_t bigger = size + LISP_ALIGNMENT;
1382 if (size < bigger) 1391 if (size < bigger)
@@ -1929,8 +1938,7 @@ allocate_string_data (struct Lisp_String *s,
1929 The character is at byte offset CIDX_BYTE in the string. 1938 The character is at byte offset CIDX_BYTE in the string.
1930 The character being replaced is CLEN bytes long, 1939 The character being replaced is CLEN bytes long,
1931 and the character that will replace it is NEW_CLEN bytes long. 1940 and the character that will replace it is NEW_CLEN bytes long.
1932 Return the address of where the caller should store the 1941 Return the address where the caller should store the new character. */
1933 the new character. */
1934 1942
1935unsigned char * 1943unsigned char *
1936resize_string_data (Lisp_Object string, ptrdiff_t cidx_byte, 1944resize_string_data (Lisp_Object string, ptrdiff_t cidx_byte,
@@ -7321,7 +7329,7 @@ Frames, windows, buffers, and subprocesses count as vectors
7321 make_int (strings_consed)); 7329 make_int (strings_consed));
7322} 7330}
7323 7331
7324#ifdef GNU_LINUX 7332#if defined GNU_LINUX && defined __GLIBC__
7325DEFUN ("malloc-info", Fmalloc_info, Smalloc_info, 0, 0, "", 7333DEFUN ("malloc-info", Fmalloc_info, Smalloc_info, 0, 0, "",
7326 doc: /* Report malloc information to stderr. 7334 doc: /* Report malloc information to stderr.
7327This function outputs to stderr an XML-formatted 7335This function outputs to stderr an XML-formatted
@@ -7681,7 +7689,7 @@ N should be nonnegative. */);
7681 defsubr (&Sgarbage_collect_maybe); 7689 defsubr (&Sgarbage_collect_maybe);
7682 defsubr (&Smemory_info); 7690 defsubr (&Smemory_info);
7683 defsubr (&Smemory_use_counts); 7691 defsubr (&Smemory_use_counts);
7684#ifdef GNU_LINUX 7692#if defined GNU_LINUX && defined __GLIBC__
7685 defsubr (&Smalloc_info); 7693 defsubr (&Smalloc_info);
7686#endif 7694#endif
7687 defsubr (&Ssuspicious_object); 7695 defsubr (&Ssuspicious_object);