diff options
Diffstat (limited to 's_expression.cpp')
-rw-r--r-- | s_expression.cpp | 35 |
1 files changed, 10 insertions, 25 deletions
diff --git a/s_expression.cpp b/s_expression.cpp index 4022dfab7a..26be23ea8f 100644 --- a/s_expression.cpp +++ b/s_expression.cpp @@ -30,29 +30,14 @@ s_symbol::s_symbol(const char *tmp) { - this->str = new char [strlen(tmp) + 1]; - strcpy(this->str, tmp); -} - -s_symbol::~s_symbol() -{ - delete [] this->str; - this->str = NULL; + this->str = talloc_strdup (this, tmp); + assert(this->str != NULL); } s_list::s_list() { } -s_list::~s_list() -{ - exec_list_iterator it(this->subexpressions.iterator()); - while (it.has_next()) - it.remove(); - - assert(this->subexpressions.is_empty()); -} - unsigned s_list::length() const { @@ -64,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; @@ -80,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; @@ -102,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 != ')') { |