[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] Changes to emacs/src/fns.c [lexbind]
From: |
Miles Bader |
Subject: |
[Emacs-diffs] Changes to emacs/src/fns.c [lexbind] |
Date: |
Tue, 06 Jul 2004 07:00:42 -0400 |
Index: emacs/src/fns.c
diff -c emacs/src/fns.c:1.314.2.11 emacs/src/fns.c:1.314.2.12
*** emacs/src/fns.c:1.314.2.11 Tue Jul 6 10:17:20 2004
--- emacs/src/fns.c Tue Jul 6 10:20:31 2004
***************
*** 994,999 ****
--- 994,1001 ----
{
unsigned char *buf;
int nbytes;
+ Lisp_Object ret;
+ USE_SAFE_ALLOCA;
if (STRING_MULTIBYTE (string))
return string;
***************
*** 1005,1015 ****
if (nbytes == SBYTES (string))
return string;
! buf = (unsigned char *) alloca (nbytes);
copy_text (SDATA (string), buf, SBYTES (string),
0, 1);
! return make_multibyte_string (buf, SCHARS (string), nbytes);
}
--- 1007,1020 ----
if (nbytes == SBYTES (string))
return string;
! SAFE_ALLOCA (buf, unsigned char *, nbytes);
copy_text (SDATA (string), buf, SBYTES (string),
0, 1);
! ret = make_multibyte_string (buf, SCHARS (string), nbytes);
! SAFE_FREE (nbytes);
!
! return ret;
}
***************
*** 1024,1029 ****
--- 1029,1036 ----
{
unsigned char *buf;
int nbytes;
+ Lisp_Object ret;
+ USE_SAFE_ALLOCA;
if (STRING_MULTIBYTE (string))
return string;
***************
*** 1034,1044 ****
if (nbytes == SBYTES (string))
return make_multibyte_string (SDATA (string), nbytes, nbytes);
! buf = (unsigned char *) alloca (nbytes);
bcopy (SDATA (string), buf, SBYTES (string));
str_to_multibyte (buf, nbytes, SBYTES (string));
! return make_multibyte_string (buf, SCHARS (string), nbytes);
}
--- 1041,1054 ----
if (nbytes == SBYTES (string))
return make_multibyte_string (SDATA (string), nbytes, nbytes);
! SAFE_ALLOCA (buf, unsigned char *, nbytes);
bcopy (SDATA (string), buf, SBYTES (string));
str_to_multibyte (buf, nbytes, SBYTES (string));
! ret = make_multibyte_string (buf, SCHARS (string), nbytes);
! SAFE_FREE (nbytes);
!
! return ret;
}
***************
*** 1048,1070 ****
string_make_unibyte (string)
Lisp_Object string;
{
unsigned char *buf;
Lisp_Object ret;
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));
copy_text (SDATA (string), buf, SBYTES (string),
1, 0);
! ret = make_unibyte_string (buf, SCHARS (string));
!
! xfree (buf);
return ret;
}
--- 1058,1079 ----
string_make_unibyte (string)
Lisp_Object string;
{
+ int nchars;
unsigned char *buf;
Lisp_Object ret;
+ USE_SAFE_ALLOCA;
if (! STRING_MULTIBYTE (string))
return string;
! nchars = SCHARS (string);
+ SAFE_ALLOCA (buf, unsigned char *, nchars);
copy_text (SDATA (string), buf, SBYTES (string),
1, 0);
! ret = make_unibyte_string (buf, nchars);
! SAFE_FREE (nchars);
return ret;
}
***************
*** 2991,3003 ****
register Lisp_Object *args;
register int i;
struct gcpro gcpro1;
len = Flength (sequence);
leni = XINT (len);
nargs = leni + leni - 1;
if (nargs < 0) return build_string ("");
! args = (Lisp_Object *) alloca (nargs * sizeof (Lisp_Object));
GCPRO1 (separator);
mapcar1 (leni, args, function, sequence);
--- 3000,3014 ----
register Lisp_Object *args;
register int i;
struct gcpro gcpro1;
+ Lisp_Object ret;
+ USE_SAFE_ALLOCA;
len = Flength (sequence);
leni = XINT (len);
nargs = leni + leni - 1;
if (nargs < 0) return build_string ("");
! SAFE_ALLOCA_LISP (args, nargs);
GCPRO1 (separator);
mapcar1 (leni, args, function, sequence);
***************
*** 3009,3015 ****
for (i = 1; i < nargs; i += 2)
args[i] = separator;
! return Fconcat (nargs, args);
}
DEFUN ("mapcar", Fmapcar, Smapcar, 2, 2, 0,
--- 3020,3033 ----
for (i = 1; i < nargs; i += 2)
args[i] = separator;
! GCPRO1 (*args);
! gcpro1.nvars = nargs;
! ret = Fconcat (nargs, args);
! UNGCPRO;
!
! SAFE_FREE_LISP (nargs);
!
! return ret;
}
DEFUN ("mapcar", Fmapcar, Smapcar, 2, 2, 0,
***************
*** 3022,3035 ****
register Lisp_Object len;
register int leni;
register Lisp_Object *args;
len = Flength (sequence);
leni = XFASTINT (len);
! args = (Lisp_Object *) alloca (leni * sizeof (Lisp_Object));
mapcar1 (leni, args, function, sequence);
! return Flist (leni, args);
}
DEFUN ("mapc", Fmapc, Smapc, 2, 2, 0,
--- 3040,3064 ----
register Lisp_Object len;
register int leni;
register Lisp_Object *args;
+ struct gcpro gcpro1;
+ Lisp_Object ret;
+ USE_SAFE_ALLOCA;
len = Flength (sequence);
leni = XFASTINT (len);
!
! SAFE_ALLOCA_LISP (args, leni);
mapcar1 (leni, args, function, sequence);
! GCPRO1 (*args);
! gcpro1.nvars = leni;
! ret = Flist (leni, args);
! UNGCPRO;
!
! SAFE_FREE_LISP (leni);
!
! return ret;
}
DEFUN ("mapc", Fmapc, Smapc, 2, 2, 0,
***************
*** 3644,3653 ****
} \
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] =
{
--- 3673,3678 ----
***************
*** 3713,3718 ****
--- 3738,3744 ----
int allength, length;
int ibeg, iend, encoded_length;
int old_pos = PT;
+ USE_SAFE_ALLOCA;
validate_region (&beg, &end);
***************
*** 3727,3736 ****
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);
encoded_length = base64_encode_1 (BYTE_POS_ADDR (ibeg), encoded, length,
NILP (no_line_break),
!NILP
(current_buffer->enable_multibyte_characters));
--- 3753,3759 ----
allength = length + length/3 + 1;
allength += allength / MIME_LINE_LENGTH + 1 + 6;
! 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));
***************
*** 3740,3747 ****
if (encoded_length < 0)
{
/* The encoding wasn't possible. */
! if (length > MAX_ALLOCA)
! xfree (encoded);
error ("Multibyte character in data for base64 encoding");
}
--- 3763,3769 ----
if (encoded_length < 0)
{
/* The encoding wasn't possible. */
! SAFE_FREE (allength);
error ("Multibyte character in data for base64 encoding");
}
***************
*** 3749,3756 ****
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);
del_range_byte (ibeg + encoded_length, iend + encoded_length, 1);
/* If point was outside of the region, restore it exactly; else just
--- 3771,3777 ----
and delete the old. (Insert first in order to preserve markers.) */
SET_PT_BOTH (XFASTINT (beg), ibeg);
insert (encoded, encoded_length);
! 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
***************
*** 3776,3781 ****
--- 3797,3803 ----
int allength, length, encoded_length;
char *encoded;
Lisp_Object encoded_string;
+ USE_SAFE_ALLOCA;
CHECK_STRING (string);
***************
*** 3787,3796 ****
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);
encoded_length = base64_encode_1 (SDATA (string),
encoded, length, NILP (no_line_break),
--- 3809,3815 ----
allength += allength / MIME_LINE_LENGTH + 1 + 6;
/* We need to allocate enough room for decoding the text. */
! SAFE_ALLOCA (encoded, char *, allength);
encoded_length = base64_encode_1 (SDATA (string),
encoded, length, NILP (no_line_break),
***************
*** 3801,3814 ****
if (encoded_length < 0)
{
/* The encoding wasn't possible. */
! if (length > MAX_ALLOCA)
! xfree (encoded);
error ("Multibyte character in data for base64 encoding");
}
encoded_string = make_unibyte_string (encoded, encoded_length);
! if (allength > MAX_ALLOCA)
! xfree (encoded);
return encoded_string;
}
--- 3820,3831 ----
if (encoded_length < 0)
{
/* The encoding wasn't possible. */
! SAFE_FREE (allength);
error ("Multibyte character in data for base64 encoding");
}
encoded_string = make_unibyte_string (encoded, encoded_length);
! SAFE_FREE (allength);
return encoded_string;
}
***************
*** 3921,3926 ****
--- 3938,3944 ----
int decoded_length;
int inserted_chars;
int multibyte = !NILP (current_buffer->enable_multibyte_characters);
+ USE_SAFE_ALLOCA;
validate_region (&beg, &end);
***************
*** 3933,3942 ****
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);
move_gap_both (XFASTINT (beg), ibeg);
decoded_length = base64_decode_1 (BYTE_POS_ADDR (ibeg), decoded, length,
--- 3951,3957 ----
working on a multibyte buffer, each decoded code may occupy at
most two bytes. */
allength = multibyte ? length * 2 : length;
! SAFE_ALLOCA (decoded, char *, allength);
move_gap_both (XFASTINT (beg), ibeg);
decoded_length = base64_decode_1 (BYTE_POS_ADDR (ibeg), decoded, length,
***************
*** 3947,3954 ****
if (decoded_length < 0)
{
/* The decoding wasn't possible. */
! if (allength > MAX_ALLOCA)
! xfree (decoded);
error ("Invalid base64 data");
}
--- 3962,3968 ----
if (decoded_length < 0)
{
/* The decoding wasn't possible. */
! SAFE_FREE (allength);
error ("Invalid base64 data");
}
***************
*** 3956,3963 ****
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);
/* Delete the original text. */
del_range_both (PT, PT_BYTE, XFASTINT (end) + inserted_chars,
iend + decoded_length, 1);
--- 3970,3977 ----
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);
! SAFE_FREE (allength);
!
/* Delete the original text. */
del_range_both (PT, PT_BYTE, XFASTINT (end) + inserted_chars,
iend + decoded_length, 1);
***************
*** 3982,3996 ****
char *decoded;
int length, decoded_length;
Lisp_Object decoded_string;
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);
/* The decoded result should be unibyte. */
decoded_length = base64_decode_1 (SDATA (string), decoded, length,
--- 3996,4008 ----
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. */
! SAFE_ALLOCA (decoded, char *, length);
/* The decoded result should be unibyte. */
decoded_length = base64_decode_1 (SDATA (string), decoded, length,
***************
*** 4002,4009 ****
else
decoded_string = Qnil;
! if (length > MAX_ALLOCA)
! xfree (decoded);
if (!STRINGP (decoded_string))
error ("Invalid base64 data");
--- 4014,4020 ----
else
decoded_string = Qnil;
! SAFE_FREE (length);
if (!STRINGP (decoded_string))
error ("Invalid base64 data");