add oom handling to iterative LR engine
This commit is contained in:
parent
384a7b9390
commit
22b5611cdf
2 changed files with 15 additions and 1 deletions
|
|
@ -426,6 +426,16 @@ bool h_lr_parse_chunk(HSuspendedParser* s, HInputStream *stream)
|
||||||
engine->input = *stream;
|
engine->input = *stream;
|
||||||
|
|
||||||
bool run = true;
|
bool run = true;
|
||||||
|
|
||||||
|
// out-of-memory handling
|
||||||
|
jmp_buf except;
|
||||||
|
h_arena_set_except(engine->arena, &except);
|
||||||
|
h_arena_set_except(engine->tarena, &except);
|
||||||
|
if(setjmp(except)) {
|
||||||
|
run = false; // done immediately
|
||||||
|
assert(engine->state != HLR_SUCCESS); // h_parse_finish will return NULL
|
||||||
|
}
|
||||||
|
|
||||||
while(run) {
|
while(run) {
|
||||||
// check input against table to determine which action to take
|
// check input against table to determine which action to take
|
||||||
const HLRAction *action = h_lrengine_action(engine);
|
const HLRAction *action = h_lrengine_action(engine);
|
||||||
|
|
@ -441,6 +451,9 @@ bool h_lr_parse_chunk(HSuspendedParser* s, HInputStream *stream)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
h_arena_set_except(engine->arena, NULL);
|
||||||
|
h_arena_set_except(engine->tarena, NULL);
|
||||||
|
|
||||||
*stream = engine->input;
|
*stream = engine->input;
|
||||||
return !run; // done if engine no longer running
|
return !run; // done if engine no longer running
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -57,8 +57,9 @@ static void test_oom(void) {
|
||||||
g_check_parse_failed(p, PB_LALR, "x",1);
|
g_check_parse_failed(p, PB_LALR, "x",1);
|
||||||
g_check_parse_failed(p, PB_GLR, "x",1);
|
g_check_parse_failed(p, PB_GLR, "x",1);
|
||||||
|
|
||||||
|
//g_check_parse_chunks_failed(p, PB_REGULAR, "",0, "x",1);
|
||||||
g_check_parse_chunks_failed(p, PB_LLk, "",0, "x",1);
|
g_check_parse_chunks_failed(p, PB_LLk, "",0, "x",1);
|
||||||
//g_check_parse_chunks_failed(p, PB_LALR, "",0, "x",1);
|
g_check_parse_chunks_failed(p, PB_LALR, "",0, "x",1);
|
||||||
//g_check_parse_chunks_failed(p, PB_GLR, "",0, "x",1);
|
//g_check_parse_chunks_failed(p, PB_GLR, "",0, "x",1);
|
||||||
|
|
||||||
i = setrlimit(RLIMIT_DATA, &bak);
|
i = setrlimit(RLIMIT_DATA, &bak);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue