From b0e977cee76b7e3a5e3180c21b272a59b8d5c9df Mon Sep 17 00:00:00 2001 From: karurochari Date: Mon, 10 Jun 2024 07:49:30 +0000 Subject: [PATCH] Renamed variables, fixed code to work with latest changes in main --- quickjs.c | 31 +++++++++++++------------------ quickjs.h | 5 ++--- 2 files changed, 15 insertions(+), 21 deletions(-) diff --git a/quickjs.c b/quickjs.c index 66a153f..bed806d 100644 --- a/quickjs.c +++ b/quickjs.c @@ -237,9 +237,9 @@ struct JSRuntime { struct list_head tmp_obj_list; /* used during GC */ JSGCPhaseEnum gc_phase : 8; size_t malloc_gc_threshold; - BOOL malloc_gc_fix_threshold : 8; - BOOL (*malloc_gc_before_callback)(); - void (*malloc_gc_after_callback)(); + BOOL fix_malloc_gc_threshold : 8; + BOOL (*gc_before_callback)(); /* Callback before the gc event takes place */ + void (*gc_after_callback)(); /* Callback after the gc event takes place */ #ifdef DUMP_LEAKS struct list_head string_list; /* list of JSString.link */ #endif @@ -1365,18 +1365,18 @@ static void js_trigger_gc(JSRuntime *rt, size_t size) (uint64_t)rt->malloc_state.malloc_size); } #endif - //To ensure JS_RunGC cannot be executed again within callbacks. + //To ensure JS_RunGC cannot be executed again within callbacks, disable and restore it after. size_t tmp_threshold = rt->malloc_gc_threshold; rt->malloc_gc_threshold=-1; - if((rt->malloc_gc_before_callback == NULL) || rt->malloc_gc_before_callback()){ + if((rt->gc_before_callback == NULL) || rt->gc_before_callback()){ JS_RunGC(rt); - if(rt->malloc_gc_after_callback != NULL)rt->malloc_gc_after_callback(); + if(rt->gc_after_callback != NULL)rt->gc_after_callback(); } rt->malloc_gc_threshold=tmp_threshold; - if(rt->malloc_gc_fix_threshold == FALSE) { + if(rt->fix_malloc_gc_threshold == FALSE) { rt->malloc_gc_threshold = rt->malloc_state.malloc_size + (rt->malloc_state.malloc_size >> 1); } @@ -1646,9 +1646,9 @@ JSRuntime *JS_NewRuntime2(const JSMallocFunctions *mf, void *opaque) rt->malloc_state = ms; rt->malloc_gc_threshold = 256 * 1024; - rt->malloc_gc_fix_threshold = FALSE; - rt->malloc_gc_after_callback = NULL; - rt->malloc_gc_before_callback = NULL; + rt->fix_malloc_gc_threshold = FALSE; + rt->gc_after_callback = NULL; + rt->gc_before_callback = NULL; bf_context_init(&rt->bf_ctx, js_bf_realloc, rt); @@ -1796,25 +1796,20 @@ void JS_SetGCThreshold(JSRuntime *rt, size_t gc_threshold) rt->malloc_gc_threshold = gc_threshold; } -size_t JS_GetGCThreshold(JSRuntime *rt) -{ - return rt->malloc_gc_threshold; -} - void JS_SetGCThresholdFixed(JSRuntime *rt, BOOL fix) { - rt->malloc_gc_fix_threshold = fix; + rt->fix_malloc_gc_threshold = fix; } void JS_SetGCBeforeCallback(JSRuntime *rt, BOOL(*fn)()) { - rt->malloc_gc_before_callback = fn; + rt->gc_before_callback = fn; } void JS_SetGCAfterCallback(JSRuntime *rt, void(*fn)()) { - rt->malloc_gc_after_callback = fn; + rt->gc_after_callback = fn; } #define malloc(s) malloc_is_forbidden(s) diff --git a/quickjs.h b/quickjs.h index 38129ee..d5c3bef 100644 --- a/quickjs.h +++ b/quickjs.h @@ -307,10 +307,9 @@ 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); JS_EXTERN void JS_SetGCThreshold(JSRuntime *rt, size_t gc_threshold); -JS_EXTERN size_t JS_GetGCThreshold(JSRuntime *rt); JS_EXTERN void JS_SetGCThresholdFixed(JSRuntime *rt, JS_BOOL fixed); -JS_EXTERN void JS_SetGCBeforeCallback(JSRuntime *rt, JS_BOOL(*fn)()); -JS_EXTERN void JS_SetGCAfterCallback(JSRuntime *rt, void(*fn)()); +JS_EXTERN void JS_SetGCBeforeCallback(JSRuntime *rt, JS_BOOL(*cb)()); +JS_EXTERN void JS_SetGCAfterCallback(JSRuntime *rt, void(*cb)()); /* use 0 to disable maximum stack size check */ JS_EXTERN void JS_SetMaxStackSize(JSRuntime *rt, size_t stack_size); /* should be called when changing thread to update the stack top value