From 20bec5ff6a3bfb4ffa7ae475f762a20ac42df41b Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sun, 3 Oct 2010 21:41:28 -0700 Subject: * lib.h (lazy_string): Fix incorrect comment. * lib.c (split_str, split_str_set): It is necessary to protect input parameters against GC, because we cache their internal pointers, after which we no longer refer to the objects themselves. Moreover, we perform object allocation, and then keep using the internal pointers. --- ChangeLog | 10 ++++++++++ lib.c | 12 ++++++++++++ lib.h | 2 +- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index ee4b19cd..6ec76f4d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2010-10-03 Kaz Kylheku + + * lib.h (lazy_string): Fix incorrect comment. + + * lib.c (split_str, split_str_set): It is necessary to protect input + parameters against GC, because we cache their internal pointers, + after which we no longer refer to the objects themselves. Moreover, + we perform object allocation, and then keep using the internal + pointers. + 2010-09-30 Kaz Kylheku * txr.1: Fix formatting problem. diff --git a/lib.c b/lib.c index 99edd835..4d3c511a 100644 --- a/lib.c +++ b/lib.c @@ -999,6 +999,9 @@ val split_str(val str, val sep) const wchar_t *csep = c_str(sep); size_t len_sep = c_num(length_str(sep)); + prot1(&str); + prot1(&sep); + list_collect_decl (out, iter); for (; *cstr != 0; cstr += len_sep) { @@ -1010,6 +1013,9 @@ val split_str(val str, val sep) cstr += span; } + rel1(&sep); + rel1(&str); + return out; } @@ -1019,6 +1025,9 @@ val split_str_set(val str, val set) const wchar_t *cset = c_str(set); list_collect_decl (out, iter); + prot1(&str); + prot1(&set); + for (; *cstr != 0; cstr++) { size_t span = wcscspn(cstr, cset); val piece = mkustring(num(span)); @@ -1027,6 +1036,9 @@ val split_str_set(val str, val set) cstr += span; } + rel1(&set); + rel1(&str); + return out; } diff --git a/lib.h b/lib.h index 233e4a0a..f1022c67 100644 --- a/lib.h +++ b/lib.h @@ -137,7 +137,7 @@ struct lazy_string { type_t type; val prefix; /* actual string part */ val list; /* remaining list */ - val opts; /* ( limit . sepstring ) */ + val opts; /* ( separator . limit ) */ }; struct cobj { -- cgit v1.2.3