From 4093f9a3181a09c0c2fb8c83b5b84a28c17a2e53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sa=C3=BAl=20Ibarra=20Corretg=C3=A9?= Date: Tue, 4 Jun 2024 17:36:36 +0200 Subject: [PATCH 1/2] Use 0 for disabling automatic GC Similarly to other limits such as memory or stack limit, 0 means unlimited. --- quickjs.c | 4 ++-- quickjs.h | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/quickjs.c b/quickjs.c index 085037e8a..221ef6d17 100644 --- a/quickjs.c +++ b/quickjs.c @@ -1341,7 +1341,7 @@ static void js_trigger_gc(JSRuntime *rt, size_t size) force_gc = TRUE; #else force_gc = ((rt->malloc_state.malloc_size + size) > - rt->malloc_gc_threshold); + rt->malloc_gc_threshold - 1); #endif if (force_gc) { #ifdef DUMP_GC @@ -1755,7 +1755,7 @@ void JS_SetDumpFlags(JSRuntime *rt, uint64_t flags) rt->dump_flags = flags; } -/* use -1 to disable automatic GC */ +/* use 0 to disable automatic GC */ void JS_SetGCThreshold(JSRuntime *rt, size_t gc_threshold) { rt->malloc_gc_threshold = gc_threshold; diff --git a/quickjs.h b/quickjs.h index d44ebbc9c..c9843d2af 100644 --- a/quickjs.h +++ b/quickjs.h @@ -301,6 +301,7 @@ JS_EXTERN void JS_SetRuntimeInfo(JSRuntime *rt, const char *info); /* use 0 to disable memory limit */ JS_EXTERN void JS_SetMemoryLimit(JSRuntime *rt, size_t limit); JS_EXTERN void JS_SetDumpFlags(JSRuntime *rt, uint64_t flags); +/* use 0 to disable automatic GC */ JS_EXTERN void JS_SetGCThreshold(JSRuntime *rt, size_t gc_threshold); /* use 0 to disable maximum stack size check */ JS_EXTERN void JS_SetMaxStackSize(JSRuntime *rt, size_t stack_size); From 2674e97fb571b7c37fcde50d4a1ea1054584e02c Mon Sep 17 00:00:00 2001 From: KaruroChori Date: Tue, 4 Jun 2024 17:40:07 +0200 Subject: [PATCH 2/2] Add getter for GC threshold --- quickjs.c | 4 ++++ quickjs.h | 1 + 2 files changed, 5 insertions(+) diff --git a/quickjs.c b/quickjs.c index 221ef6d17..946caf5cd 100644 --- a/quickjs.c +++ b/quickjs.c @@ -1755,6 +1755,10 @@ void JS_SetDumpFlags(JSRuntime *rt, uint64_t flags) rt->dump_flags = flags; } +size_t JS_GetGCThreshold(JSRuntime *rt) { + return rt->malloc_gc_threshold; +} + /* use 0 to disable automatic GC */ void JS_SetGCThreshold(JSRuntime *rt, size_t gc_threshold) { diff --git a/quickjs.h b/quickjs.h index c9843d2af..e3ac650b7 100644 --- a/quickjs.h +++ b/quickjs.h @@ -301,6 +301,7 @@ JS_EXTERN void JS_SetRuntimeInfo(JSRuntime *rt, const char *info); /* use 0 to disable memory limit */ JS_EXTERN void JS_SetMemoryLimit(JSRuntime *rt, size_t limit); JS_EXTERN void JS_SetDumpFlags(JSRuntime *rt, uint64_t flags); +JS_EXTERN size_t JS_GetGCThreshold(JSRuntime *rt); /* use 0 to disable automatic GC */ JS_EXTERN void JS_SetGCThreshold(JSRuntime *rt, size_t gc_threshold); /* use 0 to disable maximum stack size check */