mirror of
https://github.com/janet-lang/janet
synced 2025-01-12 16:40:27 +00:00
Invert recursion guard to count down instead of up.
This commit is contained in:
parent
b19c834cf4
commit
891c550980
@ -1263,7 +1263,7 @@ static Slot compile_form(GstCompiler *c, FormOptions opts, const GstValue *form)
|
||||
static Slot compile_value(GstCompiler *c, FormOptions opts, GstValue x) {
|
||||
Slot ret;
|
||||
/* Check if recursion is too deep */
|
||||
if (c->recursionGuard++ > GST_RECURSION_GUARD) {
|
||||
if (--c->recursionGuard == 0) {
|
||||
c_error(c, "recursed too deeply");
|
||||
}
|
||||
switch (x.type) {
|
||||
@ -1289,7 +1289,7 @@ static Slot compile_value(GstCompiler *c, FormOptions opts, GstValue x) {
|
||||
ret = compile_literal(c, opts, x);
|
||||
break;
|
||||
}
|
||||
c->recursionGuard--;
|
||||
c->recursionGuard++;
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -1300,7 +1300,7 @@ void gst_compiler(GstCompiler *c, Gst *vm) {
|
||||
c->tail = NULL;
|
||||
c->error.type = GST_NIL;
|
||||
c->env = vm->env;
|
||||
c->recursionGuard = 0;
|
||||
c->recursionGuard = GST_RECURSION_GUARD;
|
||||
compiler_push_scope(c, 0);
|
||||
}
|
||||
|
||||
@ -1308,7 +1308,7 @@ void gst_compiler(GstCompiler *c, Gst *vm) {
|
||||
* given AST. Returns NULL if there was an error during compilation. */
|
||||
GstFunction *gst_compiler_compile(GstCompiler *c, GstValue form) {
|
||||
FormOptions opts = form_options_default();
|
||||
c->recursionGuard = 0;
|
||||
c->recursionGuard = GST_RECURSION_GUARD;
|
||||
GstFuncDef *def;
|
||||
if (setjmp(c->onError)) {
|
||||
/* Clear all but root scope */
|
||||
|
@ -131,7 +131,7 @@ static const char *gst_deserialize_impl(
|
||||
#define read_i64(out) do{deser_datacheck(8); (out)=bytes2int(data); data += 8; }while(0)
|
||||
|
||||
/* Check if we have recursed too deeply */
|
||||
if (depth++ > GST_RECURSION_GUARD) {
|
||||
if (--depth == 0) {
|
||||
return "deserialize recursed too deeply";
|
||||
}
|
||||
|
||||
@ -467,7 +467,7 @@ const char *gst_deserialize(
|
||||
GstValue ret;
|
||||
const char *err;
|
||||
GstArray *visited = gst_array(vm, 10);
|
||||
err = gst_deserialize_impl(vm, data, data + len, nextData, visited, &ret, 0);
|
||||
err = gst_deserialize_impl(vm, data, data + len, nextData, visited, &ret, GST_RECURSION_GUARD);
|
||||
if (err != NULL) return err;
|
||||
*out = ret;
|
||||
return NULL;
|
||||
@ -501,7 +501,7 @@ static const char *gst_serialize_impl(
|
||||
/*printf("Type: %d\n", x.type);*/
|
||||
|
||||
/* Check if we have gone too deep */
|
||||
if (depth++ > GST_RECURSION_GUARD) {
|
||||
if (--depth == 0) {
|
||||
return "serialize recursed too deeply";
|
||||
}
|
||||
|
||||
@ -759,7 +759,7 @@ const char *gst_serialize(Gst *vm, GstBuffer *buffer, GstValue x) {
|
||||
uint32_t oldCount = buffer->count;
|
||||
const char *err;
|
||||
GstTable *visited = gst_table(vm, 10);
|
||||
err = gst_serialize_impl(vm, buffer, visited, &nextId, x, 0);
|
||||
err = gst_serialize_impl(vm, buffer, visited, &nextId, x, GST_RECURSION_GUARD);
|
||||
if (err != NULL) {
|
||||
buffer->count = oldCount;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user