summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2014-10-04 08:14:31 -0700
committerKaz Kylheku <kaz@kylheku.com>2014-10-04 08:14:31 -0700
commita9d41d03d13b369118a5e12a42898d8af894107f (patch)
treed9eba0488a37905ce983bc977393d3e35d798321
parent972fd2cff9ff7e3981acc4c3807a529e1b40d0bf (diff)
downloadtxr-a9d41d03d13b369118a5e12a42898d8af894107f.tar.gz
txr-a9d41d03d13b369118a5e12a42898d8af894107f.tar.bz2
txr-a9d41d03d13b369118a5e12a42898d8af894107f.zip
Keep regex source code in regex objects, in anticipation
of pretty-printing. Fix object construction bugs. * regex.c (struct regex): New member, source. (regex_mark): Ensure source is visited by garbage collector. (regex_compile): Store regex_sexp in source. Fix violations of section 3.2 of HACKING document.
-rw-r--r--ChangeLog10
-rw-r--r--regex.c15
2 files changed, 23 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 9fb4c8ba..db72ecee 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2014-10-04 Kaz Kylheku <kaz@kylheku.com>
+
+ Keep regex source code in regex objects, in anticipation
+ of pretty-printing. Fix object construction bugs.
+
+ * regex.c (struct regex): New member, source.
+ (regex_mark): Ensure source is visited by garbage collector.
+ (regex_compile): Store regex_sexp in source.
+ Fix violations of section 3.2 of HACKING document.
+
2014-10-03 Kaz Kylheku <kaz@kylheku.com>
Eliminating the extra list wrapping applied to regular
diff --git a/regex.c b/regex.c
index 8c93c964..df07cf74 100644
--- a/regex.c
+++ b/regex.c
@@ -60,6 +60,7 @@ typedef struct regex {
struct nfa nfa;
val dv;
} r;
+ val source;
} regex_t;
/*
@@ -1301,6 +1302,7 @@ static void regex_mark(val obj)
regex_t *regex = (regex_t *) obj->co.handle;
if (regex->kind == REGEX_DV)
gc_mark(regex->r.dv);
+ gc_mark(regex->source);
}
static struct cobj_ops regex_obj_ops = {
@@ -1663,14 +1665,23 @@ val regex_compile(val regex_sexp, val error_stream)
return if2(regex_sexp, regex_compile(regex_sexp, error_stream));
} else if (opt_derivative_regex || regex_requires_dv(regex_sexp)) {
regex_t *regex = (regex_t *) chk_malloc(sizeof *regex);
+ val ret;
regex->kind = REGEX_DV;
+ regex->r.dv = nil;
+ regex->source = nil;
+ ret = cobj((mem_t *) regex, regex_s, &regex_obj_ops);
regex->r.dv = dv_compile_regex(regex_sexp);
- return cobj((mem_t *) regex, regex_s, &regex_obj_ops);
+ regex->source = regex_sexp;
+ return ret;
} else {
regex_t *regex = (regex_t *) chk_malloc(sizeof *regex);
+ val ret;
regex->kind = REGEX_NFA;
+ regex->source = nil;
+ ret = cobj((mem_t *) regex, regex_s, &regex_obj_ops);
regex->r.nfa = nfa_compile_regex(regex_sexp);
- return cobj((mem_t *) regex, regex_s, &regex_obj_ops);
+ regex->source = regex_sexp;
+ return ret;
}
}