diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2011-05-06 23:19:48 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2011-05-06 23:32:28 +0300 |
commit | 18d7db07b9f369901300bf664d07d4b39032ce64 (patch) | |
tree | a25c55b95491a507564b2f62a1c1abeebff636ad /src/grecs.h | |
parent | 352b268186931579ae8dcc6a19aaaa89547555f5 (diff) | |
download | grecs-18d7db07b9f369901300bf664d07d4b39032ce64.tar.gz grecs-18d7db07b9f369901300bf664d07d4b39032ce64.tar.bz2 |
Redo memory management (1).
* src/grecs-lex.l (grecs_lex_end): Free both lists.
Additional argument specifies if string data should be
freed as well (on error).
(grecs_value_dup): Don't append to string_list.
* src/grecs.h (grecs_value) <v.string>: Remove const qualifier.
<v.arg.v>: Array of struct grecs_value pointers.
(grecs_node)<value>: Move to the union v.
<v.texttab>: Text storage table (for grecs_node_root).
(grecs_lex_end): Fix prototype.
(grecs_value_list_create): New prototype.
(grecs_value_free: New prototype.
(grecs_value_dup): Rename to grecs_value_ptr_from_static.
* src/text.c (grecs_text_table): New function.
* src/tree.c (grecs_value_free): New function.
(grecs_node_free): Reimplement.
(grecs_tree_free): Rewrite using grecs_tree_recurse.
(grecs_string_convert): strdup string values.
(grecs_value_list_create): New function.
* tests/gcffmt.c: Call grecs_tree_free.
* tests/gcfpeek.c: Likewise.
* tests/gcfset.c: Likewise.
Diffstat (limited to 'src/grecs.h')
-rw-r--r-- | src/grecs.h | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/src/grecs.h b/src/grecs.h index 41f88d9..f6b88ab 100644 --- a/src/grecs.h +++ b/src/grecs.h @@ -105,10 +105,10 @@ typedef struct grecs_value { int type; union { struct grecs_list *list; - const char *string; + char *string; struct { size_t c; - struct grecs_value *v; + struct grecs_value **v; } arg; } v; } grecs_value_t; @@ -131,7 +131,10 @@ typedef struct grecs_node { struct grecs_node *next; struct grecs_node *prev; char *ident; - struct grecs_value value; + union { + struct grecs_value *value; + struct grecs_symtab *texttab; + } v; } grecs_node_t; typedef int (*grecs_callback_fn)( @@ -173,7 +176,7 @@ void *grecs_realloc(void *ptr, size_t size); void grecs_alloc_die(void); char *grecs_strdup(const char *str); -grecs_value_t *grecs_value_dup(grecs_value_t *input); +grecs_value_t *grecs_value_ptr_from_static(grecs_value_t *input); extern void (*grecs_print_diag_fun)(grecs_locus_t *, int, int, const char*); @@ -185,10 +188,11 @@ void grecs_gram_trace(int n); void grecs_lex_trace(int n); int grecs_lex_begin(const char*); -void grecs_lex_end(void); +void grecs_lex_end(int err); struct grecs_node *grecs_parse(const char *name); struct grecs_list *_grecs_simple_list_create(int dispose); +struct grecs_list *grecs_value_list_create(void); void grecs_line_begin(void); void grecs_line_add(const char *text, size_t len); @@ -227,6 +231,7 @@ void grecs_preproc_extrn_shutdown(pid_t pid); char *grecs_install_text(const char *str); void grecs_destroy_text(void); +struct grecs_symtab *grecs_text_table(void); void grecs_include_path_setup(const char *dir, ...); void grecs_include_path_setup_v(char **dirs); @@ -300,8 +305,9 @@ int grecs_symtab_enumerate(struct grecs_symtab *st, size_t grecs_symtab_count_entries(struct grecs_symtab *st); +void grecs_value_free(struct grecs_value *val); void grecs_node_free(struct grecs_node *node); -void grecs_tree_free(struct grecs_node *node); +int grecs_tree_free(struct grecs_node *node); enum grecs_tree_recurse_op { grecs_tree_recurse_set, |