mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[python/port] Fix size of gc collection
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <ion/keyboard.h>
|
||||
|
||||
#include <math.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <setjmp.h>
|
||||
@@ -140,11 +141,30 @@ void gc_collect(void) {
|
||||
size_t stackLength;
|
||||
void ** scanStart;
|
||||
if ((uintptr_t)python_stack_top > (uintptr_t)®s) {
|
||||
stackLength = ((uintptr_t)python_stack_top - (uintptr_t)®s) / sizeof(uintptr_t);
|
||||
|
||||
/* To compute the stack length:
|
||||
* regs
|
||||
* <----------->
|
||||
* STACK -> ...| | | | | |--|--|--|--| | | | | | |
|
||||
* ^®s ^python_stack_top
|
||||
* */
|
||||
|
||||
stackLength = ceil((float)((uintptr_t)python_stack_top - (uintptr_t)®s) / (float)sizeof(uintptr_t));
|
||||
scanStart = regs_ptr;
|
||||
|
||||
} else {
|
||||
stackLength = ((uintptr_t)(®s) - (uintptr_t)python_stack_top) / sizeof(uintptr_t);
|
||||
|
||||
/* When computing the stack length, take into account regs' size.
|
||||
* regs
|
||||
* <----------->
|
||||
* STACK -> | | | | | | | | | | | |--|--|--|--| | | |...
|
||||
* ^python_stack_top ^®s
|
||||
* */
|
||||
|
||||
size_t sizeOfRegs = ceil(((float)sizeof(regs))/(float)sizeof(uintptr_t));
|
||||
stackLength = (size_t)ceil(((float)((uintptr_t)(®s) - (uintptr_t)python_stack_top)) / (float)sizeof(uintptr_t)) + sizeOfRegs;
|
||||
scanStart = (void **)python_stack_top;
|
||||
|
||||
}
|
||||
gc_collect_root(scanStart, stackLength);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user