summaryrefslogtreecommitdiff
path: root/src/alloc.c
diff options
context:
space:
mode:
authorStefan Monnier <monnier@iro.umontreal.ca>2010-09-30 01:28:20 +0200
committerStefan Monnier <monnier@iro.umontreal.ca>2010-09-30 01:28:20 +0200
commita01a7932080e8a6e7bc8472c58cefabcc2c37df3 (patch)
tree94b28b19c8f1536e76ffe7d5826811b74a79e3a5 /src/alloc.c
parentcc390e46c7ba95b76ea133d98fd386214cd01709 (diff)
parent6b0f7311f16646e0de2045b2410e20921901c616 (diff)
downloademacs-a01a7932080e8a6e7bc8472c58cefabcc2c37df3.tar.gz
emacs-a01a7932080e8a6e7bc8472c58cefabcc2c37df3.tar.bz2
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;
/* Number of bytes used by live strings. */
-static int total_string_size;
+static EMACS_INT total_string_size;
/* Given a pointer to a Lisp_String S which is on the free-list
string_free_list, return a pointer to its successor in the
@@ -1738,11 +1738,12 @@ static void check_sblock (struct sblock *);
/* Like GC_STRING_BYTES, but with debugging check. */
-int
-string_bytes (s)
- struct Lisp_String *s;
+EMACS_INT
+string_bytes (struct Lisp_String *s)
{
- int nbytes = (s->size_byte < 0 ? s->size & ~ARRAY_MARK_FLAG : s->size_byte);
+ EMACS_INT nbytes =
+ (s->size_byte < 0 ? s->size & ~ARRAY_MARK_FLAG : s->size_byte);
+
if (!PURE_POINTER_P (s)
&& s->data
&& nbytes != SDATA_NBYTES (SDATA_OF_STRING (s)))
@@ -1764,7 +1765,7 @@ check_sblock (b)
{
/* Compute the next FROM here because copying below may
overwrite data we need to compute it. */
- int nbytes;
+ EMACS_INT nbytes;
/* Check that the string size recorded in the string is the
same as the one recorded in the sdata structure. */
@@ -1824,7 +1825,7 @@ check_string_free_list ()
s = string_free_list;
while (s != NULL)
{
- if ((unsigned)s < 1024)
+ if ((unsigned long)s < 1024)
abort();
s = NEXT_FREE_LISP_STRING (s);
}
@@ -1907,11 +1908,12 @@ allocate_string (void)
S->data if it was initially non-null. */
void
-allocate_string_data (struct Lisp_String *s, int nchars, int nbytes)
+allocate_string_data (struct Lisp_String *s,
+ EMACS_INT nchars, EMACS_INT nbytes)
{
struct sdata *data, *old_data;
struct sblock *b;
- int needed, old_nbytes;
+ EMACS_INT needed, old_nbytes;
/* Determine the number of bytes needed to store NBYTES bytes
of string data. */
@@ -2153,7 +2155,7 @@ compact_small_strings (void)
{
/* Compute the next FROM here because copying below may
overwrite data we need to compute it. */
- int nbytes;
+ EMACS_INT nbytes;
#ifdef GC_CHECK_STRING_BYTES
/* Check that the string size recorded in the string is the
@@ -2231,7 +2233,8 @@ INIT must be an integer that represents a character. */)
{
register Lisp_Object val;
register unsigned char *p, *end;
- int c, nbytes;
+ int c;
+ EMACS_INT nbytes;
CHECK_NATNUM (length);
CHECK_NUMBER (init);
@@ -2250,9 +2253,12 @@ INIT must be an integer that represents a character. */)
{
unsigned char str[MAX_MULTIBYTE_LENGTH];
int len = CHAR_STRING (c, str);
+ EMACS_INT string_len = XINT (length);
- nbytes = len * XINT (length);
- val = make_uninit_multibyte_string (XINT (length), nbytes);
+ if (string_len > MOST_POSITIVE_FIXNUM / len)
+ error ("Maximum string size exceeded");
+ nbytes = len * string_len;
+ val = make_uninit_multibyte_string (string_len, nbytes);
p = SDATA (val);
end = p + nbytes;
while (p != end)
@@ -2275,7 +2281,8 @@ LENGTH must be a number. INIT matters only in whether it is t or nil. */)
register Lisp_Object val;
struct Lisp_Bool_Vector *p;
int real_init, i;
- int length_in_chars, length_in_elts, bits_per_value;
+ EMACS_INT length_in_chars, length_in_elts;
+ int bits_per_value;
CHECK_NATNUM (length);
@@ -2315,10 +2322,10 @@ LENGTH must be a number. INIT matters only in whether it is t or nil. */)
multibyte, depending on the contents. */
Lisp_Object
-make_string (const char *contents, int nbytes)
+make_string (const char *contents, EMACS_INT nbytes)
{
register Lisp_Object val;
- int nchars, multibyte_nbytes;
+ EMACS_INT nchars, multibyte_nbytes;
parse_str_as_multibyte (contents, nbytes, &nchars, &multibyte_nbytes);
if (nbytes == nchars || nbytes != multibyte_nbytes)
@@ -2334,7 +2341,7 @@ make_string (const char *contents, int nbytes)
/* Make an unibyte string from LENGTH bytes at CONTENTS. */
Lisp_Object
-make_unibyte_string (const char *contents, int length)
+make_unibyte_string (const char *contents, EMACS_INT length)
{
register Lisp_Object val;
val = make_uninit_string (length);
@@ -2348,7 +2355,8 @@ make_unibyte_string (const char *contents, int length)
bytes at CONTENTS. */
Lisp_Object
-make_multibyte_string (const char *contents, int nchars, int nbytes)
+make_multibyte_string (const char *contents,
+ EMACS_INT nchars, EMACS_INT nbytes)
{
register Lisp_Object val;
val = make_uninit_multibyte_string (nchars, nbytes);
@@ -2361,7 +2369,8 @@ make_multibyte_string (const char *contents, int nchars, int nbytes)
CONTENTS. It is a multibyte string if NBYTES != NCHARS. */
Lisp_Object
-make_string_from_bytes (const char *contents, int nchars, int nbytes)
+make_string_from_bytes (const char *contents,
+ EMACS_INT nchars, EMACS_INT nbytes)
{
register Lisp_Object val;
val = make_uninit_multibyte_string (nchars, nbytes);
@@ -2378,7 +2387,8 @@ make_string_from_bytes (const char *contents, int nchars, int nbytes)
characters by itself. */
Lisp_Object
-make_specified_string (const char *contents, int nchars, int nbytes, int multibyte)
+make_specified_string (const char *contents,
+ EMACS_INT nchars, EMACS_INT nbytes, int multibyte)
{
register Lisp_Object val;
@@ -2411,7 +2421,7 @@ build_string (const char *str)
occupying LENGTH bytes. */
Lisp_Object
-make_uninit_string (int length)
+make_uninit_string (EMACS_INT length)
{
Lisp_Object val;
@@ -2427,7 +2437,7 @@ make_uninit_string (int length)
which occupy NBYTES bytes. */
Lisp_Object
-make_uninit_multibyte_string (int nchars, int nbytes)
+make_uninit_multibyte_string (EMACS_INT nchars, EMACS_INT nbytes)
{
Lisp_Object string;
struct Lisp_String *s;
@@ -2766,7 +2776,7 @@ DEFUN ("make-list", Fmake_list, Smake_list, 2, 2, 0,
(register Lisp_Object length, Lisp_Object init)
{
register Lisp_Object val;
- register int size;
+ register EMACS_INT size;
CHECK_NATNUM (length);
size = XFASTINT (length);
@@ -2944,7 +2954,7 @@ See also the function `vector'. */)
{
Lisp_Object vector;
register EMACS_INT sizei;
- register int index;
+ register EMACS_INT index;
register struct Lisp_Vector *p;
CHECK_NATNUM (length);
@@ -3841,7 +3851,7 @@ live_string_p (struct mem_node *m, void *p)
if (m->type == MEM_TYPE_STRING)
{
struct string_block *b = (struct string_block *) m->start;
- int offset = (char *) p - (char *) &b->strings[0];
+ ptrdiff_t offset = (char *) p - (char *) &b->strings[0];
/* P must point to the start of a Lisp_String structure, and it
must not be on the free-list. */
@@ -3864,7 +3874,7 @@ live_cons_p (struct mem_node *m, void *p)
if (m->type == MEM_TYPE_CONS)
{
struct cons_block *b = (struct cons_block *) m->start;
- int offset = (char *) p - (char *) &b->conses[0];
+ ptrdiff_t offset = (char *) p - (char *) &b->conses[0];
/* P must point to the start of a Lisp_Cons, not be
one of the unused cells in the current cons block,
@@ -3890,7 +3900,7 @@ live_symbol_p (struct mem_node *m, void *p)
if (m->type == MEM_TYPE_SYMBOL)
{
struct symbol_block *b = (struct symbol_block *) m->start;
- int offset = (char *) p - (char *) &b->symbols[0];
+ ptrdiff_t offset = (char *) p - (char *) &b->symbols[0];
/* P must point to the start of a Lisp_Symbol, not be
one of the unused cells in the current symbol block,
@@ -3916,7 +3926,7 @@ live_float_p (struct mem_node *m, void *p)
if (m->type == MEM_TYPE_FLOAT)
{
struct float_block *b = (struct float_block *) m->start;
- int offset = (char *) p - (char *) &b->floats[0];
+ ptrdiff_t offset = (char *) p - (char *) &b->floats[0];
/* P must point to the start of a Lisp_Float and not be
one of the unused cells in the current float block. */
@@ -3940,7 +3950,7 @@ live_misc_p (struct mem_node *m, void *p)
if (m->type == MEM_TYPE_MISC)
{
struct marker_block *b = (struct marker_block *) m->start;
- int offset = (char *) p - (char *) &b->markers[0];
+ ptrdiff_t offset = (char *) p - (char *) &b->markers[0];
/* P must point to the start of a Lisp_Misc, not be
one of the unused cells in the current misc block,
@@ -4647,9 +4657,10 @@ check_pure_size (void)
address. Return NULL if not found. */
static char *
-find_string_data_in_pure (const char *data, int nbytes)
+find_string_data_in_pure (const char *data, EMACS_INT nbytes)
{
- int i, skip, bm_skip[256], last_char_skip, infinity, start, start_max;
+ int i;
+ EMACS_INT skip, bm_skip[256], last_char_skip, infinity, start, start_max;
const unsigned char *p;
char *non_lisp_beg;
@@ -4716,7 +4727,8 @@ find_string_data_in_pure (const char *data, int nbytes)
string; then the string is not protected from gc. */
Lisp_Object
-make_pure_string (const char *data, int nchars, int nbytes, int multibyte)
+make_pure_string (const char *data,
+ EMACS_INT nchars, EMACS_INT nbytes, int multibyte)
{
Lisp_Object string;
struct Lisp_String *s;
@@ -4744,7 +4756,7 @@ make_pure_c_string (const char *data)
{
Lisp_Object string;
struct Lisp_String *s;
- int nchars = strlen (data);
+ EMACS_INT nchars = strlen (data);
s = (struct Lisp_String *) pure_alloc (sizeof *s, Lisp_String);
s->size = nchars;
@@ -4834,7 +4846,7 @@ Does not copy symbols. Copies strings without text properties. */)
else if (FUNVECP (obj) || VECTORP (obj))
{
register struct Lisp_Vector *vec;
- register int i;
+ register EMACS_INT i;
EMACS_INT size;
size = XVECTOR (obj)->size;
@@ -5283,8 +5295,8 @@ static int mark_object_loop_halt;
static void
mark_vectorlike (struct Lisp_Vector *ptr)
{
- register EMACS_INT size = ptr->size;
- register int i;
+ register EMACS_UINT size = ptr->size;
+ register EMACS_UINT i;
eassert (!VECTOR_MARKED_P (ptr));
VECTOR_MARK (ptr); /* Else mark it */
@@ -5306,8 +5318,8 @@ mark_vectorlike (struct Lisp_Vector *ptr)
static void
mark_char_table (struct Lisp_Vector *ptr)
{
- register EMACS_INT size = ptr->size & PSEUDOVECTOR_SIZE_MASK;
- register int i;
+ register EMACS_UINT size = ptr->size & PSEUDOVECTOR_SIZE_MASK;
+ register EMACS_UINT i;
eassert (!VECTOR_MARKED_P (ptr));
VECTOR_MARK (ptr);
@@ -5436,8 +5448,8 @@ mark_object (Lisp_Object arg)
recursion there. */
{
register struct Lisp_Vector *ptr = XVECTOR (obj);
- register EMACS_INT size = ptr->size;
- register int i;
+ register EMACS_UINT size = ptr->size;
+ register EMACS_UINT i;
CHECK_LIVE (live_vector_p);
VECTOR_MARK (ptr); /* Else mark it */