aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorCalvin Rose <calsrose@gmail.com>2025-09-01 12:38:11 -0500
committerCalvin Rose <calsrose@gmail.com>2025-09-01 12:38:11 -0500
commit095a81286a429064cd30462748664abd2f198f78 (patch)
tree554877cbbd01a391a9690ae0826866304845d0ad /src
parentAddress #1629 - janet_deinit called before threaded channel message sent (diff)
Add per-thread finalizer calls in missing places.
Diffstat (limited to 'src')
-rw-r--r--src/core/gc.c11
-rw-r--r--src/core/vm.c12
2 files changed, 14 insertions, 9 deletions
diff --git a/src/core/gc.c b/src/core/gc.c
index 074560af..aad993ad 100644
--- a/src/core/gc.c
+++ b/src/core/gc.c
@@ -346,6 +346,9 @@ static void janet_deinit_block(JanetGCObject *mem) {
break;
case JANET_MEMORY_ABSTRACT: {
JanetAbstractHead *head = (JanetAbstractHead *)mem;
+ if (head->type->gcperthread) {
+ janet_assert(!head->type->gcperthread(head->data, head->size), "per-thread finalizer failed");
+ }
if (head->type->gc) {
janet_assert(!head->type->gc(head->data, head->size), "finalizer failed");
}
@@ -498,9 +501,8 @@ void janet_sweep() {
if (!janet_truthy(items[i].value)) {
void *abst = janet_unwrap_abstract(items[i].key);
JanetAbstractHead *head = janet_abstract_head(abst);
- /* Optional per-thread finalizer */
if (head->type->gcperthread) {
- janet_assert(!head->type->gcperthread(head->data, head->size), "finalizer failed");
+ janet_assert(!head->type->gcperthread(head->data, head->size), "per-thread finalizer failed");
}
if (0 == janet_abstract_decref(abst)) {
/* Run finalizer */
@@ -676,8 +678,11 @@ void janet_clear_memory(void) {
for (int32_t i = 0; i < janet_vm.threaded_abstracts.capacity; i++) {
if (janet_checktype(items[i].key, JANET_ABSTRACT)) {
void *abst = janet_unwrap_abstract(items[i].key);
+ JanetAbstractHead *head = janet_abstract_head(abst);
+ if (head->type->gcperthread) {
+ janet_assert(!head->type->gcperthread(head->data, head->size), "per-thread finalizer failed");
+ }
if (0 == janet_abstract_decref(abst)) {
- JanetAbstractHead *head = janet_abstract_head(abst);
if (head->type->gc) {
janet_assert(!head->type->gc(head->data, head->size), "finalizer failed");
}
diff --git a/src/core/vm.c b/src/core/vm.c
index a0dae1c8..0329b8e7 100644
--- a/src/core/vm.c
+++ b/src/core/vm.c
@@ -1677,6 +1677,12 @@ void janet_sandbox_assert(uint32_t forbidden_flags) {
/* Clear all memory associated with the VM */
void janet_deinit(void) {
+#ifdef JANET_NET
+ janet_net_deinit();
+#endif
+#ifdef JANET_EV
+ janet_ev_deinit();
+#endif
janet_clear_memory();
janet_symcache_deinit();
janet_free(janet_vm.roots);
@@ -1692,10 +1698,4 @@ void janet_deinit(void) {
janet_vm.root_fiber = NULL;
janet_free(janet_vm.registry);
janet_vm.registry = NULL;
-#ifdef JANET_EV
- janet_ev_deinit();
-#endif
-#ifdef JANET_NET
- janet_net_deinit();
-#endif
}