[python/port] Fix size of gc collection

This commit is contained in:
Léa Saviot
2019-01-15 16:14:59 +01:00
committed by LeaNumworks
parent 835c112f2f
commit fdc02ee5e1

View File

@@ -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)&regs) {
stackLength = ((uintptr_t)python_stack_top - (uintptr_t)&regs) / sizeof(uintptr_t);
/* To compute the stack length:
* regs
* <----------->
* STACK -> ...| | | | | |--|--|--|--| | | | | | |
* ^&regs ^python_stack_top
* */
stackLength = ceil((float)((uintptr_t)python_stack_top - (uintptr_t)&regs) / (float)sizeof(uintptr_t));
scanStart = regs_ptr;
} else {
stackLength = ((uintptr_t)(&regs) - (uintptr_t)python_stack_top) / sizeof(uintptr_t);
/* When computing the stack length, take into account regs' size.
* regs
* <----------->
* STACK -> | | | | | | | | | | | |--|--|--|--| | | |...
* ^python_stack_top ^&regs
* */
size_t sizeOfRegs = ceil(((float)sizeof(regs))/(float)sizeof(uintptr_t));
stackLength = (size_t)ceil(((float)((uintptr_t)(&regs) - (uintptr_t)python_stack_top)) / (float)sizeof(uintptr_t)) + sizeOfRegs;
scanStart = (void **)python_stack_top;
}
gc_collect_root(scanStart, stackLength);