mirror of
https://github.com/pocketpy/pocketpy
synced 2025-12-06 18:20:17 +00:00
[no ci] fix
This commit is contained in:
parent
d11967293f
commit
61300ce313
@ -13,7 +13,7 @@ typedef struct ManagedHeap {
|
|||||||
int gc_threshold; // threshold for gc_counter
|
int gc_threshold; // threshold for gc_counter
|
||||||
int gc_counter; // objects created since last gc
|
int gc_counter; // objects created since last gc
|
||||||
bool gc_enabled;
|
bool gc_enabled;
|
||||||
py_Ref debug_callback;
|
py_TValue debug_callback;
|
||||||
} ManagedHeap;
|
} ManagedHeap;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|||||||
@ -17,7 +17,7 @@ void ManagedHeap__ctor(ManagedHeap* self) {
|
|||||||
self->gc_threshold = PK_GC_MIN_THRESHOLD;
|
self->gc_threshold = PK_GC_MIN_THRESHOLD;
|
||||||
self->gc_counter = 0;
|
self->gc_counter = 0;
|
||||||
self->gc_enabled = true;
|
self->gc_enabled = true;
|
||||||
self->debug_callback = NULL;
|
self->debug_callback = *py_None();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ManagedHeap__dtor(ManagedHeap* self) {
|
void ManagedHeap__dtor(ManagedHeap* self) {
|
||||||
@ -34,7 +34,6 @@ void ManagedHeap__dtor(ManagedHeap* self) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void ManagedHeap__fire_debug_callback(ManagedHeap* self, ManagedHeapSwpetInfo* out_info) {
|
static void ManagedHeap__fire_debug_callback(ManagedHeap* self, ManagedHeapSwpetInfo* out_info) {
|
||||||
assert(self->debug_callback != NULL);
|
|
||||||
assert(out_info != NULL);
|
assert(out_info != NULL);
|
||||||
|
|
||||||
c11_sbuf buf;
|
c11_sbuf buf;
|
||||||
@ -84,7 +83,7 @@ static void ManagedHeap__fire_debug_callback(ManagedHeap* self, ManagedHeapSwpet
|
|||||||
pk_sprintf(&buf, "auto_thres.free_ratio: %f\n", out_info->auto_thres.free_ratio);
|
pk_sprintf(&buf, "auto_thres.free_ratio: %f\n", out_info->auto_thres.free_ratio);
|
||||||
c11_sbuf__write_cstr(&buf, DIVIDER);
|
c11_sbuf__write_cstr(&buf, DIVIDER);
|
||||||
|
|
||||||
py_push(self->debug_callback);
|
py_push(&self->debug_callback);
|
||||||
py_pushnil();
|
py_pushnil();
|
||||||
py_StackRef arg = py_pushtmp();
|
py_StackRef arg = py_pushtmp();
|
||||||
c11_sbuf__py_submit(&buf, arg);
|
c11_sbuf__py_submit(&buf, arg);
|
||||||
@ -101,7 +100,7 @@ void ManagedHeap__collect_if_needed(ManagedHeap* self) {
|
|||||||
self->gc_counter = 0;
|
self->gc_counter = 0;
|
||||||
|
|
||||||
ManagedHeapSwpetInfo* out_info = NULL;
|
ManagedHeapSwpetInfo* out_info = NULL;
|
||||||
if(self->debug_callback) out_info = ManagedHeapSwpetInfo__new();
|
if(!py_isnone(&self->debug_callback)) out_info = ManagedHeapSwpetInfo__new();
|
||||||
|
|
||||||
ManagedHeap__mark(self);
|
ManagedHeap__mark(self);
|
||||||
if(out_info) out_info->mark_end = clock();
|
if(out_info) out_info->mark_end = clock();
|
||||||
@ -127,7 +126,7 @@ void ManagedHeap__collect_if_needed(ManagedHeap* self) {
|
|||||||
}
|
}
|
||||||
self->gc_threshold = c11__min(c11__max(new_threshold, lower), upper);
|
self->gc_threshold = c11__min(c11__max(new_threshold, lower), upper);
|
||||||
|
|
||||||
if(self->debug_callback) {
|
if(!py_isnone(&self->debug_callback)) {
|
||||||
ManagedHeap__fire_debug_callback(self, out_info);
|
ManagedHeap__fire_debug_callback(self, out_info);
|
||||||
ManagedHeapSwpetInfo__delete(out_info);
|
ManagedHeapSwpetInfo__delete(out_info);
|
||||||
}
|
}
|
||||||
@ -137,7 +136,7 @@ int ManagedHeap__collect(ManagedHeap* self) {
|
|||||||
self->gc_counter = 0;
|
self->gc_counter = 0;
|
||||||
|
|
||||||
ManagedHeapSwpetInfo* out_info = NULL;
|
ManagedHeapSwpetInfo* out_info = NULL;
|
||||||
if(self->debug_callback) out_info = ManagedHeapSwpetInfo__new();
|
if(!py_isnone(&self->debug_callback)) out_info = ManagedHeapSwpetInfo__new();
|
||||||
|
|
||||||
ManagedHeap__mark(self);
|
ManagedHeap__mark(self);
|
||||||
if(out_info) out_info->mark_end = clock();
|
if(out_info) out_info->mark_end = clock();
|
||||||
@ -149,7 +148,7 @@ int ManagedHeap__collect(ManagedHeap* self) {
|
|||||||
out_info->auto_thres.after = self->gc_threshold;
|
out_info->auto_thres.after = self->gc_threshold;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(self->debug_callback) {
|
if(!py_isnone(&self->debug_callback)) {
|
||||||
ManagedHeap__fire_debug_callback(self, out_info);
|
ManagedHeap__fire_debug_callback(self, out_info);
|
||||||
ManagedHeapSwpetInfo__delete(out_info);
|
ManagedHeapSwpetInfo__delete(out_info);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -686,7 +686,7 @@ void ManagedHeap__mark(ManagedHeap* self) {
|
|||||||
pk__mark_value(&vm->reg[i]);
|
pk__mark_value(&vm->reg[i]);
|
||||||
}
|
}
|
||||||
// mark gc debug callback
|
// mark gc debug callback
|
||||||
if(vm->heap.debug_callback) pk__mark_value(vm->heap.debug_callback);
|
pk__mark_value(&vm->heap.debug_callback);
|
||||||
// mark user func
|
// mark user func
|
||||||
if(vm->callbacks.gc_mark) vm->callbacks.gc_mark(pk__mark_value_func, p_stack);
|
if(vm->callbacks.gc_mark) vm->callbacks.gc_mark(pk__mark_value_func, p_stack);
|
||||||
/*****************************/
|
/*****************************/
|
||||||
|
|||||||
@ -60,11 +60,7 @@ static bool pkpy_memory_usage(int argc, py_Ref argv) {
|
|||||||
static bool pkpy_setup_gc_debug_callback(int argc, py_Ref argv) {
|
static bool pkpy_setup_gc_debug_callback(int argc, py_Ref argv) {
|
||||||
PY_CHECK_ARGC(1);
|
PY_CHECK_ARGC(1);
|
||||||
ManagedHeap* heap = &pk_current_vm->heap;
|
ManagedHeap* heap = &pk_current_vm->heap;
|
||||||
if(py_isnone(argv)) {
|
heap->debug_callback = *argv;
|
||||||
heap->debug_callback = NULL;
|
|
||||||
} else {
|
|
||||||
heap->debug_callback = argv;
|
|
||||||
}
|
|
||||||
py_newnone(py_retval());
|
py_newnone(py_retval());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user