1
0
mirror of https://github.com/janet-lang/janet synced 2024-06-24 06:03:17 +00:00

Invert recursion guard to count down instead of up.

This commit is contained in:
bakpakin 2017-07-09 13:31:30 -04:00
parent b19c834cf4
commit 891c550980
2 changed files with 8 additions and 8 deletions

View File

@ -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 */

View File

@ -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;
}