diff options
author | Eric Anholt <eric@anholt.net> | 2010-06-24 15:13:03 -0700 |
---|---|---|
committer | Eric Anholt <eric@anholt.net> | 2010-06-24 15:13:03 -0700 |
commit | e33c10328caec29616a5433b1d1df9088f3a84df (patch) | |
tree | 723cc38803bb10032d28be9a9a161232d05d0fd1 /list.h | |
parent | 9290e0dd28e646c3dc810e0a6405582f8bf643b6 (diff) | |
parent | 26bbfb7917a71d46d9227bbf960606cb673636d3 (diff) |
Merge remote branch 'cworth/master'
Conflicts:
ast_to_hir.cpp
ir.cpp
This brings in the talloc-based memory management work, so that the
compiler (almost) no longer leaks memory.
Diffstat (limited to 'list.h')
-rw-r--r-- | list.h | 25 |
1 files changed, 25 insertions, 0 deletions
@@ -66,7 +66,13 @@ #ifndef __cplusplus #include <stddef.h> +#include <talloc.h> +#else +extern "C" { +#include <talloc.h> +} #endif + #include <assert.h> struct exec_node { @@ -74,6 +80,25 @@ struct exec_node { struct exec_node *prev; #ifdef __cplusplus + /* Callers of this talloc-based new need not call delete. It's + * easier to just talloc_free 'ctx' (or any of its ancestors). */ + static void* operator new(size_t size, void *ctx) + { + void *node; + + node = talloc_size(ctx, size); + assert(node != NULL); + + return node; + } + + /* If the user *does* call delete, that's OK, we will just + * talloc_free in that case. */ + static void operator delete(void *node) + { + talloc_free(node); + } + exec_node() : next(NULL), prev(NULL) { /* empty */ |