1983 |
} |
} |
1984 |
} |
} |
1985 |
|
|
|
/* Don't use alloca for relocating string data larger than this, lest |
|
|
we overflow their stack. The value is the same as what used in |
|
|
fns.c for base64 handling. */ |
|
|
#define MAX_ALLOCA 16*1024 |
|
|
|
|
1986 |
DEFUN ("aset", Faset, Saset, 3, 3, 0, |
DEFUN ("aset", Faset, Saset, 3, 3, 0, |
1987 |
doc: /* Store into the element of ARRAY at index IDX the value NEWELT. |
doc: /* Store into the element of ARRAY at index IDX the value NEWELT. |
1988 |
Return NEWELT. ARRAY may be a vector, a string, a char-table or a |
Return NEWELT. ARRAY may be a vector, a string, a char-table or a |
2046 |
/* We must relocate the string data. */ |
/* We must relocate the string data. */ |
2047 |
int nchars = SCHARS (array); |
int nchars = SCHARS (array); |
2048 |
unsigned char *str; |
unsigned char *str; |
2049 |
|
USE_SAFE_ALLOCA; |
2050 |
|
|
2051 |
str = (nbytes <= MAX_ALLOCA |
SAFE_ALLOCA (str, unsigned char *, nbytes); |
|
? (unsigned char *) alloca (nbytes) |
|
|
: (unsigned char *) xmalloc (nbytes)); |
|
2052 |
bcopy (SDATA (array), str, nbytes); |
bcopy (SDATA (array), str, nbytes); |
2053 |
allocate_string_data (XSTRING (array), nchars, |
allocate_string_data (XSTRING (array), nchars, |
2054 |
nbytes + new_bytes - prev_bytes); |
nbytes + new_bytes - prev_bytes); |
2056 |
p1 = SDATA (array) + idxval_byte; |
p1 = SDATA (array) + idxval_byte; |
2057 |
bcopy (str + idxval_byte + prev_bytes, p1 + new_bytes, |
bcopy (str + idxval_byte + prev_bytes, p1 + new_bytes, |
2058 |
nbytes - (idxval_byte + prev_bytes)); |
nbytes - (idxval_byte + prev_bytes)); |
2059 |
if (nbytes > MAX_ALLOCA) |
SAFE_FREE (nbytes); |
|
xfree (str); |
|
2060 |
clear_string_char_byte_cache (); |
clear_string_char_byte_cache (); |
2061 |
} |
} |
2062 |
while (new_bytes--) |
while (new_bytes--) |
2079 |
unsigned char workbuf[MAX_MULTIBYTE_LENGTH], *p0 = workbuf, *p1; |
unsigned char workbuf[MAX_MULTIBYTE_LENGTH], *p0 = workbuf, *p1; |
2080 |
unsigned char *origstr = SDATA (array), *str; |
unsigned char *origstr = SDATA (array), *str; |
2081 |
int nchars, nbytes; |
int nchars, nbytes; |
2082 |
|
USE_SAFE_ALLOCA; |
2083 |
|
|
2084 |
nchars = SCHARS (array); |
nchars = SCHARS (array); |
2085 |
nbytes = idxval_byte = count_size_as_multibyte (origstr, idxval); |
nbytes = idxval_byte = count_size_as_multibyte (origstr, idxval); |
2086 |
nbytes += count_size_as_multibyte (origstr + idxval, |
nbytes += count_size_as_multibyte (origstr + idxval, |
2087 |
nchars - idxval); |
nchars - idxval); |
2088 |
str = (nbytes <= MAX_ALLOCA |
SAFE_ALLOCA (str, unsigned char *, nbytes); |
|
? (unsigned char *) alloca (nbytes) |
|
|
: (unsigned char *) xmalloc (nbytes)); |
|
2089 |
copy_text (SDATA (array), str, nchars, 0, 1); |
copy_text (SDATA (array), str, nchars, 0, 1); |
2090 |
PARSE_MULTIBYTE_SEQ (str + idxval_byte, nbytes - idxval_byte, |
PARSE_MULTIBYTE_SEQ (str + idxval_byte, nbytes - idxval_byte, |
2091 |
prev_bytes); |
prev_bytes); |
2098 |
*p1++ = *p0++; |
*p1++ = *p0++; |
2099 |
bcopy (str + idxval_byte + prev_bytes, p1, |
bcopy (str + idxval_byte + prev_bytes, p1, |
2100 |
nbytes - (idxval_byte + prev_bytes)); |
nbytes - (idxval_byte + prev_bytes)); |
2101 |
if (nbytes > MAX_ALLOCA) |
SAFE_FREE (nbytes); |
|
xfree (str); |
|
2102 |
clear_string_char_byte_cache (); |
clear_string_char_byte_cache (); |
2103 |
} |
} |
2104 |
} |
} |