Mercurial > emacs
diff src/fns.c @ 89945:59dcbfe97385
Revision: miles@gnu.org--gnu-2004/emacs--unicode--0--patch-17
Merge from emacs--cvs-trunk--0
Patches applied:
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-417
- miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-419
Update from CVS
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-420
Tweak permissions
* miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-421
- miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-430
Update from CVS
author | Miles Bader <miles@gnu.org> |
---|---|
date | Tue, 29 Jun 2004 16:46:06 +0000 |
parents | 4c90ffeb71c5 98133cccc0cc |
children | 8282359ed212 |
line wrap: on
line diff
--- a/src/fns.c Tue Jun 29 15:25:11 2004 +0000 +++ b/src/fns.c Tue Jun 29 16:46:06 2004 +0000 @@ -929,11 +929,14 @@ if (nbytes == SBYTES (string)) return string; - buf = (unsigned char *) alloca (nbytes); + SAFE_ALLOCA (buf, unsigned char *, nbytes); copy_text (SDATA (string), buf, SBYTES (string), 0, 1); - return make_multibyte_string (buf, SCHARS (string), nbytes); + ret = make_multibyte_string (buf, SCHARS (string), nbytes); + SAFE_FREE (nbytes); + + return ret; } @@ -947,6 +950,8 @@ { unsigned char *buf; int nbytes; + Lisp_Object ret; + USE_SAFE_ALLOCA; if (STRING_MULTIBYTE (string)) return string; @@ -957,11 +962,14 @@ if (nbytes == SBYTES (string)) return make_multibyte_string (SDATA (string), nbytes, nbytes); - buf = (unsigned char *) alloca (nbytes); + SAFE_ALLOCA (buf, unsigned char *, nbytes); bcopy (SDATA (string), buf, SBYTES (string)); str_to_multibyte (buf, nbytes, SBYTES (string)); - return make_multibyte_string (buf, SCHARS (string), nbytes); + ret = make_multibyte_string (buf, SCHARS (string), nbytes); + SAFE_FREE (nbytes); + + return ret; } @@ -971,23 +979,22 @@ string_make_unibyte (string) Lisp_Object string; { + int nchars; unsigned char *buf; Lisp_Object ret; + USE_SAFE_ALLOCA; if (! STRING_MULTIBYTE (string)) return string; - /* We can not use alloca here, because string might be very long. - For example when selecting megabytes of text and then pasting it to - another application. */ - buf = (unsigned char *) xmalloc (SCHARS (string)); - + nchars = SCHARS (string); + + SAFE_ALLOCA (buf, unsigned char *, nchars); copy_text (SDATA (string), buf, SBYTES (string), 1, 0); - ret = make_unibyte_string (buf, SCHARS (string)); - - xfree (buf); + ret = make_unibyte_string (buf, nchars); + SAFE_FREE (nchars); return ret; } @@ -2455,6 +2462,8 @@ register Lisp_Object *args; register int i; struct gcpro gcpro1; + Lisp_Object ret; + USE_SAFE_ALLOCA; len = Flength (sequence); if (CHAR_TABLE_P (sequence)) @@ -2463,7 +2472,7 @@ nargs = leni + leni - 1; if (nargs < 0) return build_string (""); - args = (Lisp_Object *) alloca (nargs * sizeof (Lisp_Object)); + SAFE_ALLOCA_LISP (args, nargs); GCPRO1 (separator); mapcar1 (leni, args, function, sequence); @@ -2475,7 +2484,10 @@ for (i = 1; i < nargs; i += 2) args[i] = separator; - return Fconcat (nargs, args); + ret = Fconcat (nargs, args); + SAFE_FREE_LISP (nargs); + + return ret; } DEFUN ("mapcar", Fmapcar, Smapcar, 2, 2, 0, @@ -2488,16 +2500,22 @@ register Lisp_Object len; register int leni; register Lisp_Object *args; + Lisp_Object ret; + USE_SAFE_ALLOCA; len = Flength (sequence); if (CHAR_TABLE_P (sequence)) wrong_type_argument (Qlistp, sequence); leni = XFASTINT (len); - args = (Lisp_Object *) alloca (leni * sizeof (Lisp_Object)); + + SAFE_ALLOCA_LISP (args, leni); mapcar1 (leni, args, function, sequence); - return Flist (leni, args); + ret = Flist (leni, args); + SAFE_FREE_LISP (leni); + + return ret; } DEFUN ("mapc", Fmapc, Smapc, 2, 2, 0, @@ -3114,10 +3132,6 @@ } \ while (IS_BASE64_IGNORABLE (c)) -/* Don't use alloca for regions larger than this, lest we overflow - their stack. */ -#define MAX_ALLOCA 16*1024 - /* Table of characters coding the 64 values. */ static char base64_value_to_char[64] = { @@ -3183,6 +3197,7 @@ int allength, length; int ibeg, iend, encoded_length; int old_pos = PT; + USE_SAFE_ALLOCA; validate_region (&beg, &end); @@ -3197,10 +3212,7 @@ allength = length + length/3 + 1; allength += allength / MIME_LINE_LENGTH + 1 + 6; - if (allength <= MAX_ALLOCA) - encoded = (char *) alloca (allength); - else - encoded = (char *) xmalloc (allength); + SAFE_ALLOCA (encoded, char *, allength); encoded_length = base64_encode_1 (BYTE_POS_ADDR (ibeg), encoded, length, NILP (no_line_break), !NILP (current_buffer->enable_multibyte_characters)); @@ -3210,8 +3222,7 @@ if (encoded_length < 0) { /* The encoding wasn't possible. */ - if (length > MAX_ALLOCA) - xfree (encoded); + SAFE_FREE (allength); error ("Multibyte character in data for base64 encoding"); } @@ -3219,8 +3230,7 @@ and delete the old. (Insert first in order to preserve markers.) */ SET_PT_BOTH (XFASTINT (beg), ibeg); insert (encoded, encoded_length); - if (allength > MAX_ALLOCA) - xfree (encoded); + SAFE_FREE (allength); del_range_byte (ibeg + encoded_length, iend + encoded_length, 1); /* If point was outside of the region, restore it exactly; else just @@ -3246,6 +3256,7 @@ int allength, length, encoded_length; char *encoded; Lisp_Object encoded_string; + USE_SAFE_ALLOCA; CHECK_STRING (string); @@ -3257,10 +3268,7 @@ allength += allength / MIME_LINE_LENGTH + 1 + 6; /* We need to allocate enough room for decoding the text. */ - if (allength <= MAX_ALLOCA) - encoded = (char *) alloca (allength); - else - encoded = (char *) xmalloc (allength); + SAFE_ALLOCA (encoded, char *, allength); encoded_length = base64_encode_1 (SDATA (string), encoded, length, NILP (no_line_break), @@ -3271,14 +3279,12 @@ if (encoded_length < 0) { /* The encoding wasn't possible. */ - if (length > MAX_ALLOCA) - xfree (encoded); + SAFE_FREE (allength); error ("Multibyte character in data for base64 encoding"); } encoded_string = make_unibyte_string (encoded, encoded_length); - if (allength > MAX_ALLOCA) - xfree (encoded); + SAFE_FREE (allength); return encoded_string; } @@ -3397,6 +3403,7 @@ int decoded_length; int inserted_chars; int multibyte = !NILP (current_buffer->enable_multibyte_characters); + USE_SAFE_ALLOCA; validate_region (&beg, &end); @@ -3409,10 +3416,7 @@ working on a multibyte buffer, each decoded code may occupy at most two bytes. */ allength = multibyte ? length * 2 : length; - if (allength <= MAX_ALLOCA) - decoded = (char *) alloca (allength); - else - decoded = (char *) xmalloc (allength); + SAFE_ALLOCA (decoded, char *, allength); move_gap_both (XFASTINT (beg), ibeg); decoded_length = base64_decode_1 (BYTE_POS_ADDR (ibeg), decoded, length, @@ -3423,8 +3427,7 @@ if (decoded_length < 0) { /* The decoding wasn't possible. */ - if (allength > MAX_ALLOCA) - xfree (decoded); + SAFE_FREE (allength); error ("Invalid base64 data"); } @@ -3432,8 +3435,8 @@ and delete the old. (Insert first in order to preserve markers.) */ TEMP_SET_PT_BOTH (XFASTINT (beg), ibeg); insert_1_both (decoded, inserted_chars, decoded_length, 0, 1, 0); - if (allength > MAX_ALLOCA) - xfree (decoded); + SAFE_FREE (allength); + /* Delete the original text. */ del_range_both (PT, PT_BYTE, XFASTINT (end) + inserted_chars, iend + decoded_length, 1); @@ -3458,15 +3461,13 @@ char *decoded; int length, decoded_length; Lisp_Object decoded_string; + USE_SAFE_ALLOCA; CHECK_STRING (string); length = SBYTES (string); /* We need to allocate enough room for decoding the text. */ - if (length <= MAX_ALLOCA) - decoded = (char *) alloca (length); - else - decoded = (char *) xmalloc (length); + SAFE_ALLOCA (decoded, char *, length); /* The decoded result should be unibyte. */ decoded_length = base64_decode_1 (SDATA (string), decoded, length, @@ -3478,8 +3479,7 @@ else decoded_string = Qnil; - if (length > MAX_ALLOCA) - xfree (decoded); + SAFE_FREE (length); if (!STRINGP (decoded_string)) error ("Invalid base64 data");