Skip to content

Commit

Permalink
fix assign statement bug and optimize the return value of Eval
Browse files Browse the repository at this point in the history
  • Loading branch information
Water-Melon committed Oct 31, 2023
1 parent 9fcb2a5 commit 67bfe0f
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/mln_lang.c
Original file line number Diff line number Diff line change
Expand Up @@ -655,8 +655,16 @@ static void mln_lang_run_handler(mln_event_t *ev, int fd, void *data)
goto out;
}
}
if (!ctx->ref)
/*
* ctx->ref == 0 means that this task is not suspended.
* and the gc should not collect if the next step is
* assign-statement. Because the right value might not be
* referred now, so it might be collected and free before
* assigned to the left variable.
*/
if (!ctx->ref && (mln_lang_stack_top(ctx) == NULL || mln_lang_stack_top(ctx)->type != M_LSNT_ASSIGN)) {
mln_gc_collect(ctx->gc, ctx);
}
pthread_mutex_lock(&lang->lock);
ctx->owner = 0;
out:
Expand Down Expand Up @@ -2764,7 +2772,9 @@ static inline void __mln_lang_funccall_val_free(mln_lang_funccall_val_t *func)
{
if (func == NULL) return;
mln_lang_var_t *var, *fr;
if (func->name != NULL) mln_string_free(func->name);
if (func->name != NULL) {
mln_string_free(func->name);
}
var = func->args_head;
while (var != NULL) {
fr = var;
Expand Down Expand Up @@ -6886,8 +6896,11 @@ static mln_lang_var_t *mln_lang_func_eval_process(mln_lang_ctx_t *ctx)
}
/*create job ctx*/
if ((newctx = __mln_lang_job_new(ctx->lang, alias, job_type, val1->data.s, NULL, NULL)) == NULL) {
mln_lang_errmsg(ctx, "Eval failed.");
return NULL;
if ((ret_var = mln_lang_var_create_false(ctx, NULL)) == NULL) {
mln_lang_errmsg(ctx, "No memory.");
return NULL;
}
return ret_var;
}
switch (type) {
case M_LANG_VAL_TYPE_NIL:
Expand Down

0 comments on commit 67bfe0f

Please sign in to comment.