@@ -134,26 +134,18 @@ static void reset_devices(void) {
134
134
135
135
#if MICROPY_ENABLE_PYSTACK
136
136
STATIC supervisor_allocation * allocate_pystack (safe_mode_t safe_mode ) {
137
- mp_int_t pystack_size = CIRCUITPY_PYSTACK_SIZE ;
138
137
#if CIRCUITPY_OS_GETENV && CIRCUITPY_SETTABLE_PYSTACK
139
- // Fetch value if exists from settings.toml
140
- // Leaves size to build default on any failure
141
- if (safe_mode == SAFE_MODE_NONE || safe_mode == SAFE_MODE_USER ) {
138
+ if (safe_mode == SAFE_MODE_NONE ) {
139
+ mp_int_t pystack_size = CIRCUITPY_PYSTACK_SIZE ;
142
140
(void )common_hal_os_getenv_int ("CIRCUITPY_PYSTACK_SIZE" , & pystack_size );
143
- // Check if value is valid
144
- pystack_size = pystack_size - pystack_size % sizeof (size_t ); // Round down to multiple of 4.
145
- if ((pystack_size < 384 ) || (pystack_size > 900000 )) {
146
- serial_write_compressed (translate ("\nInvalid CIRCUITPY_PYSTACK_SIZE\n\n\r" ));
147
- pystack_size = CIRCUITPY_PYSTACK_SIZE ; // Reset
141
+ supervisor_allocation * pystack = allocate_memory (pystack_size >= 384 ? pystack_size : 0 , false, false);
142
+ if (pystack ) {
143
+ return pystack ;
148
144
}
145
+ serial_write_compressed (translate ("Invalid CIRCUITPY_PYSTACK_SIZE\n" ));
149
146
}
150
147
#endif
151
- supervisor_allocation * pystack = allocate_memory (pystack_size , false, false);
152
- if (pystack == NULL ) {
153
- serial_write_compressed (translate ("\nInvalid CIRCUITPY_PYSTACK_SIZE\n\n\r" ));
154
- pystack = allocate_memory (CIRCUITPY_PYSTACK_SIZE , false, false);
155
- }
156
- return pystack ;
148
+ return allocate_memory (CIRCUITPY_PYSTACK_SIZE , false, false);
157
149
}
158
150
#endif
159
151
0 commit comments