From 0ed0eabeaa4b36844981a9cf7652a0f3fda37dcf Mon Sep 17 00:00:00 2001 From: Jeroen van der Heijden Date: Tue, 30 Jan 2024 09:43:16 +0100 Subject: [PATCH] Fixed nesting tasks through arguments bug --- CHANGELOG.md | 1 + inc/ti/val.inline.h | 5 +++++ inc/ti/version.h | 2 +- src/ti/do.c | 3 +-- src/ti/vtask.c | 12 ++++++++++-- 5 files changed, 18 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d92ec754..7402ffb2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ * A bug with adding enumerators to restricted lists has been fixed. * A bug with applying a new relation to existing data has been fixed. * A bug with async future error reporting has been fixed. +* A bug with clearing nesting tasks through arguments has been fixed. * The `change._tasks` structure in C code has been renamed. This has no impact on user-facing functionality. * Replaced Docker images _(both tests and builds)_ with newer versions. diff --git a/inc/ti/val.inline.h b/inc/ti/val.inline.h index b873a313..1916372c 100644 --- a/inc/ti/val.inline.h +++ b/inc/ti/val.inline.h @@ -611,6 +611,11 @@ static inline _Bool ti_val_is_nil(ti_val_t * val) return val->tp == TI_VAL_NIL; } +static inline _Bool ti_val_is_opt_chain(ti_val_t * val) +{ + return val->tp == TI_VAL_NIL || val->tp == TI_VAL_ERROR; +} + static inline _Bool ti_val_is_str(ti_val_t * val) { return val->tp == TI_VAL_STR || val->tp == TI_VAL_NAME; diff --git a/inc/ti/version.h b/inc/ti/version.h index 156680ff..1961725f 100644 --- a/inc/ti/version.h +++ b/inc/ti/version.h @@ -25,7 +25,7 @@ * "-rc0" * "" */ -#define TI_VERSION_PRE_RELEASE "-alpha10" +#define TI_VERSION_PRE_RELEASE "-alpha11" #define TI_MAINTAINER \ "Jeroen van der Heijden " diff --git a/src/ti/do.c b/src/ti/do.c index f0cb0ca8..5eadb3bb 100644 --- a/src/ti/do.c +++ b/src/ti/do.c @@ -634,8 +634,7 @@ static int do__chain(ti_query_t * query, cleri_node_t * nd, ex_t * e) cleri_node_t * node = child; /* function, assignment, name */ cleri_node_t * index_node = child->next; - if (nd->children->len == 2 && - (ti_val_is_nil(query->rval) || ti_val_is_error(query->rval))) + if (nd->children->len == 2 && ti_val_is_opt_chain(query->rval)) return 0; child = child->next->next; /* set to chain child (or NULL) */ diff --git a/src/ti/vtask.c b/src/ti/vtask.c index ddaa4042..51d039c2 100644 --- a/src/ti/vtask.c +++ b/src/ti/vtask.c @@ -68,7 +68,7 @@ void ti_vtask_destroy(ti_vtask_t * vtask) if (vtask && vtask->id) { ti_user_drop(vtask->user); - ti_closure_unsafe_drop(vtask->closure); + ti_closure_drop(vtask->closure); ti_verror_drop(vtask->verr); vec_destroy(vtask->args, (vec_destroy_cb) ti_val_unsafe_drop); } @@ -197,7 +197,7 @@ int ti_vtask_run(ti_vtask_t * vtask, ti_collection_t * collection) static void vtask__clear(ti_vtask_t * vtask) { ti_user_drop(vtask->user); - ti_closure_unsafe_drop(vtask->closure); + ti_closure_drop(vtask->closure); ti_verror_drop(vtask->verr); vec_destroy(vtask->args, (vec_destroy_cb) ti_val_unsafe_drop); vtask->id = 0; @@ -219,7 +219,15 @@ void ti_vtask_del(uint64_t vtask_id, ti_collection_t * collection) { ti_vtask_t * vtask = vec_swap_remove(vtasks, idx); if (--vtask->ref) + { + ++vtask->ref; /* temporary add one reference for when tasks + * are nested in the task arguments */ vtask__clear(vtask); + + /* check again as all the references might be cleared by now */ + if (!--vtask->ref) + ti_vtask_destroy(vtask); + } else ti_vtask_destroy(vtask); break;