diff --git a/python/port/port.cpp b/python/port/port.cpp index 385367101..d0d1f7224 100644 --- a/python/port/port.cpp +++ b/python/port/port.cpp @@ -123,7 +123,7 @@ void MicroPython::init(void * heapStart, void * heapEnd) { mp_pystack_init(pystack, &pystack[MP_ARRAY_SIZE(pystack)]); #endif - volatile int stackTop; + volatile uintptr_t stackTop; void * stackTopAddress = (void *)(&stackTop); /* We delimit the stack part that will be used by Python. The stackTop is the * address of the first object that can be allocated on Python stack. This @@ -155,29 +155,12 @@ void MicroPython::registerScriptProvider(ScriptProvider * s) { } void MicroPython::collectRootsAtAddress(char * address, int byteLength) { -#if __EMSCRIPTEN__ - // All objects are aligned, as asserted. + /* All pointers on the stack are aligned on sizeof(void *), as asserted. + * This is a consequence of the alignment requireduirements of compilers as long + * (Cf http://www.catb.org/esr/structure-packing/). */ assert(((unsigned long)address) % ((unsigned long)sizeof(void *)) == 0); assert(byteLength % sizeof(void *) == 0); gc_collect_root((void **)address, byteLength / sizeof(void *)); -#else - for (size_t i = 0; i < sizeof(void *); i++) { - /* Objects on the stack are not necessarily aligned on sizeof(void *), - * which is also true for pointers refering to the heap. MicroPython - * gc_collect_root expects a table of void * that will be scanned every - * sizeof(void *) step. So we have to scan the stack repetitively with a - * increasing offset to be sure to check every byte for a heap address. - * If some memory can be reinterpreted as a pointer in the heap, gc_collect_root - * will prevent the destruction of the pointed heap memory. At worst (if - * the interpreted pointer was in fact an unaligned object or uninitialized - * memory), we will just keep extra objects in the heap which is not optimal - * but does not cause any crash. */ - char * addressWithOffset = address + i; - // Ensure to round the length to the ceiling - size_t lengthInAddressSize = (byteLength - i + sizeof(void *) - 1)/sizeof(void *); - gc_collect_root((void **)addressWithOffset, lengthInAddressSize); - } -#endif } KDColor MicroPython::ColorParser::ParseColor(mp_obj_t input, ColorMode ColorMode){