forked from GitHub/gf-core
bug fix in the management of memory pools in the statistical parser
This commit is contained in:
@@ -1638,12 +1638,12 @@ pgf_parsing_default_beam_size(PgfConcr* concr)
|
||||
}
|
||||
|
||||
static PgfParsing*
|
||||
pgf_new_parsing(PgfConcr* concr, GuPool* pool)
|
||||
pgf_new_parsing(PgfConcr* concr, GuPool* pool, GuPool* out_pool)
|
||||
{
|
||||
PgfParsing* ps = gu_new(PgfParsing, pool);
|
||||
ps->concr = concr;
|
||||
ps->pool = pool;
|
||||
ps->out_pool = NULL;
|
||||
ps->out_pool = out_pool;
|
||||
ps->expr_queue = gu_new_buf(PgfExprState*, pool);
|
||||
ps->max_fid = concr->total_cats;
|
||||
#ifdef PGF_COUNTS_DEBUG
|
||||
@@ -1861,20 +1861,19 @@ pgf_parser_completions_next(GuEnum* self, void* to, GuPool* pool)
|
||||
}
|
||||
|
||||
GuEnum*
|
||||
pgf_parser_completions(PgfParseState* prev, GuString prefix,
|
||||
GuPool* pool)
|
||||
pgf_parser_completions(PgfParseState* prev, GuString prefix)
|
||||
{
|
||||
#ifdef PGF_COUNTS_DEBUG
|
||||
pgf_parsing_print_counts(prev->ps);
|
||||
#endif
|
||||
|
||||
PgfPrefixTokenState* ts =
|
||||
pgf_new_token_state(PgfPrefixTokenState, pool);
|
||||
pgf_new_token_state(PgfPrefixTokenState, prev->ps->pool);
|
||||
ts->en.next = pgf_parser_completions_next;
|
||||
ts->prefix = prefix;
|
||||
ts->tp = NULL;
|
||||
ts->state =
|
||||
pgf_new_parse_state(prev->ps, prev, &ts->ts, pool);
|
||||
pgf_new_parse_state(prev->ps, prev, &ts->ts, prev->ps->pool);
|
||||
|
||||
return &ts->en;
|
||||
}
|
||||
@@ -2101,18 +2100,16 @@ pgf_parse_result_enum_next(GuEnum* self, void* to, GuPool* pool)
|
||||
}
|
||||
|
||||
PgfExprEnum*
|
||||
pgf_parse_result(PgfParseState* state, GuPool* pool)
|
||||
pgf_parse_result(PgfParseState* state)
|
||||
{
|
||||
#ifdef PGF_COUNTS_DEBUG
|
||||
pgf_parsing_print_counts(state->ps);
|
||||
#endif
|
||||
|
||||
state->ps->out_pool = pool;
|
||||
|
||||
PgfExprEnum* en =
|
||||
&gu_new_i(pool, PgfParseResult,
|
||||
.state = state,
|
||||
.en.next = pgf_parse_result_enum_next)->en;
|
||||
&gu_new_i(state->ps->pool, PgfParseResult,
|
||||
.state = state,
|
||||
.en.next = pgf_parse_result_enum_next)->en;
|
||||
|
||||
return en;
|
||||
}
|
||||
@@ -2216,7 +2213,8 @@ pgf_parse_print_chunks(PgfParseState* state)
|
||||
|
||||
// TODO: s/CId/Cat, add the cid to Cat, make Cat the key to CncCat
|
||||
PgfParseState*
|
||||
pgf_parser_init_state(PgfConcr* concr, PgfCId cat, size_t lin_idx, GuPool* pool)
|
||||
pgf_parser_init_state(PgfConcr* concr, PgfCId cat, size_t lin_idx,
|
||||
GuPool* pool, GuPool* out_pool)
|
||||
{
|
||||
PgfCncCat* cnccat =
|
||||
gu_map_get(concr->cnccats, &cat, PgfCncCat*);
|
||||
@@ -2226,7 +2224,7 @@ pgf_parser_init_state(PgfConcr* concr, PgfCId cat, size_t lin_idx, GuPool* pool)
|
||||
gu_assert(lin_idx < cnccat->n_lins);
|
||||
|
||||
PgfParsing* ps =
|
||||
pgf_new_parsing(concr, pool);
|
||||
pgf_new_parsing(concr, pool, out_pool);
|
||||
PgfParseState* state =
|
||||
pgf_new_parse_state(ps, NULL, NULL, pool);
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ typedef struct PgfParseState PgfParseState;
|
||||
/// Begin parsing
|
||||
PgfParseState*
|
||||
pgf_parser_init_state(PgfConcr* concr, PgfCId cat, size_t lin_idx,
|
||||
GuPool* pool);
|
||||
GuPool* pool, GuPool* out_pool);
|
||||
/**<
|
||||
* @param parser The parser to use
|
||||
*
|
||||
@@ -67,8 +67,7 @@ pgf_parser_next_state(PgfParseState* prev, PgfToken tok);
|
||||
*/
|
||||
|
||||
GuEnum*
|
||||
pgf_parser_completions(PgfParseState* prev, GuString prefix,
|
||||
GuPool* pool);
|
||||
pgf_parser_completions(PgfParseState* prev, GuString prefix);
|
||||
|
||||
void
|
||||
pgf_parser_set_beam_size(PgfParseState* state, double beam_size);
|
||||
@@ -90,7 +89,7 @@ pgf_parser_add_literal(PgfConcr *concr, PgfCId cat,
|
||||
|
||||
/// Retrieve the current parses from the parse state.
|
||||
PgfExprEnum*
|
||||
pgf_parse_result(PgfParseState* state, GuPool* pool);
|
||||
pgf_parse_result(PgfParseState* state);
|
||||
/**<
|
||||
* @param parse A parse state
|
||||
*
|
||||
|
||||
@@ -157,7 +157,7 @@ pgf_parseval(PgfConcr* concr, PgfExpr expr, PgfCId cat,
|
||||
|
||||
PgfMetricsLznState state;
|
||||
state.funcs = &pgf_metrics_lin_funcs1;
|
||||
state.ps = pgf_parser_init_state(concr, cat, 0, pool);
|
||||
state.ps = pgf_parser_init_state(concr, cat, 0, pool, pool);
|
||||
state.marks = gu_new_buf(int, pool);
|
||||
state.pos = 0;
|
||||
state.phrases = gu_new_buf(PgfPhrase*, pool);
|
||||
@@ -172,7 +172,7 @@ pgf_parseval(PgfConcr* concr, PgfExpr expr, PgfCId cat,
|
||||
return false;
|
||||
}
|
||||
|
||||
GuEnum* en_trees = pgf_parse_result(state.ps, pool);
|
||||
GuEnum* en_trees = pgf_parse_result(state.ps);
|
||||
PgfExprProb* ep = gu_next(en_trees, PgfExprProb*, pool);
|
||||
if (ep == NULL) {
|
||||
gu_pool_free(pool);
|
||||
|
||||
@@ -212,7 +212,7 @@ pgf_parse(PgfConcr* concr, PgfCId cat, PgfLexer *lexer,
|
||||
{
|
||||
// Begin parsing a sentence of the specified category
|
||||
PgfParseState* state =
|
||||
pgf_parser_init_state(concr, cat, 0, pool);
|
||||
pgf_parser_init_state(concr, cat, 0, pool, out_pool);
|
||||
if (state == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -234,7 +234,7 @@ pgf_parse(PgfConcr* concr, PgfCId cat, PgfLexer *lexer,
|
||||
return NULL;
|
||||
|
||||
// Now begin enumerating the resulting syntax trees
|
||||
return pgf_parse_result(state, out_pool);
|
||||
return pgf_parse_result(state);
|
||||
}
|
||||
|
||||
GuEnum*
|
||||
@@ -243,7 +243,7 @@ pgf_get_completions(PgfConcr* concr, PgfCId cat, PgfLexer *lexer,
|
||||
{
|
||||
// Begin parsing a sentence of the specified category
|
||||
PgfParseState* state =
|
||||
pgf_parser_init_state(concr, cat, 0, pool);
|
||||
pgf_parser_init_state(concr, cat, 0, pool, pool);
|
||||
if (state == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -265,7 +265,7 @@ pgf_get_completions(PgfConcr* concr, PgfCId cat, PgfLexer *lexer,
|
||||
return NULL;
|
||||
|
||||
// Now begin enumerating the resulting syntax trees
|
||||
return pgf_parser_completions(state, prefix, pool);
|
||||
return pgf_parser_completions(state, prefix);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -273,7 +273,7 @@ pgf_print_chunks(PgfConcr* concr, PgfCId cat, PgfLexer *lexer, GuPool* pool)
|
||||
{
|
||||
// Begin parsing a sentence of the specified category
|
||||
PgfParseState* state =
|
||||
pgf_parser_init_state(concr, cat, 0, pool);
|
||||
pgf_parser_init_state(concr, cat, 0, pool, pool);
|
||||
if (state == NULL) {
|
||||
printf("\n");
|
||||
return;
|
||||
|
||||
@@ -115,7 +115,7 @@ int main(int argc, char* argv[]) {
|
||||
|
||||
// Begin parsing a sentence of the specified category
|
||||
PgfParseState* state =
|
||||
pgf_parser_init_state(concr, cat, 0, ppool);
|
||||
pgf_parser_init_state(concr, cat, 0, ppool, ppool);
|
||||
if (state == NULL) {
|
||||
fprintf(stderr, "Couldn't begin parsing\n");
|
||||
status = EXIT_FAILURE;
|
||||
|
||||
Reference in New Issue
Block a user