Skip to content

Commit fd40a9c

Browse files
committed
py: Make GC's STACK_SIZE definition a proper MICROPY_ config variable.
1 parent 872a829 commit fd40a9c

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

py/gc.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747

4848
#define WORDS_PER_BLOCK (4)
4949
#define BYTES_PER_BLOCK (WORDS_PER_BLOCK * BYTES_PER_WORD)
50-
#define STACK_SIZE (64) // tunable; minimum is 1
5150

5251
STATIC byte *gc_alloc_table_start;
5352
STATIC mp_uint_t gc_alloc_table_byte_len;
@@ -62,7 +61,7 @@ STATIC mp_uint_t *gc_pool_start = (void*)4;
6261
STATIC mp_uint_t *gc_pool_end;
6362

6463
STATIC int gc_stack_overflow;
65-
STATIC mp_uint_t gc_stack[STACK_SIZE];
64+
STATIC mp_uint_t gc_stack[MICROPY_ALLOC_GC_STACK_SIZE];
6665
STATIC mp_uint_t *gc_sp;
6766
STATIC uint16_t gc_lock_depth;
6867
uint16_t gc_auto_collect_enabled;
@@ -196,7 +195,7 @@ bool gc_is_locked(void) {
196195
if (ATB_GET_KIND(_block) == AT_HEAD) { \
197196
/* an unmarked head, mark it, and push it on gc stack */ \
198197
ATB_HEAD_TO_MARK(_block); \
199-
if (gc_sp < &gc_stack[STACK_SIZE]) { \
198+
if (gc_sp < &gc_stack[MICROPY_ALLOC_GC_STACK_SIZE]) { \
200199
*gc_sp++ = _block; \
201200
} else { \
202201
gc_stack_overflow = 1; \

py/mpconfig.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@
5151
/*****************************************************************************/
5252
/* Memory allocation policy */
5353

54+
// Number of words allocated (in BSS) to the GC stack (minimum is 1)
55+
#ifndef MICROPY_ALLOC_GC_STACK_SIZE
56+
#define MICROPY_ALLOC_GC_STACK_SIZE (64)
57+
#endif
58+
5459
// Initial amount for lexer indentation level
5560
#ifndef MICROPY_ALLOC_LEXER_INDENT_INIT
5661
#define MICROPY_ALLOC_LEXER_INDENT_INIT (10)

0 commit comments

Comments
 (0)