aboutsummaryrefslogtreecommitdiffstats
path: root/src/alloc.c
diff options
context:
space:
mode:
authorJoakim Verona2012-05-30 14:08:12 +0200
committerJoakim Verona2012-05-30 14:08:12 +0200
commit70700d8c47a35b19e29607ac5f0ed322bdd78249 (patch)
tree4fa00d3fac00025354f0b6e23dcda1b58689a094 /src/alloc.c
parent44fce8ffe7198991c41c985ff4e67ec7d407907e (diff)
parent72cb32cf2f0938dd7dc733eed77b1ed1e497b053 (diff)
downloademacs-70700d8c47a35b19e29607ac5f0ed322bdd78249.tar.gz
emacs-70700d8c47a35b19e29607ac5f0ed322bdd78249.zip
upstream
Diffstat (limited to 'src/alloc.c')
-rw-r--r--src/alloc.c100
1 files changed, 51 insertions, 49 deletions
diff --git a/src/alloc.c b/src/alloc.c
index 1f422a6d3b0..cf7778c05f6 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -234,11 +234,11 @@ static ptrdiff_t pure_bytes_used_before_overflow;
234 234
235/* Index in pure at which next pure Lisp object will be allocated.. */ 235/* Index in pure at which next pure Lisp object will be allocated.. */
236 236
237static EMACS_INT pure_bytes_used_lisp; 237static ptrdiff_t pure_bytes_used_lisp;
238 238
239/* Number of bytes allocated for non-Lisp objects in pure storage. */ 239/* Number of bytes allocated for non-Lisp objects in pure storage. */
240 240
241static EMACS_INT pure_bytes_used_non_lisp; 241static ptrdiff_t pure_bytes_used_non_lisp;
242 242
243/* If nonzero, this is a warning delivered by malloc and not yet 243/* If nonzero, this is a warning delivered by malloc and not yet
244 displayed. */ 244 displayed. */
@@ -273,6 +273,7 @@ static Lisp_Object Qpost_gc_hook;
273static void mark_buffer (Lisp_Object); 273static void mark_buffer (Lisp_Object);
274static void mark_terminals (void); 274static void mark_terminals (void);
275static void gc_sweep (void); 275static void gc_sweep (void);
276static Lisp_Object make_pure_vector (ptrdiff_t);
276static void mark_glyph_matrix (struct glyph_matrix *); 277static void mark_glyph_matrix (struct glyph_matrix *);
277static void mark_face_cache (struct face_cache *); 278static void mark_face_cache (struct face_cache *);
278 279
@@ -387,7 +388,7 @@ static void *min_heap_address, *max_heap_address;
387static struct mem_node mem_z; 388static struct mem_node mem_z;
388#define MEM_NIL &mem_z 389#define MEM_NIL &mem_z
389 390
390static struct Lisp_Vector *allocate_vectorlike (EMACS_INT); 391static struct Lisp_Vector *allocate_vectorlike (ptrdiff_t);
391static void lisp_free (void *); 392static void lisp_free (void *);
392static void mark_stack (void); 393static void mark_stack (void);
393static int live_vector_p (struct mem_node *, void *); 394static int live_vector_p (struct mem_node *, void *);
@@ -475,7 +476,7 @@ display_malloc_warning (void)
475/* Called if we can't allocate relocatable space for a buffer. */ 476/* Called if we can't allocate relocatable space for a buffer. */
476 477
477void 478void
478buffer_memory_full (EMACS_INT nbytes) 479buffer_memory_full (ptrdiff_t nbytes)
479{ 480{
480 /* If buffers use the relocating allocator, no need to free 481 /* If buffers use the relocating allocator, no need to free
481 spare_memory, because we may have plenty of malloc space left 482 spare_memory, because we may have plenty of malloc space left
@@ -1662,7 +1663,7 @@ struct sdata
1662 1663
1663#ifdef GC_CHECK_STRING_BYTES 1664#ifdef GC_CHECK_STRING_BYTES
1664 1665
1665 EMACS_INT nbytes; 1666 ptrdiff_t nbytes;
1666 unsigned char data[1]; 1667 unsigned char data[1];
1667 1668
1668#define SDATA_NBYTES(S) (S)->nbytes 1669#define SDATA_NBYTES(S) (S)->nbytes
@@ -1677,7 +1678,7 @@ struct sdata
1677 unsigned char data[1]; 1678 unsigned char data[1];
1678 1679
1679 /* When STRING is null. */ 1680 /* When STRING is null. */
1680 EMACS_INT nbytes; 1681 ptrdiff_t nbytes;
1681 } u; 1682 } u;
1682 1683
1683#define SDATA_NBYTES(S) (S)->u.nbytes 1684#define SDATA_NBYTES(S) (S)->u.nbytes
@@ -1787,24 +1788,24 @@ static char const string_overrun_cookie[GC_STRING_OVERRUN_COOKIE_SIZE] =
1787#define SDATA_SIZE(NBYTES) \ 1788#define SDATA_SIZE(NBYTES) \
1788 ((SDATA_DATA_OFFSET \ 1789 ((SDATA_DATA_OFFSET \
1789 + (NBYTES) + 1 \ 1790 + (NBYTES) + 1 \
1790 + sizeof (EMACS_INT) - 1) \ 1791 + sizeof (ptrdiff_t) - 1) \
1791 & ~(sizeof (EMACS_INT) - 1)) 1792 & ~(sizeof (ptrdiff_t) - 1))
1792 1793
1793#else /* not GC_CHECK_STRING_BYTES */ 1794#else /* not GC_CHECK_STRING_BYTES */
1794 1795
1795/* The 'max' reserves space for the nbytes union member even when NBYTES + 1 is 1796/* The 'max' reserves space for the nbytes union member even when NBYTES + 1 is
1796 less than the size of that member. The 'max' is not needed when 1797 less than the size of that member. The 'max' is not needed when
1797 SDATA_DATA_OFFSET is a multiple of sizeof (EMACS_INT), because then the 1798 SDATA_DATA_OFFSET is a multiple of sizeof (ptrdiff_t), because then the
1798 alignment code reserves enough space. */ 1799 alignment code reserves enough space. */
1799 1800
1800#define SDATA_SIZE(NBYTES) \ 1801#define SDATA_SIZE(NBYTES) \
1801 ((SDATA_DATA_OFFSET \ 1802 ((SDATA_DATA_OFFSET \
1802 + (SDATA_DATA_OFFSET % sizeof (EMACS_INT) == 0 \ 1803 + (SDATA_DATA_OFFSET % sizeof (ptrdiff_t) == 0 \
1803 ? NBYTES \ 1804 ? NBYTES \
1804 : max (NBYTES, sizeof (EMACS_INT) - 1)) \ 1805 : max (NBYTES, sizeof (ptrdiff_t) - 1)) \
1805 + 1 \ 1806 + 1 \
1806 + sizeof (EMACS_INT) - 1) \ 1807 + sizeof (ptrdiff_t) - 1) \
1807 & ~(sizeof (EMACS_INT) - 1)) 1808 & ~(sizeof (ptrdiff_t) - 1))
1808 1809
1809#endif /* not GC_CHECK_STRING_BYTES */ 1810#endif /* not GC_CHECK_STRING_BYTES */
1810 1811
@@ -1848,10 +1849,10 @@ static int check_string_bytes_count;
1848 1849
1849/* Like GC_STRING_BYTES, but with debugging check. */ 1850/* Like GC_STRING_BYTES, but with debugging check. */
1850 1851
1851EMACS_INT 1852ptrdiff_t
1852string_bytes (struct Lisp_String *s) 1853string_bytes (struct Lisp_String *s)
1853{ 1854{
1854 EMACS_INT nbytes = 1855 ptrdiff_t nbytes =
1855 (s->size_byte < 0 ? s->size & ~ARRAY_MARK_FLAG : s->size_byte); 1856 (s->size_byte < 0 ? s->size & ~ARRAY_MARK_FLAG : s->size_byte);
1856 1857
1857 if (!PURE_POINTER_P (s) 1858 if (!PURE_POINTER_P (s)
@@ -1874,7 +1875,7 @@ check_sblock (struct sblock *b)
1874 { 1875 {
1875 /* Compute the next FROM here because copying below may 1876 /* Compute the next FROM here because copying below may
1876 overwrite data we need to compute it. */ 1877 overwrite data we need to compute it. */
1877 EMACS_INT nbytes; 1878 ptrdiff_t nbytes;
1878 1879
1879 /* Check that the string size recorded in the string is the 1880 /* Check that the string size recorded in the string is the
1880 same as the one recorded in the sdata structure. */ 1881 same as the one recorded in the sdata structure. */
@@ -2020,7 +2021,7 @@ allocate_string_data (struct Lisp_String *s,
2020{ 2021{
2021 struct sdata *data, *old_data; 2022 struct sdata *data, *old_data;
2022 struct sblock *b; 2023 struct sblock *b;
2023 EMACS_INT needed, old_nbytes; 2024 ptrdiff_t needed, old_nbytes;
2024 2025
2025 if (STRING_BYTES_MAX < nbytes) 2026 if (STRING_BYTES_MAX < nbytes)
2026 string_overflow (); 2027 string_overflow ();
@@ -2265,7 +2266,7 @@ compact_small_strings (void)
2265 { 2266 {
2266 /* Compute the next FROM here because copying below may 2267 /* Compute the next FROM here because copying below may
2267 overwrite data we need to compute it. */ 2268 overwrite data we need to compute it. */
2268 EMACS_INT nbytes; 2269 ptrdiff_t nbytes;
2269 2270
2270#ifdef GC_CHECK_STRING_BYTES 2271#ifdef GC_CHECK_STRING_BYTES
2271 /* Check that the string size recorded in the string is the 2272 /* Check that the string size recorded in the string is the
@@ -2395,7 +2396,8 @@ LENGTH must be a number. INIT matters only in whether it is t or nil. */)
2395{ 2396{
2396 register Lisp_Object val; 2397 register Lisp_Object val;
2397 struct Lisp_Bool_Vector *p; 2398 struct Lisp_Bool_Vector *p;
2398 EMACS_INT length_in_chars, length_in_elts; 2399 ptrdiff_t length_in_chars;
2400 EMACS_INT length_in_elts;
2399 int bits_per_value; 2401 int bits_per_value;
2400 2402
2401 CHECK_NATNUM (length); 2403 CHECK_NATNUM (length);
@@ -2403,8 +2405,6 @@ LENGTH must be a number. INIT matters only in whether it is t or nil. */)
2403 bits_per_value = sizeof (EMACS_INT) * BOOL_VECTOR_BITS_PER_CHAR; 2405 bits_per_value = sizeof (EMACS_INT) * BOOL_VECTOR_BITS_PER_CHAR;
2404 2406
2405 length_in_elts = (XFASTINT (length) + bits_per_value - 1) / bits_per_value; 2407 length_in_elts = (XFASTINT (length) + bits_per_value - 1) / bits_per_value;
2406 length_in_chars = ((XFASTINT (length) + BOOL_VECTOR_BITS_PER_CHAR - 1)
2407 / BOOL_VECTOR_BITS_PER_CHAR);
2408 2408
2409 /* We must allocate one more elements than LENGTH_IN_ELTS for the 2409 /* We must allocate one more elements than LENGTH_IN_ELTS for the
2410 slot `size' of the struct Lisp_Bool_Vector. */ 2410 slot `size' of the struct Lisp_Bool_Vector. */
@@ -2416,6 +2416,8 @@ LENGTH must be a number. INIT matters only in whether it is t or nil. */)
2416 p = XBOOL_VECTOR (val); 2416 p = XBOOL_VECTOR (val);
2417 p->size = XFASTINT (length); 2417 p->size = XFASTINT (length);
2418 2418
2419 length_in_chars = ((XFASTINT (length) + BOOL_VECTOR_BITS_PER_CHAR - 1)
2420 / BOOL_VECTOR_BITS_PER_CHAR);
2419 if (length_in_chars) 2421 if (length_in_chars)
2420 { 2422 {
2421 memset (p->data, ! NILP (init) ? -1 : 0, length_in_chars); 2423 memset (p->data, ! NILP (init) ? -1 : 0, length_in_chars);
@@ -2434,10 +2436,10 @@ LENGTH must be a number. INIT matters only in whether it is t or nil. */)
2434 multibyte, depending on the contents. */ 2436 multibyte, depending on the contents. */
2435 2437
2436Lisp_Object 2438Lisp_Object
2437make_string (const char *contents, EMACS_INT nbytes) 2439make_string (const char *contents, ptrdiff_t nbytes)
2438{ 2440{
2439 register Lisp_Object val; 2441 register Lisp_Object val;
2440 EMACS_INT nchars, multibyte_nbytes; 2442 ptrdiff_t nchars, multibyte_nbytes;
2441 2443
2442 parse_str_as_multibyte ((const unsigned char *) contents, nbytes, 2444 parse_str_as_multibyte ((const unsigned char *) contents, nbytes,
2443 &nchars, &multibyte_nbytes); 2445 &nchars, &multibyte_nbytes);
@@ -2454,7 +2456,7 @@ make_string (const char *contents, EMACS_INT nbytes)
2454/* Make an unibyte string from LENGTH bytes at CONTENTS. */ 2456/* Make an unibyte string from LENGTH bytes at CONTENTS. */
2455 2457
2456Lisp_Object 2458Lisp_Object
2457make_unibyte_string (const char *contents, EMACS_INT length) 2459make_unibyte_string (const char *contents, ptrdiff_t length)
2458{ 2460{
2459 register Lisp_Object val; 2461 register Lisp_Object val;
2460 val = make_uninit_string (length); 2462 val = make_uninit_string (length);
@@ -2468,7 +2470,7 @@ make_unibyte_string (const char *contents, EMACS_INT length)
2468 2470
2469Lisp_Object 2471Lisp_Object
2470make_multibyte_string (const char *contents, 2472make_multibyte_string (const char *contents,
2471 EMACS_INT nchars, EMACS_INT nbytes) 2473 ptrdiff_t nchars, ptrdiff_t nbytes)
2472{ 2474{
2473 register Lisp_Object val; 2475 register Lisp_Object val;
2474 val = make_uninit_multibyte_string (nchars, nbytes); 2476 val = make_uninit_multibyte_string (nchars, nbytes);
@@ -2482,7 +2484,7 @@ make_multibyte_string (const char *contents,
2482 2484
2483Lisp_Object 2485Lisp_Object
2484make_string_from_bytes (const char *contents, 2486make_string_from_bytes (const char *contents,
2485 EMACS_INT nchars, EMACS_INT nbytes) 2487 ptrdiff_t nchars, ptrdiff_t nbytes)
2486{ 2488{
2487 register Lisp_Object val; 2489 register Lisp_Object val;
2488 val = make_uninit_multibyte_string (nchars, nbytes); 2490 val = make_uninit_multibyte_string (nchars, nbytes);
@@ -2500,7 +2502,7 @@ make_string_from_bytes (const char *contents,
2500 2502
2501Lisp_Object 2503Lisp_Object
2502make_specified_string (const char *contents, 2504make_specified_string (const char *contents,
2503 EMACS_INT nchars, EMACS_INT nbytes, int multibyte) 2505 ptrdiff_t nchars, ptrdiff_t nbytes, int multibyte)
2504{ 2506{
2505 register Lisp_Object val; 2507 register Lisp_Object val;
2506 2508
@@ -2939,7 +2941,7 @@ enum
2939 with room for LEN Lisp_Objects. */ 2941 with room for LEN Lisp_Objects. */
2940 2942
2941static struct Lisp_Vector * 2943static struct Lisp_Vector *
2942allocate_vectorlike (EMACS_INT len) 2944allocate_vectorlike (ptrdiff_t len)
2943{ 2945{
2944 struct Lisp_Vector *p; 2946 struct Lisp_Vector *p;
2945 size_t nbytes; 2947 size_t nbytes;
@@ -2995,7 +2997,7 @@ allocate_vector (EMACS_INT len)
2995/* Allocate other vector-like structures. */ 2997/* Allocate other vector-like structures. */
2996 2998
2997struct Lisp_Vector * 2999struct Lisp_Vector *
2998allocate_pseudovector (int memlen, int lisplen, EMACS_INT tag) 3000allocate_pseudovector (int memlen, int lisplen, int tag)
2999{ 3001{
3000 struct Lisp_Vector *v = allocate_vectorlike (memlen); 3002 struct Lisp_Vector *v = allocate_vectorlike (memlen);
3001 int i; 3003 int i;
@@ -3059,14 +3061,14 @@ See also the function `vector'. */)
3059 (register Lisp_Object length, Lisp_Object init) 3061 (register Lisp_Object length, Lisp_Object init)
3060{ 3062{
3061 Lisp_Object vector; 3063 Lisp_Object vector;
3062 register EMACS_INT sizei; 3064 register ptrdiff_t sizei;
3063 register EMACS_INT i; 3065 register ptrdiff_t i;
3064 register struct Lisp_Vector *p; 3066 register struct Lisp_Vector *p;
3065 3067
3066 CHECK_NATNUM (length); 3068 CHECK_NATNUM (length);
3067 sizei = XFASTINT (length);
3068 3069
3069 p = allocate_vector (sizei); 3070 p = allocate_vector (XFASTINT (length));
3071 sizei = XFASTINT (length);
3070 for (i = 0; i < sizei; i++) 3072 for (i = 0; i < sizei; i++)
3071 p->contents[i] = init; 3073 p->contents[i] = init;
3072 3074
@@ -4791,14 +4793,14 @@ check_pure_size (void)
4791 address. Return NULL if not found. */ 4793 address. Return NULL if not found. */
4792 4794
4793static char * 4795static char *
4794find_string_data_in_pure (const char *data, EMACS_INT nbytes) 4796find_string_data_in_pure (const char *data, ptrdiff_t nbytes)
4795{ 4797{
4796 int i; 4798 int i;
4797 EMACS_INT skip, bm_skip[256], last_char_skip, infinity, start, start_max; 4799 ptrdiff_t skip, bm_skip[256], last_char_skip, infinity, start, start_max;
4798 const unsigned char *p; 4800 const unsigned char *p;
4799 char *non_lisp_beg; 4801 char *non_lisp_beg;
4800 4802
4801 if (pure_bytes_used_non_lisp < nbytes + 1) 4803 if (pure_bytes_used_non_lisp <= nbytes)
4802 return NULL; 4804 return NULL;
4803 4805
4804 /* Set up the Boyer-Moore table. */ 4806 /* Set up the Boyer-Moore table. */
@@ -4862,7 +4864,7 @@ find_string_data_in_pure (const char *data, EMACS_INT nbytes)
4862 4864
4863Lisp_Object 4865Lisp_Object
4864make_pure_string (const char *data, 4866make_pure_string (const char *data,
4865 EMACS_INT nchars, EMACS_INT nbytes, int multibyte) 4867 ptrdiff_t nchars, ptrdiff_t nbytes, int multibyte)
4866{ 4868{
4867 Lisp_Object string; 4869 Lisp_Object string;
4868 struct Lisp_String *s; 4870 struct Lisp_String *s;
@@ -4890,7 +4892,7 @@ make_pure_c_string (const char *data)
4890{ 4892{
4891 Lisp_Object string; 4893 Lisp_Object string;
4892 struct Lisp_String *s; 4894 struct Lisp_String *s;
4893 EMACS_INT nchars = strlen (data); 4895 ptrdiff_t nchars = strlen (data);
4894 4896
4895 s = (struct Lisp_String *) pure_alloc (sizeof *s, Lisp_String); 4897 s = (struct Lisp_String *) pure_alloc (sizeof *s, Lisp_String);
4896 s->size = nchars; 4898 s->size = nchars;
@@ -4936,8 +4938,8 @@ make_pure_float (double num)
4936/* Return a vector with room for LEN Lisp_Objects allocated from 4938/* Return a vector with room for LEN Lisp_Objects allocated from
4937 pure space. */ 4939 pure space. */
4938 4940
4939Lisp_Object 4941static Lisp_Object
4940make_pure_vector (EMACS_INT len) 4942make_pure_vector (ptrdiff_t len)
4941{ 4943{
4942 Lisp_Object new; 4944 Lisp_Object new;
4943 struct Lisp_Vector *p; 4945 struct Lisp_Vector *p;
@@ -4981,8 +4983,8 @@ Does not copy symbols. Copies strings without text properties. */)
4981 else if (COMPILEDP (obj) || VECTORP (obj)) 4983 else if (COMPILEDP (obj) || VECTORP (obj))
4982 { 4984 {
4983 register struct Lisp_Vector *vec; 4985 register struct Lisp_Vector *vec;
4984 register EMACS_INT i; 4986 register ptrdiff_t i;
4985 EMACS_INT size; 4987 ptrdiff_t size;
4986 4988
4987 size = ASIZE (obj); 4989 size = ASIZE (obj);
4988 if (size & PSEUDOVECTOR_FLAG) 4990 if (size & PSEUDOVECTOR_FLAG)
@@ -5034,10 +5036,10 @@ staticpro (Lisp_Object *varaddress)
5034 5036
5035/* Temporarily prevent garbage collection. */ 5037/* Temporarily prevent garbage collection. */
5036 5038
5037int 5039ptrdiff_t
5038inhibit_garbage_collection (void) 5040inhibit_garbage_collection (void)
5039{ 5041{
5040 int count = SPECPDL_INDEX (); 5042 ptrdiff_t count = SPECPDL_INDEX ();
5041 5043
5042 specbind (Qgc_cons_threshold, make_number (MOST_POSITIVE_FIXNUM)); 5044 specbind (Qgc_cons_threshold, make_number (MOST_POSITIVE_FIXNUM));
5043 return count; 5045 return count;
@@ -5063,7 +5065,7 @@ See Info node `(elisp)Garbage Collection'. */)
5063 ptrdiff_t i; 5065 ptrdiff_t i;
5064 int message_p; 5066 int message_p;
5065 Lisp_Object total[8]; 5067 Lisp_Object total[8];
5066 int count = SPECPDL_INDEX (); 5068 ptrdiff_t count = SPECPDL_INDEX ();
5067 EMACS_TIME t1, t2, t3; 5069 EMACS_TIME t1, t2, t3;
5068 5070
5069 if (abort_on_gc) 5071 if (abort_on_gc)
@@ -5358,7 +5360,7 @@ See Info node `(elisp)Garbage Collection'. */)
5358 5360
5359 if (!NILP (Vpost_gc_hook)) 5361 if (!NILP (Vpost_gc_hook))
5360 { 5362 {
5361 int gc_count = inhibit_garbage_collection (); 5363 ptrdiff_t gc_count = inhibit_garbage_collection ();
5362 safe_run_hooks (Qpost_gc_hook); 5364 safe_run_hooks (Qpost_gc_hook);
5363 unbind_to (gc_count, Qnil); 5365 unbind_to (gc_count, Qnil);
5364 } 5366 }
@@ -5443,8 +5445,8 @@ ptrdiff_t mark_object_loop_halt EXTERNALLY_VISIBLE;
5443static void 5445static void
5444mark_vectorlike (struct Lisp_Vector *ptr) 5446mark_vectorlike (struct Lisp_Vector *ptr)
5445{ 5447{
5446 EMACS_INT size = ptr->header.size; 5448 ptrdiff_t size = ptr->header.size;
5447 EMACS_INT i; 5449 ptrdiff_t i;
5448 5450
5449 eassert (!VECTOR_MARKED_P (ptr)); 5451 eassert (!VECTOR_MARKED_P (ptr));
5450 VECTOR_MARK (ptr); /* Else mark it */ 5452 VECTOR_MARK (ptr); /* Else mark it */
@@ -6325,7 +6327,7 @@ Lisp_Object
6325which_symbols (Lisp_Object obj, EMACS_INT find_max) 6327which_symbols (Lisp_Object obj, EMACS_INT find_max)
6326{ 6328{
6327 struct symbol_block *sblk; 6329 struct symbol_block *sblk;
6328 int gc_count = inhibit_garbage_collection (); 6330 ptrdiff_t gc_count = inhibit_garbage_collection ();
6329 Lisp_Object found = Qnil; 6331 Lisp_Object found = Qnil;
6330 6332
6331 if (! DEADP (obj)) 6333 if (! DEADP (obj))