summaryrefslogtreecommitdiff
path: root/s_expression.cpp
diff options
context:
space:
mode:
authorCarl Worth <cworth@cworth.org>2010-06-23 18:11:51 -0700
committerCarl Worth <cworth@cworth.org>2010-06-23 18:59:35 -0700
commit1660a2954797e056caba319c5d6c70b0d4be22fe (patch)
tree172af2dd8effb58c89828b917cae850058312edd /s_expression.cpp
parent8f52c9b5fcbc73ed12b23253caa44c28fd4452e2 (diff)
exec_node: Add new talloc-based new()
And fix all callers to use the tallbac-based new for exec_node construction. We make ready use of talloc_parent in order to get valid, (and appropriate) talloc owners for everything we construct without having to add new 'ctx' parameters up and down all the call trees. This closes the majority of the memory leaks in the glsl-orangebook-ch06-bump.frag test: total heap usage: 55,623 allocs, 42,672 frees (was 14,533 frees) Now 76.7% leak-free. Woo-hoo!
Diffstat (limited to 's_expression.cpp')
-rw-r--r--s_expression.cpp16
1 files changed, 8 insertions, 8 deletions
diff --git a/s_expression.cpp b/s_expression.cpp
index 0fb296e..875d739 100644
--- a/s_expression.cpp
+++ b/s_expression.cpp
@@ -49,7 +49,7 @@ s_list::length() const
}
static s_expression *
-read_atom(const char *& src)
+read_atom(void *ctx, const char *& src)
{
char buf[101];
int n;
@@ -65,20 +65,20 @@ read_atom(const char *& src)
int i = strtol(buf, &int_end, 10);
// If strtod matched more characters, it must have a decimal part
if (float_end > int_end)
- return new s_float(f);
+ return new(ctx) s_float(f);
- return new s_int(i);
+ return new(ctx) s_int(i);
}
// Not a number; return a symbol.
- return new s_symbol(buf);
+ return new(ctx) s_symbol(buf);
}
s_expression *
-s_expression::read_expression(const char *&src)
+s_expression::read_expression(void *ctx, const char *&src)
{
assert(src != NULL);
- s_expression *atom = read_atom(src);
+ s_expression *atom = read_atom(ctx, src);
if (atom != NULL)
return atom;
@@ -87,10 +87,10 @@ s_expression::read_expression(const char *&src)
if (sscanf(src, " %c%n", &c, &n) == 1 && c == '(') {
src += n;
- s_list *list = new s_list;
+ s_list *list = new(ctx) s_list;
s_expression *expr;
- while ((expr = read_expression(src)) != NULL) {
+ while ((expr = read_expression(ctx, src)) != NULL) {
list->subexpressions.push_tail(expr);
}
if (sscanf(src, " %c%n", &c, &n) != 1 || c != ')') {