aboutsummaryrefslogtreecommitdiffstats
path: root/src/alloc.c
diff options
context:
space:
mode:
authorStefan Monnier2010-09-30 01:28:20 +0200
committerStefan Monnier2010-09-30 01:28:20 +0200
commita01a7932080e8a6e7bc8472c58cefabcc2c37df3 (patch)
tree94b28b19c8f1536e76ffe7d5826811b74a79e3a5 /src/alloc.c
parentcc390e46c7ba95b76ea133d98fd386214cd01709 (diff)
parent6b0f7311f16646e0de2045b2410e20921901c616 (diff)
downloademacs-a01a7932080e8a6e7bc8472c58cefabcc2c37df3.tar.gz
emacs-a01a7932080e8a6e7bc8472c58cefabcc2c37df3.zip
Merge from trunk
Diffstat (limited to 'src/alloc.c')
-rw-r--r--src/alloc.c92
1 files changed, 52 insertions, 40 deletions
diff --git a/src/alloc.c b/src/alloc.c
index d83d8937722..f2bb28e2d96 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -1643,7 +1643,7 @@ static int total_strings, total_free_strings;
1643 1643
1644/* Number of bytes used by live strings. */ 1644/* Number of bytes used by live strings. */
1645 1645
1646static int total_string_size; 1646static EMACS_INT total_string_size;
1647 1647
1648/* Given a pointer to a Lisp_String S which is on the free-list 1648/* Given a pointer to a Lisp_String S which is on the free-list
1649 string_free_list, return a pointer to its successor in the 1649 string_free_list, return a pointer to its successor in the
@@ -1738,11 +1738,12 @@ static void check_sblock (struct sblock *);
1738 1738
1739/* Like GC_STRING_BYTES, but with debugging check. */ 1739/* Like GC_STRING_BYTES, but with debugging check. */
1740 1740
1741int 1741EMACS_INT
1742string_bytes (s) 1742string_bytes (struct Lisp_String *s)
1743 struct Lisp_String *s;
1744{ 1743{
1745 int nbytes = (s->size_byte < 0 ? s->size & ~ARRAY_MARK_FLAG : s->size_byte); 1744 EMACS_INT nbytes =
1745 (s->size_byte < 0 ? s->size & ~ARRAY_MARK_FLAG : s->size_byte);
1746
1746 if (!PURE_POINTER_P (s) 1747 if (!PURE_POINTER_P (s)
1747 && s->data 1748 && s->data
1748 && nbytes != SDATA_NBYTES (SDATA_OF_STRING (s))) 1749 && nbytes != SDATA_NBYTES (SDATA_OF_STRING (s)))
@@ -1764,7 +1765,7 @@ check_sblock (b)
1764 { 1765 {
1765 /* Compute the next FROM here because copying below may 1766 /* Compute the next FROM here because copying below may
1766 overwrite data we need to compute it. */ 1767 overwrite data we need to compute it. */
1767 int nbytes; 1768 EMACS_INT nbytes;
1768 1769
1769 /* Check that the string size recorded in the string is the 1770 /* Check that the string size recorded in the string is the
1770 same as the one recorded in the sdata structure. */ 1771 same as the one recorded in the sdata structure. */
@@ -1824,7 +1825,7 @@ check_string_free_list ()
1824 s = string_free_list; 1825 s = string_free_list;
1825 while (s != NULL) 1826 while (s != NULL)
1826 { 1827 {
1827 if ((unsigned)s < 1024) 1828 if ((unsigned long)s < 1024)
1828 abort(); 1829 abort();
1829 s = NEXT_FREE_LISP_STRING (s); 1830 s = NEXT_FREE_LISP_STRING (s);
1830 } 1831 }
@@ -1907,11 +1908,12 @@ allocate_string (void)
1907 S->data if it was initially non-null. */ 1908 S->data if it was initially non-null. */
1908 1909
1909void 1910void
1910allocate_string_data (struct Lisp_String *s, int nchars, int nbytes) 1911allocate_string_data (struct Lisp_String *s,
1912 EMACS_INT nchars, EMACS_INT nbytes)
1911{ 1913{
1912 struct sdata *data, *old_data; 1914 struct sdata *data, *old_data;
1913 struct sblock *b; 1915 struct sblock *b;
1914 int needed, old_nbytes; 1916 EMACS_INT needed, old_nbytes;
1915 1917
1916 /* Determine the number of bytes needed to store NBYTES bytes 1918 /* Determine the number of bytes needed to store NBYTES bytes
1917 of string data. */ 1919 of string data. */
@@ -2153,7 +2155,7 @@ compact_small_strings (void)
2153 { 2155 {
2154 /* Compute the next FROM here because copying below may 2156 /* Compute the next FROM here because copying below may
2155 overwrite data we need to compute it. */ 2157 overwrite data we need to compute it. */
2156 int nbytes; 2158 EMACS_INT nbytes;
2157 2159
2158#ifdef GC_CHECK_STRING_BYTES 2160#ifdef GC_CHECK_STRING_BYTES
2159 /* Check that the string size recorded in the string is the 2161 /* Check that the string size recorded in the string is the
@@ -2231,7 +2233,8 @@ INIT must be an integer that represents a character. */)
2231{ 2233{
2232 register Lisp_Object val; 2234 register Lisp_Object val;
2233 register unsigned char *p, *end; 2235 register unsigned char *p, *end;
2234 int c, nbytes; 2236 int c;
2237 EMACS_INT nbytes;
2235 2238
2236 CHECK_NATNUM (length); 2239 CHECK_NATNUM (length);
2237 CHECK_NUMBER (init); 2240 CHECK_NUMBER (init);
@@ -2250,9 +2253,12 @@ INIT must be an integer that represents a character. */)
2250 { 2253 {
2251 unsigned char str[MAX_MULTIBYTE_LENGTH]; 2254 unsigned char str[MAX_MULTIBYTE_LENGTH];
2252 int len = CHAR_STRING (c, str); 2255 int len = CHAR_STRING (c, str);
2256 EMACS_INT string_len = XINT (length);
2253 2257
2254 nbytes = len * XINT (length); 2258 if (string_len > MOST_POSITIVE_FIXNUM / len)
2255 val = make_uninit_multibyte_string (XINT (length), nbytes); 2259 error ("Maximum string size exceeded");
2260 nbytes = len * string_len;
2261 val = make_uninit_multibyte_string (string_len, nbytes);
2256 p = SDATA (val); 2262 p = SDATA (val);
2257 end = p + nbytes; 2263 end = p + nbytes;
2258 while (p != end) 2264 while (p != end)
@@ -2275,7 +2281,8 @@ LENGTH must be a number. INIT matters only in whether it is t or nil. */)
2275 register Lisp_Object val; 2281 register Lisp_Object val;
2276 struct Lisp_Bool_Vector *p; 2282 struct Lisp_Bool_Vector *p;
2277 int real_init, i; 2283 int real_init, i;
2278 int length_in_chars, length_in_elts, bits_per_value; 2284 EMACS_INT length_in_chars, length_in_elts;
2285 int bits_per_value;
2279 2286
2280 CHECK_NATNUM (length); 2287 CHECK_NATNUM (length);
2281 2288
@@ -2315,10 +2322,10 @@ LENGTH must be a number. INIT matters only in whether it is t or nil. */)
2315 multibyte, depending on the contents. */ 2322 multibyte, depending on the contents. */
2316 2323
2317Lisp_Object 2324Lisp_Object
2318make_string (const char *contents, int nbytes) 2325make_string (const char *contents, EMACS_INT nbytes)
2319{ 2326{
2320 register Lisp_Object val; 2327 register Lisp_Object val;
2321 int nchars, multibyte_nbytes; 2328 EMACS_INT nchars, multibyte_nbytes;
2322 2329
2323 parse_str_as_multibyte (contents, nbytes, &nchars, &multibyte_nbytes); 2330 parse_str_as_multibyte (contents, nbytes, &nchars, &multibyte_nbytes);
2324 if (nbytes == nchars || nbytes != multibyte_nbytes) 2331 if (nbytes == nchars || nbytes != multibyte_nbytes)
@@ -2334,7 +2341,7 @@ make_string (const char *contents, int nbytes)
2334/* Make an unibyte string from LENGTH bytes at CONTENTS. */ 2341/* Make an unibyte string from LENGTH bytes at CONTENTS. */
2335 2342
2336Lisp_Object 2343Lisp_Object
2337make_unibyte_string (const char *contents, int length) 2344make_unibyte_string (const char *contents, EMACS_INT length)
2338{ 2345{
2339 register Lisp_Object val; 2346 register Lisp_Object val;
2340 val = make_uninit_string (length); 2347 val = make_uninit_string (length);
@@ -2348,7 +2355,8 @@ make_unibyte_string (const char *contents, int length)
2348 bytes at CONTENTS. */ 2355 bytes at CONTENTS. */
2349 2356
2350Lisp_Object 2357Lisp_Object
2351make_multibyte_string (const char *contents, int nchars, int nbytes) 2358make_multibyte_string (const char *contents,
2359 EMACS_INT nchars, EMACS_INT nbytes)
2352{ 2360{
2353 register Lisp_Object val; 2361 register Lisp_Object val;
2354 val = make_uninit_multibyte_string (nchars, nbytes); 2362 val = make_uninit_multibyte_string (nchars, nbytes);
@@ -2361,7 +2369,8 @@ make_multibyte_string (const char *contents, int nchars, int nbytes)
2361 CONTENTS. It is a multibyte string if NBYTES != NCHARS. */ 2369 CONTENTS. It is a multibyte string if NBYTES != NCHARS. */
2362 2370
2363Lisp_Object 2371Lisp_Object
2364make_string_from_bytes (const char *contents, int nchars, int nbytes) 2372make_string_from_bytes (const char *contents,
2373 EMACS_INT nchars, EMACS_INT nbytes)
2365{ 2374{
2366 register Lisp_Object val; 2375 register Lisp_Object val;
2367 val = make_uninit_multibyte_string (nchars, nbytes); 2376 val = make_uninit_multibyte_string (nchars, nbytes);
@@ -2378,7 +2387,8 @@ make_string_from_bytes (const char *contents, int nchars, int nbytes)
2378 characters by itself. */ 2387 characters by itself. */
2379 2388
2380Lisp_Object 2389Lisp_Object
2381make_specified_string (const char *contents, int nchars, int nbytes, int multibyte) 2390make_specified_string (const char *contents,
2391 EMACS_INT nchars, EMACS_INT nbytes, int multibyte)
2382{ 2392{
2383 register Lisp_Object val; 2393 register Lisp_Object val;
2384 2394
@@ -2411,7 +2421,7 @@ build_string (const char *str)
2411 occupying LENGTH bytes. */ 2421 occupying LENGTH bytes. */
2412 2422
2413Lisp_Object 2423Lisp_Object
2414make_uninit_string (int length) 2424make_uninit_string (EMACS_INT length)
2415{ 2425{
2416 Lisp_Object val; 2426 Lisp_Object val;
2417 2427
@@ -2427,7 +2437,7 @@ make_uninit_string (int length)
2427 which occupy NBYTES bytes. */ 2437 which occupy NBYTES bytes. */
2428 2438
2429Lisp_Object 2439Lisp_Object
2430make_uninit_multibyte_string (int nchars, int nbytes) 2440make_uninit_multibyte_string (EMACS_INT nchars, EMACS_INT nbytes)
2431{ 2441{
2432 Lisp_Object string; 2442 Lisp_Object string;
2433 struct Lisp_String *s; 2443 struct Lisp_String *s;
@@ -2766,7 +2776,7 @@ DEFUN ("make-list", Fmake_list, Smake_list, 2, 2, 0,
2766 (register Lisp_Object length, Lisp_Object init) 2776 (register Lisp_Object length, Lisp_Object init)
2767{ 2777{
2768 register Lisp_Object val; 2778 register Lisp_Object val;
2769 register int size; 2779 register EMACS_INT size;
2770 2780
2771 CHECK_NATNUM (length); 2781 CHECK_NATNUM (length);
2772 size = XFASTINT (length); 2782 size = XFASTINT (length);
@@ -2944,7 +2954,7 @@ See also the function `vector'. */)
2944{ 2954{
2945 Lisp_Object vector; 2955 Lisp_Object vector;
2946 register EMACS_INT sizei; 2956 register EMACS_INT sizei;
2947 register int index; 2957 register EMACS_INT index;
2948 register struct Lisp_Vector *p; 2958 register struct Lisp_Vector *p;
2949 2959
2950 CHECK_NATNUM (length); 2960 CHECK_NATNUM (length);
@@ -3841,7 +3851,7 @@ live_string_p (struct mem_node *m, void *p)
3841 if (m->type == MEM_TYPE_STRING) 3851 if (m->type == MEM_TYPE_STRING)
3842 { 3852 {
3843 struct string_block *b = (struct string_block *) m->start; 3853 struct string_block *b = (struct string_block *) m->start;
3844 int offset = (char *) p - (char *) &b->strings[0]; 3854 ptrdiff_t offset = (char *) p - (char *) &b->strings[0];
3845 3855
3846 /* P must point to the start of a Lisp_String structure, and it 3856 /* P must point to the start of a Lisp_String structure, and it
3847 must not be on the free-list. */ 3857 must not be on the free-list. */
@@ -3864,7 +3874,7 @@ live_cons_p (struct mem_node *m, void *p)
3864 if (m->type == MEM_TYPE_CONS) 3874 if (m->type == MEM_TYPE_CONS)
3865 { 3875 {
3866 struct cons_block *b = (struct cons_block *) m->start; 3876 struct cons_block *b = (struct cons_block *) m->start;
3867 int offset = (char *) p - (char *) &b->conses[0]; 3877 ptrdiff_t offset = (char *) p - (char *) &b->conses[0];
3868 3878
3869 /* P must point to the start of a Lisp_Cons, not be 3879 /* P must point to the start of a Lisp_Cons, not be
3870 one of the unused cells in the current cons block, 3880 one of the unused cells in the current cons block,
@@ -3890,7 +3900,7 @@ live_symbol_p (struct mem_node *m, void *p)
3890 if (m->type == MEM_TYPE_SYMBOL) 3900 if (m->type == MEM_TYPE_SYMBOL)
3891 { 3901 {
3892 struct symbol_block *b = (struct symbol_block *) m->start; 3902 struct symbol_block *b = (struct symbol_block *) m->start;
3893 int offset = (char *) p - (char *) &b->symbols[0]; 3903 ptrdiff_t offset = (char *) p - (char *) &b->symbols[0];
3894 3904
3895 /* P must point to the start of a Lisp_Symbol, not be 3905 /* P must point to the start of a Lisp_Symbol, not be
3896 one of the unused cells in the current symbol block, 3906 one of the unused cells in the current symbol block,
@@ -3916,7 +3926,7 @@ live_float_p (struct mem_node *m, void *p)
3916 if (m->type == MEM_TYPE_FLOAT) 3926 if (m->type == MEM_TYPE_FLOAT)
3917 { 3927 {
3918 struct float_block *b = (struct float_block *) m->start; 3928 struct float_block *b = (struct float_block *) m->start;
3919 int offset = (char *) p - (char *) &b->floats[0]; 3929 ptrdiff_t offset = (char *) p - (char *) &b->floats[0];
3920 3930
3921 /* P must point to the start of a Lisp_Float and not be 3931 /* P must point to the start of a Lisp_Float and not be
3922 one of the unused cells in the current float block. */ 3932 one of the unused cells in the current float block. */
@@ -3940,7 +3950,7 @@ live_misc_p (struct mem_node *m, void *p)
3940 if (m->type == MEM_TYPE_MISC) 3950 if (m->type == MEM_TYPE_MISC)
3941 { 3951 {
3942 struct marker_block *b = (struct marker_block *) m->start; 3952 struct marker_block *b = (struct marker_block *) m->start;
3943 int offset = (char *) p - (char *) &b->markers[0]; 3953 ptrdiff_t offset = (char *) p - (char *) &b->markers[0];
3944 3954
3945 /* P must point to the start of a Lisp_Misc, not be 3955 /* P must point to the start of a Lisp_Misc, not be
3946 one of the unused cells in the current misc block, 3956 one of the unused cells in the current misc block,
@@ -4647,9 +4657,10 @@ check_pure_size (void)
4647 address. Return NULL if not found. */ 4657 address. Return NULL if not found. */
4648 4658
4649static char * 4659static char *
4650find_string_data_in_pure (const char *data, int nbytes) 4660find_string_data_in_pure (const char *data, EMACS_INT nbytes)
4651{ 4661{
4652 int i, skip, bm_skip[256], last_char_skip, infinity, start, start_max; 4662 int i;
4663 EMACS_INT skip, bm_skip[256], last_char_skip, infinity, start, start_max;
4653 const unsigned char *p; 4664 const unsigned char *p;
4654 char *non_lisp_beg; 4665 char *non_lisp_beg;
4655 4666
@@ -4716,7 +4727,8 @@ find_string_data_in_pure (const char *data, int nbytes)
4716 string; then the string is not protected from gc. */ 4727 string; then the string is not protected from gc. */
4717 4728
4718Lisp_Object 4729Lisp_Object
4719make_pure_string (const char *data, int nchars, int nbytes, int multibyte) 4730make_pure_string (const char *data,
4731 EMACS_INT nchars, EMACS_INT nbytes, int multibyte)
4720{ 4732{
4721 Lisp_Object string; 4733 Lisp_Object string;
4722 struct Lisp_String *s; 4734 struct Lisp_String *s;
@@ -4744,7 +4756,7 @@ make_pure_c_string (const char *data)
4744{ 4756{
4745 Lisp_Object string; 4757 Lisp_Object string;
4746 struct Lisp_String *s; 4758 struct Lisp_String *s;
4747 int nchars = strlen (data); 4759 EMACS_INT nchars = strlen (data);
4748 4760
4749 s = (struct Lisp_String *) pure_alloc (sizeof *s, Lisp_String); 4761 s = (struct Lisp_String *) pure_alloc (sizeof *s, Lisp_String);
4750 s->size = nchars; 4762 s->size = nchars;
@@ -4834,7 +4846,7 @@ Does not copy symbols. Copies strings without text properties. */)
4834 else if (FUNVECP (obj) || VECTORP (obj)) 4846 else if (FUNVECP (obj) || VECTORP (obj))
4835 { 4847 {
4836 register struct Lisp_Vector *vec; 4848 register struct Lisp_Vector *vec;
4837 register int i; 4849 register EMACS_INT i;
4838 EMACS_INT size; 4850 EMACS_INT size;
4839 4851
4840 size = XVECTOR (obj)->size; 4852 size = XVECTOR (obj)->size;
@@ -5283,8 +5295,8 @@ static int mark_object_loop_halt;
5283static void 5295static void
5284mark_vectorlike (struct Lisp_Vector *ptr) 5296mark_vectorlike (struct Lisp_Vector *ptr)
5285{ 5297{
5286 register EMACS_INT size = ptr->size; 5298 register EMACS_UINT size = ptr->size;
5287 register int i; 5299 register EMACS_UINT i;
5288 5300
5289 eassert (!VECTOR_MARKED_P (ptr)); 5301 eassert (!VECTOR_MARKED_P (ptr));
5290 VECTOR_MARK (ptr); /* Else mark it */ 5302 VECTOR_MARK (ptr); /* Else mark it */
@@ -5306,8 +5318,8 @@ mark_vectorlike (struct Lisp_Vector *ptr)
5306static void 5318static void
5307mark_char_table (struct Lisp_Vector *ptr) 5319mark_char_table (struct Lisp_Vector *ptr)
5308{ 5320{
5309 register EMACS_INT size = ptr->size & PSEUDOVECTOR_SIZE_MASK; 5321 register EMACS_UINT size = ptr->size & PSEUDOVECTOR_SIZE_MASK;
5310 register int i; 5322 register EMACS_UINT i;
5311 5323
5312 eassert (!VECTOR_MARKED_P (ptr)); 5324 eassert (!VECTOR_MARKED_P (ptr));
5313 VECTOR_MARK (ptr); 5325 VECTOR_MARK (ptr);
@@ -5436,8 +5448,8 @@ mark_object (Lisp_Object arg)
5436 recursion there. */ 5448 recursion there. */
5437 { 5449 {
5438 register struct Lisp_Vector *ptr = XVECTOR (obj); 5450 register struct Lisp_Vector *ptr = XVECTOR (obj);
5439 register EMACS_INT size = ptr->size; 5451 register EMACS_UINT size = ptr->size;
5440 register int i; 5452 register EMACS_UINT i;
5441 5453
5442 CHECK_LIVE (live_vector_p); 5454 CHECK_LIVE (live_vector_p);
5443 VECTOR_MARK (ptr); /* Else mark it */ 5455 VECTOR_MARK (ptr); /* Else mark it */