mirror of
https://github.com/janet-lang/janet
synced 2024-11-28 19:19:53 +00:00
Address #778
Relax check that number of closure environments in a function matches that of the def. The def could be partially constructed, and so there may be a false negative. The runtime will check that this is consistent, and the garbage collector should handle when this constraint is not kept.
This commit is contained in:
parent
ef23356309
commit
bb405ee1aa
@ -560,9 +560,9 @@ static void marshal_one(MarshalState *st, Janet x, int flags) {
|
|||||||
case JANET_FUNCTION: {
|
case JANET_FUNCTION: {
|
||||||
pushbyte(st, LB_FUNCTION);
|
pushbyte(st, LB_FUNCTION);
|
||||||
JanetFunction *func = janet_unwrap_function(x);
|
JanetFunction *func = janet_unwrap_function(x);
|
||||||
|
pushint(st, func->def->environments_length);
|
||||||
/* Mark seen before reading def */
|
/* Mark seen before reading def */
|
||||||
MARK_SEEN();
|
MARK_SEEN();
|
||||||
pushint(st, func->def->environments_length);
|
|
||||||
marshal_one_def(st, func->def, flags);
|
marshal_one_def(st, func->def, flags);
|
||||||
for (int32_t i = 0; i < func->def->environments_length; i++)
|
for (int32_t i = 0; i < func->def->environments_length; i++)
|
||||||
marshal_one_env(st, func->envs[i], flags + 1);
|
marshal_one_env(st, func->envs[i], flags + 1);
|
||||||
@ -1262,15 +1262,12 @@ static const uint8_t *unmarshal_one(
|
|||||||
}
|
}
|
||||||
func = janet_gcalloc(JANET_MEMORY_FUNCTION, sizeof(JanetFunction) +
|
func = janet_gcalloc(JANET_MEMORY_FUNCTION, sizeof(JanetFunction) +
|
||||||
len * sizeof(JanetFuncEnv));
|
len * sizeof(JanetFuncEnv));
|
||||||
|
func->def = NULL;
|
||||||
*out = janet_wrap_function(func);
|
*out = janet_wrap_function(func);
|
||||||
janet_v_push(st->lookup, *out);
|
janet_v_push(st->lookup, *out);
|
||||||
data = unmarshal_one_def(st, data, &def, flags + 1);
|
data = unmarshal_one_def(st, data, &def, flags + 1);
|
||||||
if (def->environments_length != len) {
|
|
||||||
janet_panicf("invalid function - env count does not match def (%d != %d)",
|
|
||||||
len, def->environments_length);
|
|
||||||
}
|
|
||||||
func->def = def;
|
func->def = def;
|
||||||
for (int32_t i = 0; i < def->environments_length; i++) {
|
for (int32_t i = 0; i < len; i++) {
|
||||||
data = unmarshal_one_env(st, data, &(func->envs[i]), flags + 1);
|
data = unmarshal_one_env(st, data, &(func->envs[i]), flags + 1);
|
||||||
}
|
}
|
||||||
return data;
|
return data;
|
||||||
|
Loading…
Reference in New Issue
Block a user