aboutsummaryrefslogtreecommitdiffstats
path: root/src/alloc.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/alloc.c')
-rw-r--r--src/alloc.c95
1 files changed, 48 insertions, 47 deletions
diff --git a/src/alloc.c b/src/alloc.c
index ad1741e308f..6bcb216bb5e 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -229,11 +229,11 @@ static ptrdiff_t pure_bytes_used_before_overflow;
229 229
230/* Index in pure at which next pure Lisp object will be allocated.. */ 230/* Index in pure at which next pure Lisp object will be allocated.. */
231 231
232static EMACS_INT pure_bytes_used_lisp; 232static ptrdiff_t pure_bytes_used_lisp;
233 233
234/* Number of bytes allocated for non-Lisp objects in pure storage. */ 234/* Number of bytes allocated for non-Lisp objects in pure storage. */
235 235
236static EMACS_INT pure_bytes_used_non_lisp; 236static ptrdiff_t pure_bytes_used_non_lisp;
237 237
238/* If nonzero, this is a warning delivered by malloc and not yet 238/* If nonzero, this is a warning delivered by malloc and not yet
239 displayed. */ 239 displayed. */
@@ -382,7 +382,7 @@ static void *min_heap_address, *max_heap_address;
382static struct mem_node mem_z; 382static struct mem_node mem_z;
383#define MEM_NIL &mem_z 383#define MEM_NIL &mem_z
384 384
385static struct Lisp_Vector *allocate_vectorlike (EMACS_INT); 385static struct Lisp_Vector *allocate_vectorlike (ptrdiff_t);
386static void lisp_free (POINTER_TYPE *); 386static void lisp_free (POINTER_TYPE *);
387static void mark_stack (void); 387static void mark_stack (void);
388static int live_vector_p (struct mem_node *, void *); 388static int live_vector_p (struct mem_node *, void *);
@@ -464,7 +464,7 @@ display_malloc_warning (void)
464/* Called if we can't allocate relocatable space for a buffer. */ 464/* Called if we can't allocate relocatable space for a buffer. */
465 465
466void 466void
467buffer_memory_full (EMACS_INT nbytes) 467buffer_memory_full (ptrdiff_t nbytes)
468{ 468{
469 /* If buffers use the relocating allocator, no need to free 469 /* If buffers use the relocating allocator, no need to free
470 spare_memory, because we may have plenty of malloc space left 470 spare_memory, because we may have plenty of malloc space left
@@ -1608,7 +1608,7 @@ struct sdata
1608 1608
1609#ifdef GC_CHECK_STRING_BYTES 1609#ifdef GC_CHECK_STRING_BYTES
1610 1610
1611 EMACS_INT nbytes; 1611 ptrdiff_t nbytes;
1612 unsigned char data[1]; 1612 unsigned char data[1];
1613 1613
1614#define SDATA_NBYTES(S) (S)->nbytes 1614#define SDATA_NBYTES(S) (S)->nbytes
@@ -1623,7 +1623,7 @@ struct sdata
1623 unsigned char data[1]; 1623 unsigned char data[1];
1624 1624
1625 /* When STRING is null. */ 1625 /* When STRING is null. */
1626 EMACS_INT nbytes; 1626 ptrdiff_t nbytes;
1627 } u; 1627 } u;
1628 1628
1629#define SDATA_NBYTES(S) (S)->u.nbytes 1629#define SDATA_NBYTES(S) (S)->u.nbytes
@@ -1733,24 +1733,24 @@ static char const string_overrun_cookie[GC_STRING_OVERRUN_COOKIE_SIZE] =
1733#define SDATA_SIZE(NBYTES) \ 1733#define SDATA_SIZE(NBYTES) \
1734 ((SDATA_DATA_OFFSET \ 1734 ((SDATA_DATA_OFFSET \
1735 + (NBYTES) + 1 \ 1735 + (NBYTES) + 1 \
1736 + sizeof (EMACS_INT) - 1) \ 1736 + sizeof (ptrdiff_t) - 1) \
1737 & ~(sizeof (EMACS_INT) - 1)) 1737 & ~(sizeof (ptrdiff_t) - 1))
1738 1738
1739#else /* not GC_CHECK_STRING_BYTES */ 1739#else /* not GC_CHECK_STRING_BYTES */
1740 1740
1741/* The 'max' reserves space for the nbytes union member even when NBYTES + 1 is 1741/* The 'max' reserves space for the nbytes union member even when NBYTES + 1 is
1742 less than the size of that member. The 'max' is not needed when 1742 less than the size of that member. The 'max' is not needed when
1743 SDATA_DATA_OFFSET is a multiple of sizeof (EMACS_INT), because then the 1743 SDATA_DATA_OFFSET is a multiple of sizeof (ptrdiff_t), because then the
1744 alignment code reserves enough space. */ 1744 alignment code reserves enough space. */
1745 1745
1746#define SDATA_SIZE(NBYTES) \ 1746#define SDATA_SIZE(NBYTES) \
1747 ((SDATA_DATA_OFFSET \ 1747 ((SDATA_DATA_OFFSET \
1748 + (SDATA_DATA_OFFSET % sizeof (EMACS_INT) == 0 \ 1748 + (SDATA_DATA_OFFSET % sizeof (ptrdiff_t) == 0 \
1749 ? NBYTES \ 1749 ? NBYTES \
1750 : max (NBYTES, sizeof (EMACS_INT) - 1)) \ 1750 : max (NBYTES, sizeof (ptrdiff_t) - 1)) \
1751 + 1 \ 1751 + 1 \
1752 + sizeof (EMACS_INT) - 1) \ 1752 + sizeof (ptrdiff_t) - 1) \
1753 & ~(sizeof (EMACS_INT) - 1)) 1753 & ~(sizeof (ptrdiff_t) - 1))
1754 1754
1755#endif /* not GC_CHECK_STRING_BYTES */ 1755#endif /* not GC_CHECK_STRING_BYTES */
1756 1756
@@ -1794,10 +1794,10 @@ static int check_string_bytes_count;
1794 1794
1795/* Like GC_STRING_BYTES, but with debugging check. */ 1795/* Like GC_STRING_BYTES, but with debugging check. */
1796 1796
1797EMACS_INT 1797ptrdiff_t
1798string_bytes (struct Lisp_String *s) 1798string_bytes (struct Lisp_String *s)
1799{ 1799{
1800 EMACS_INT nbytes = 1800 ptrdiff_t nbytes =
1801 (s->size_byte < 0 ? s->size & ~ARRAY_MARK_FLAG : s->size_byte); 1801 (s->size_byte < 0 ? s->size & ~ARRAY_MARK_FLAG : s->size_byte);
1802 1802
1803 if (!PURE_POINTER_P (s) 1803 if (!PURE_POINTER_P (s)
@@ -1820,7 +1820,7 @@ check_sblock (struct sblock *b)
1820 { 1820 {
1821 /* Compute the next FROM here because copying below may 1821 /* Compute the next FROM here because copying below may
1822 overwrite data we need to compute it. */ 1822 overwrite data we need to compute it. */
1823 EMACS_INT nbytes; 1823 ptrdiff_t nbytes;
1824 1824
1825 /* Check that the string size recorded in the string is the 1825 /* Check that the string size recorded in the string is the
1826 same as the one recorded in the sdata structure. */ 1826 same as the one recorded in the sdata structure. */
@@ -1966,7 +1966,7 @@ allocate_string_data (struct Lisp_String *s,
1966{ 1966{
1967 struct sdata *data, *old_data; 1967 struct sdata *data, *old_data;
1968 struct sblock *b; 1968 struct sblock *b;
1969 EMACS_INT needed, old_nbytes; 1969 ptrdiff_t needed, old_nbytes;
1970 1970
1971 if (STRING_BYTES_MAX < nbytes) 1971 if (STRING_BYTES_MAX < nbytes)
1972 string_overflow (); 1972 string_overflow ();
@@ -2211,7 +2211,7 @@ compact_small_strings (void)
2211 { 2211 {
2212 /* Compute the next FROM here because copying below may 2212 /* Compute the next FROM here because copying below may
2213 overwrite data we need to compute it. */ 2213 overwrite data we need to compute it. */
2214 EMACS_INT nbytes; 2214 ptrdiff_t nbytes;
2215 2215
2216#ifdef GC_CHECK_STRING_BYTES 2216#ifdef GC_CHECK_STRING_BYTES
2217 /* Check that the string size recorded in the string is the 2217 /* Check that the string size recorded in the string is the
@@ -2341,7 +2341,8 @@ LENGTH must be a number. INIT matters only in whether it is t or nil. */)
2341{ 2341{
2342 register Lisp_Object val; 2342 register Lisp_Object val;
2343 struct Lisp_Bool_Vector *p; 2343 struct Lisp_Bool_Vector *p;
2344 EMACS_INT length_in_chars, length_in_elts; 2344 ptrdiff_t length_in_chars;
2345 EMACS_INT length_in_elts;
2345 int bits_per_value; 2346 int bits_per_value;
2346 2347
2347 CHECK_NATNUM (length); 2348 CHECK_NATNUM (length);
@@ -2349,8 +2350,6 @@ LENGTH must be a number. INIT matters only in whether it is t or nil. */)
2349 bits_per_value = sizeof (EMACS_INT) * BOOL_VECTOR_BITS_PER_CHAR; 2350 bits_per_value = sizeof (EMACS_INT) * BOOL_VECTOR_BITS_PER_CHAR;
2350 2351
2351 length_in_elts = (XFASTINT (length) + bits_per_value - 1) / bits_per_value; 2352 length_in_elts = (XFASTINT (length) + bits_per_value - 1) / bits_per_value;
2352 length_in_chars = ((XFASTINT (length) + BOOL_VECTOR_BITS_PER_CHAR - 1)
2353 / BOOL_VECTOR_BITS_PER_CHAR);
2354 2353
2355 /* We must allocate one more elements than LENGTH_IN_ELTS for the 2354 /* We must allocate one more elements than LENGTH_IN_ELTS for the
2356 slot `size' of the struct Lisp_Bool_Vector. */ 2355 slot `size' of the struct Lisp_Bool_Vector. */
@@ -2362,6 +2361,8 @@ LENGTH must be a number. INIT matters only in whether it is t or nil. */)
2362 p = XBOOL_VECTOR (val); 2361 p = XBOOL_VECTOR (val);
2363 p->size = XFASTINT (length); 2362 p->size = XFASTINT (length);
2364 2363
2364 length_in_chars = ((XFASTINT (length) + BOOL_VECTOR_BITS_PER_CHAR - 1)
2365 / BOOL_VECTOR_BITS_PER_CHAR);
2365 if (length_in_chars) 2366 if (length_in_chars)
2366 { 2367 {
2367 memset (p->data, ! NILP (init) ? -1 : 0, length_in_chars); 2368 memset (p->data, ! NILP (init) ? -1 : 0, length_in_chars);
@@ -2380,10 +2381,10 @@ LENGTH must be a number. INIT matters only in whether it is t or nil. */)
2380 multibyte, depending on the contents. */ 2381 multibyte, depending on the contents. */
2381 2382
2382Lisp_Object 2383Lisp_Object
2383make_string (const char *contents, EMACS_INT nbytes) 2384make_string (const char *contents, ptrdiff_t nbytes)
2384{ 2385{
2385 register Lisp_Object val; 2386 register Lisp_Object val;
2386 EMACS_INT nchars, multibyte_nbytes; 2387 ptrdiff_t nchars, multibyte_nbytes;
2387 2388
2388 parse_str_as_multibyte ((const unsigned char *) contents, nbytes, 2389 parse_str_as_multibyte ((const unsigned char *) contents, nbytes,
2389 &nchars, &multibyte_nbytes); 2390 &nchars, &multibyte_nbytes);
@@ -2400,7 +2401,7 @@ make_string (const char *contents, EMACS_INT nbytes)
2400/* Make an unibyte string from LENGTH bytes at CONTENTS. */ 2401/* Make an unibyte string from LENGTH bytes at CONTENTS. */
2401 2402
2402Lisp_Object 2403Lisp_Object
2403make_unibyte_string (const char *contents, EMACS_INT length) 2404make_unibyte_string (const char *contents, ptrdiff_t length)
2404{ 2405{
2405 register Lisp_Object val; 2406 register Lisp_Object val;
2406 val = make_uninit_string (length); 2407 val = make_uninit_string (length);
@@ -2414,7 +2415,7 @@ make_unibyte_string (const char *contents, EMACS_INT length)
2414 2415
2415Lisp_Object 2416Lisp_Object
2416make_multibyte_string (const char *contents, 2417make_multibyte_string (const char *contents,
2417 EMACS_INT nchars, EMACS_INT nbytes) 2418 ptrdiff_t nchars, ptrdiff_t nbytes)
2418{ 2419{
2419 register Lisp_Object val; 2420 register Lisp_Object val;
2420 val = make_uninit_multibyte_string (nchars, nbytes); 2421 val = make_uninit_multibyte_string (nchars, nbytes);
@@ -2428,7 +2429,7 @@ make_multibyte_string (const char *contents,
2428 2429
2429Lisp_Object 2430Lisp_Object
2430make_string_from_bytes (const char *contents, 2431make_string_from_bytes (const char *contents,
2431 EMACS_INT nchars, EMACS_INT nbytes) 2432 ptrdiff_t nchars, ptrdiff_t nbytes)
2432{ 2433{
2433 register Lisp_Object val; 2434 register Lisp_Object val;
2434 val = make_uninit_multibyte_string (nchars, nbytes); 2435 val = make_uninit_multibyte_string (nchars, nbytes);
@@ -2446,7 +2447,7 @@ make_string_from_bytes (const char *contents,
2446 2447
2447Lisp_Object 2448Lisp_Object
2448make_specified_string (const char *contents, 2449make_specified_string (const char *contents,
2449 EMACS_INT nchars, EMACS_INT nbytes, int multibyte) 2450 ptrdiff_t nchars, ptrdiff_t nbytes, int multibyte)
2450{ 2451{
2451 register Lisp_Object val; 2452 register Lisp_Object val;
2452 2453
@@ -2885,7 +2886,7 @@ enum
2885 with room for LEN Lisp_Objects. */ 2886 with room for LEN Lisp_Objects. */
2886 2887
2887static struct Lisp_Vector * 2888static struct Lisp_Vector *
2888allocate_vectorlike (EMACS_INT len) 2889allocate_vectorlike (ptrdiff_t len)
2889{ 2890{
2890 struct Lisp_Vector *p; 2891 struct Lisp_Vector *p;
2891 size_t nbytes; 2892 size_t nbytes;
@@ -2941,7 +2942,7 @@ allocate_vector (EMACS_INT len)
2941/* Allocate other vector-like structures. */ 2942/* Allocate other vector-like structures. */
2942 2943
2943struct Lisp_Vector * 2944struct Lisp_Vector *
2944allocate_pseudovector (int memlen, int lisplen, EMACS_INT tag) 2945allocate_pseudovector (int memlen, int lisplen, int tag)
2945{ 2946{
2946 struct Lisp_Vector *v = allocate_vectorlike (memlen); 2947 struct Lisp_Vector *v = allocate_vectorlike (memlen);
2947 int i; 2948 int i;
@@ -3005,14 +3006,14 @@ See also the function `vector'. */)
3005 (register Lisp_Object length, Lisp_Object init) 3006 (register Lisp_Object length, Lisp_Object init)
3006{ 3007{
3007 Lisp_Object vector; 3008 Lisp_Object vector;
3008 register EMACS_INT sizei; 3009 register ptrdiff_t sizei;
3009 register EMACS_INT i; 3010 register ptrdiff_t i;
3010 register struct Lisp_Vector *p; 3011 register struct Lisp_Vector *p;
3011 3012
3012 CHECK_NATNUM (length); 3013 CHECK_NATNUM (length);
3013 sizei = XFASTINT (length);
3014 3014
3015 p = allocate_vector (sizei); 3015 p = allocate_vector (XFASTINT (length));
3016 sizei = XFASTINT (length);
3016 for (i = 0; i < sizei; i++) 3017 for (i = 0; i < sizei; i++)
3017 p->contents[i] = init; 3018 p->contents[i] = init;
3018 3019
@@ -4696,14 +4697,14 @@ check_pure_size (void)
4696 address. Return NULL if not found. */ 4697 address. Return NULL if not found. */
4697 4698
4698static char * 4699static char *
4699find_string_data_in_pure (const char *data, EMACS_INT nbytes) 4700find_string_data_in_pure (const char *data, ptrdiff_t nbytes)
4700{ 4701{
4701 int i; 4702 int i;
4702 EMACS_INT skip, bm_skip[256], last_char_skip, infinity, start, start_max; 4703 ptrdiff_t skip, bm_skip[256], last_char_skip, infinity, start, start_max;
4703 const unsigned char *p; 4704 const unsigned char *p;
4704 char *non_lisp_beg; 4705 char *non_lisp_beg;
4705 4706
4706 if (pure_bytes_used_non_lisp < nbytes + 1) 4707 if (pure_bytes_used_non_lisp <= nbytes)
4707 return NULL; 4708 return NULL;
4708 4709
4709 /* Set up the Boyer-Moore table. */ 4710 /* Set up the Boyer-Moore table. */
@@ -4767,7 +4768,7 @@ find_string_data_in_pure (const char *data, EMACS_INT nbytes)
4767 4768
4768Lisp_Object 4769Lisp_Object
4769make_pure_string (const char *data, 4770make_pure_string (const char *data,
4770 EMACS_INT nchars, EMACS_INT nbytes, int multibyte) 4771 ptrdiff_t nchars, ptrdiff_t nbytes, int multibyte)
4771{ 4772{
4772 Lisp_Object string; 4773 Lisp_Object string;
4773 struct Lisp_String *s; 4774 struct Lisp_String *s;
@@ -4795,7 +4796,7 @@ make_pure_c_string (const char *data)
4795{ 4796{
4796 Lisp_Object string; 4797 Lisp_Object string;
4797 struct Lisp_String *s; 4798 struct Lisp_String *s;
4798 EMACS_INT nchars = strlen (data); 4799 ptrdiff_t nchars = strlen (data);
4799 4800
4800 s = (struct Lisp_String *) pure_alloc (sizeof *s, Lisp_String); 4801 s = (struct Lisp_String *) pure_alloc (sizeof *s, Lisp_String);
4801 s->size = nchars; 4802 s->size = nchars;
@@ -4842,7 +4843,7 @@ make_pure_float (double num)
4842 pure space. */ 4843 pure space. */
4843 4844
4844Lisp_Object 4845Lisp_Object
4845make_pure_vector (EMACS_INT len) 4846make_pure_vector (ptrdiff_t len)
4846{ 4847{
4847 Lisp_Object new; 4848 Lisp_Object new;
4848 struct Lisp_Vector *p; 4849 struct Lisp_Vector *p;
@@ -4886,8 +4887,8 @@ Does not copy symbols. Copies strings without text properties. */)
4886 else if (COMPILEDP (obj) || VECTORP (obj)) 4887 else if (COMPILEDP (obj) || VECTORP (obj))
4887 { 4888 {
4888 register struct Lisp_Vector *vec; 4889 register struct Lisp_Vector *vec;
4889 register EMACS_INT i; 4890 register ptrdiff_t i;
4890 EMACS_INT size; 4891 ptrdiff_t size;
4891 4892
4892 size = ASIZE (obj); 4893 size = ASIZE (obj);
4893 if (size & PSEUDOVECTOR_FLAG) 4894 if (size & PSEUDOVECTOR_FLAG)
@@ -4939,10 +4940,10 @@ staticpro (Lisp_Object *varaddress)
4939 4940
4940/* Temporarily prevent garbage collection. */ 4941/* Temporarily prevent garbage collection. */
4941 4942
4942int 4943ptrdiff_t
4943inhibit_garbage_collection (void) 4944inhibit_garbage_collection (void)
4944{ 4945{
4945 int count = SPECPDL_INDEX (); 4946 ptrdiff_t count = SPECPDL_INDEX ();
4946 4947
4947 specbind (Qgc_cons_threshold, make_number (MOST_POSITIVE_FIXNUM)); 4948 specbind (Qgc_cons_threshold, make_number (MOST_POSITIVE_FIXNUM));
4948 return count; 4949 return count;
@@ -4967,7 +4968,7 @@ returns nil, because real GC can't be done. */)
4967 ptrdiff_t i; 4968 ptrdiff_t i;
4968 int message_p; 4969 int message_p;
4969 Lisp_Object total[8]; 4970 Lisp_Object total[8];
4970 int count = SPECPDL_INDEX (); 4971 ptrdiff_t count = SPECPDL_INDEX ();
4971 EMACS_TIME t1, t2, t3; 4972 EMACS_TIME t1, t2, t3;
4972 4973
4973 if (abort_on_gc) 4974 if (abort_on_gc)
@@ -5262,7 +5263,7 @@ returns nil, because real GC can't be done. */)
5262 5263
5263 if (!NILP (Vpost_gc_hook)) 5264 if (!NILP (Vpost_gc_hook))
5264 { 5265 {
5265 int gc_count = inhibit_garbage_collection (); 5266 ptrdiff_t gc_count = inhibit_garbage_collection ();
5266 safe_run_hooks (Qpost_gc_hook); 5267 safe_run_hooks (Qpost_gc_hook);
5267 unbind_to (gc_count, Qnil); 5268 unbind_to (gc_count, Qnil);
5268 } 5269 }
@@ -5347,8 +5348,8 @@ ptrdiff_t mark_object_loop_halt EXTERNALLY_VISIBLE;
5347static void 5348static void
5348mark_vectorlike (struct Lisp_Vector *ptr) 5349mark_vectorlike (struct Lisp_Vector *ptr)
5349{ 5350{
5350 EMACS_INT size = ptr->header.size; 5351 ptrdiff_t size = ptr->header.size;
5351 EMACS_INT i; 5352 ptrdiff_t i;
5352 5353
5353 eassert (!VECTOR_MARKED_P (ptr)); 5354 eassert (!VECTOR_MARKED_P (ptr));
5354 VECTOR_MARK (ptr); /* Else mark it */ 5355 VECTOR_MARK (ptr); /* Else mark it */