diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2014-08-25 19:40:46 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2014-08-25 19:40:46 -0700 |
commit | ce496a342712083526d424d965a6fa689b6b09cb (patch) | |
tree | 536e18bef4680100bd7fb9182939efaf490c3e88 /lib.c | |
parent | b8109c296982b8641a47f9cb6223b6102fef4b8c (diff) | |
download | txr-ce496a342712083526d424d965a6fa689b6b09cb.tar.gz txr-ce496a342712083526d424d965a6fa689b6b09cb.tar.bz2 txr-ce496a342712083526d424d965a6fa689b6b09cb.zip |
GC correctness fixes: make sure we pin down objects for which we borrow
low level C pointers, while we execute code that can cons memory.
* lib.c (list_str): Protect the str argument.
(int_str): Likewise.
* regex.c (search_regex): protect the haystack string,
while using the h pointer to its data, since regex_run
can use the derivative-based engine which conses.
* stream.c (vformat_str): Protect str argument, since
put_char might conceivably cons.
(vformat): Protect fmtstr.
Diffstat (limited to 'lib.c')
-rw-r--r-- | lib.c | 11 |
1 files changed, 9 insertions, 2 deletions
@@ -2729,8 +2729,14 @@ val list_str(val str) { const wchar_t *cstr = c_str(str); list_collect_decl (out, iter); + + prot1(&str); + while (*cstr) iter = list_collect(iter, chr(*cstr++)); + + rel1(&str); + return out; } @@ -2835,11 +2841,12 @@ val int_str(val str, val base) return nil; if ((value == LONG_MAX || value == LONG_MIN) && errno == ERANGE) { - val bignum = make_bignum(); + val bignum = (prot1(&str), make_bignum()); unsigned char *ucs = utf8_dup_to_uc(wcs); mp_err err = mp_read_radix(mp(bignum), ucs, b); free(ucs); /* TODO: make wchar_t version of mp_read_radix. */ + rel1(&str); if (err != MP_OKAY) return nil; @@ -2850,7 +2857,7 @@ val int_str(val str, val base) We do not need this on our usual target platforms, where NUM_MAX is never larger than LONG_MAX. */ return (LONG_MAX < NUM_MAX) ? normalize(bignum) : bignum; - } + } if (value >= NUM_MIN && value <= NUM_MAX) return num(value); |