From c61108408695d4972bc8b66f65061d9517e333bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Fri, 14 Jun 2019 12:01:00 -0400 Subject: [PATCH] [python] Clean gc_collect and comment to explain potential address sanitize error --- python/port/port.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/python/port/port.cpp b/python/port/port.cpp index 6f01f26ca..ba1106936 100644 --- a/python/port/port.cpp +++ b/python/port/port.cpp @@ -138,9 +138,9 @@ void gc_collect(void) { /* On the device, the stack is stored in reverse order, but it might not be * the case on a computer. We thus have to take the absolute value of the * addresses difference. */ - size_t stackLength; + size_t stackLengthInByte; void ** scanStart; - if ((uintptr_t)python_stack_top > (uintptr_t)®s) { + if ((uintptr_t)python_stack_top > (uintptr_t)regs_ptr) { /* To compute the stack length: * regs @@ -149,7 +149,7 @@ void gc_collect(void) { * ^®s ^python_stack_top * */ - stackLength = ceil((float)((uintptr_t)python_stack_top - (uintptr_t)®s) / (float)sizeof(uintptr_t)); + stackLengthInByte = (uintptr_t)python_stack_top - (uintptr_t)regs_ptr; scanStart = regs_ptr; } else { @@ -161,12 +161,13 @@ void gc_collect(void) { * ^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; + stackLengthInByte = (uintptr_t)regs_ptr - (uintptr_t)python_stack_top + sizeof(regs); scanStart = (void **)python_stack_top; } - gc_collect_root(scanStart, stackLength); + /* Memory error detectors might find an error here as they might split regs + * and stack memory zones. */ + gc_collect_root(scanStart, stackLengthInByte/sizeof(void *)); gc_collect_end(); }