diff --git a/src/yaep.c b/src/yaep.c index b553e3c..03b0ac8 100644 --- a/src/yaep.c +++ b/src/yaep.c @@ -6341,24 +6341,24 @@ yaep_free_tree (struct yaep_tree_node *root, void (*parse_free) (void *), #ifdef YAEP_TEST -/* All parse_alloc memory is contained here. */ -#ifndef __cplusplus -static os_t mem_os; -#else -static os_t *mem_os; -#endif - static void * test_parse_alloc (int size) { void *result; - OS_TOP_EXPAND (mem_os, size); - result = OS_TOP_BEGIN (mem_os); - OS_TOP_FINISH (mem_os); + assert ((size > 0) && ((unsigned int) size == (size_t) size)); + result = malloc (size); + assert (result != NULL); + return result; } +static void +test_parse_free (void * mem) +{ + free( mem ); +} + /* The following variable is the current number of next input grammar terminal. */ static int nterm; @@ -6509,7 +6509,6 @@ use_functions (int argc, char **argv) fprintf (stderr, "No memory\n"); exit (1); } - OS_CREATE (mem_os, grammar->alloc, 0); yaep_set_one_parse_flag (g, FALSE); if (argc > 1) yaep_set_lookahead_level (g, atoi (argv[1])); @@ -6524,14 +6523,12 @@ use_functions (int argc, char **argv) if (yaep_read_grammar (g, TRUE, read_terminal, read_rule) != 0) { fprintf (stderr, "%s\n", yaep_error_message (g)); - OS_DELETE (mem_os); exit (1); } ntok = 0; if (yaep_parse (g, test_read_token, test_syntax_error, test_parse_alloc, - NULL, &root, &ambiguous_p)) + test_parse_free, &root, &ambiguous_p)) fprintf (stderr, "yaep_parse: %s\n", yaep_error_message (g)); - OS_DELETE (mem_os); yaep_free_grammar (g); } #endif @@ -6563,7 +6560,6 @@ use_description (int argc, char **argv) fprintf (stderr, "yaep_create_grammar: No memory\n"); exit (1); } - OS_CREATE (mem_os, grammar->alloc, 0); yaep_set_one_parse_flag (g, FALSE); if (argc > 1) yaep_set_lookahead_level (g, atoi (argv[1])); @@ -6578,13 +6574,11 @@ use_description (int argc, char **argv) if (yaep_parse_grammar (g, TRUE, description) != 0) { fprintf (stderr, "%s\n", yaep_error_message (g)); - OS_DELETE (mem_os); exit (1); } if (yaep_parse (g, test_read_token, test_syntax_error, test_parse_alloc, - NULL, &root, &ambiguous_p)) + test_parse_free, &root, &ambiguous_p)) fprintf (stderr, "yaep_parse: %s\n", yaep_error_message (g)); - OS_DELETE (mem_os); yaep_free_grammar (g); } #endif diff --git a/src/yaep.cpp b/src/yaep.cpp index e7c0091..d76e741 100644 --- a/src/yaep.cpp +++ b/src/yaep.cpp @@ -182,19 +182,12 @@ use_functions (int argc, char **argv) struct yaep_tree_node *root; int ambiguous_p; - YaepAllocator *alloc = yaep_alloc_new (NULL, NULL, NULL, NULL); - if (alloc == NULL) - { - exit (1); - } nterm = nrule = 0; - OS_CREATE (mem_os, alloc, 0); fprintf (stderr, "Use functions\n"); e = new yaep (); if (e == NULL) { fprintf (stderr, "yaep::yaep: No memory\n"); - OS_DELETE (mem_os); exit (1); } e->set_one_parse_flag (FALSE); @@ -211,16 +204,13 @@ use_functions (int argc, char **argv) if (e->read_grammar (TRUE, read_terminal, read_rule) != 0) { fprintf (stderr, "%s\n", e->error_message ()); - OS_DELETE (mem_os); exit (1); } ntok = 0; - if (e->parse (test_read_token, test_syntax_error, test_parse_alloc, NULL, - &root, &ambiguous_p)) + if (e->parse (test_read_token, test_syntax_error, test_parse_alloc, + test_parse_free, &root, &ambiguous_p)) fprintf (stderr, "yaep parse: %s\n", e->error_message ()); delete e; - OS_DELETE (mem_os); - yaep_alloc_del (alloc); } static void @@ -230,18 +220,11 @@ use_description (int argc, char **argv) struct yaep_tree_node *root; int ambiguous_p; - YaepAllocator *alloc = yaep_alloc_new (NULL, NULL, NULL, NULL); - if (alloc == NULL) - { - exit (1); - } fprintf (stderr, "Use description\n"); - OS_CREATE (mem_os, alloc, 0); e = new yaep (); if (e == NULL) { fprintf (stderr, "yaep::yaep: No memory\n"); - OS_DELETE (mem_os); exit (1); } e->set_one_parse_flag (FALSE); @@ -258,15 +241,12 @@ use_description (int argc, char **argv) if (e->parse_grammar (TRUE, description) != 0) { fprintf (stderr, "%s\n", e->error_message ()); - OS_DELETE (mem_os); exit (1); } - if (e->parse (test_read_token, test_syntax_error, test_parse_alloc, NULL, - &root, &ambiguous_p)) + if (e->parse (test_read_token, test_syntax_error, test_parse_alloc, + test_parse_free, &root, &ambiguous_p)) fprintf (stderr, "yaep::parse: %s\n", e->error_message ()); delete e; - OS_DELETE (mem_os); - yaep_alloc_del (alloc); } #endif /* #ifdef YAEP_TEST */