summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Lechner <david@pybricks.com>2022-07-01 14:06:10 -0500
committerDamien George <damien@micropython.org>2022-07-18 13:48:49 +1000
commit81dbea1ce3c27a609a9b27caadd12cceef86a907 (patch)
treef870095ea5709fdb102ec9d58fcd7dd32275b2e2
parentfc3d7ae11be11a7f05709ebfd439061fce9ee555 (diff)
shared/readline: Use MP_REGISTER_ROOT_POINTER().
This uses MP_REGISTER_ROOT_POINTER() to register the readline_history root pointer array used by shared/readline.c and removes the registration from all mpconfigport.h files. This also required adding a new MICROPY_READLINE_HISTORY_SIZE config option since not all ports used the same sized array. Signed-off-by: David Lechner <david@pybricks.com>
-rw-r--r--docs/develop/porting.rst3
-rw-r--r--examples/embedding/mpconfigport_minimal.h2
-rw-r--r--ports/cc3200/mpconfigport.h1
-rw-r--r--ports/esp32/mpconfigport.h1
-rw-r--r--ports/esp8266/mpconfigport.h1
-rw-r--r--ports/javascript/Makefile2
-rw-r--r--ports/javascript/mpconfigport.h3
-rw-r--r--ports/mimxrt/Makefile1
-rw-r--r--ports/mimxrt/mpconfigport.h1
-rw-r--r--ports/minimal/Makefile1
-rw-r--r--ports/minimal/mpconfigport.h3
-rw-r--r--ports/nrf/mpconfigport.h1
-rw-r--r--ports/pic16bit/mpconfigport.h1
-rw-r--r--ports/powerpc/Makefile2
-rw-r--r--ports/powerpc/mpconfigport.h3
-rw-r--r--ports/renesas-ra/mpconfigport.h2
-rw-r--r--ports/rp2/CMakeLists.txt1
-rw-r--r--ports/rp2/mpconfigport.h1
-rw-r--r--ports/samd/Makefile1
-rw-r--r--ports/samd/mpconfigport.h3
-rw-r--r--ports/stm32/mpconfigport.h2
-rw-r--r--ports/teensy/mpconfigport.h1
-rw-r--r--ports/unix/mpconfigport.h4
-rw-r--r--ports/windows/mpconfigport.h12
-rw-r--r--ports/zephyr/mpconfigport.h1
-rw-r--r--ports/zephyr/mpconfigport_minimal.h3
-rw-r--r--py/mpconfig.h5
-rw-r--r--shared/readline/readline.c15
28 files changed, 31 insertions, 46 deletions
diff --git a/docs/develop/porting.rst b/docs/develop/porting.rst
index 3d0553205..0511f5d27 100644
--- a/docs/develop/porting.rst
+++ b/docs/develop/porting.rst
@@ -174,9 +174,6 @@ The following is an example of an ``mpconfigport.h`` file:
#define MP_STATE_PORT MP_STATE_VM
- #define MICROPY_PORT_ROOT_POINTERS \
- const char *readline_hist[8];
-
This configuration file contains machine-specific configurations including aspects like if different
MicroPython features should be enabled e.g. ``#define MICROPY_ENABLE_GC (1)``. Making this Setting
``(0)`` disables the feature.
diff --git a/examples/embedding/mpconfigport_minimal.h b/examples/embedding/mpconfigport_minimal.h
index 6cc84dcbc..91b194bc7 100644
--- a/examples/embedding/mpconfigport_minimal.h
+++ b/examples/embedding/mpconfigport_minimal.h
@@ -87,8 +87,6 @@
#define MICROPY_PY_UHASHLIB (0)
#define MICROPY_PY_UBINASCII (0)
-#define MICROPY_PORT_ROOT_POINTERS \
-
//////////////////////////////////////////
// Do not change anything beyond this line
//////////////////////////////////////////
diff --git a/ports/cc3200/mpconfigport.h b/ports/cc3200/mpconfigport.h
index 58ec80a9f..ce708cb3f 100644
--- a/ports/cc3200/mpconfigport.h
+++ b/ports/cc3200/mpconfigport.h
@@ -142,7 +142,6 @@
// vm state and root pointers for the gc
#define MP_STATE_PORT MP_STATE_VM
#define MICROPY_PORT_ROOT_POINTERS \
- const char *readline_hist[8]; \
mp_obj_t mp_const_user_interrupt; \
mp_obj_t machine_config_main; \
mp_obj_list_t pyb_sleep_obj_list; \
diff --git a/ports/esp32/mpconfigport.h b/ports/esp32/mpconfigport.h
index 1877a0143..a374d8120 100644
--- a/ports/esp32/mpconfigport.h
+++ b/ports/esp32/mpconfigport.h
@@ -146,7 +146,6 @@ struct mp_bluetooth_nimble_root_pointers_t;
#endif
#define MICROPY_PORT_ROOT_POINTERS \
- const char *readline_hist[8]; \
mp_obj_t machine_pin_irq_handler[40]; \
struct _machine_timer_obj_t *machine_timer_obj_head; \
struct _machine_i2s_obj_t *machine_i2s_obj[I2S_NUM_MAX]; \
diff --git a/ports/esp8266/mpconfigport.h b/ports/esp8266/mpconfigport.h
index 7727f7845..3f1db723a 100644
--- a/ports/esp8266/mpconfigport.h
+++ b/ports/esp8266/mpconfigport.h
@@ -148,7 +148,6 @@ extern const struct _mp_print_t mp_debug_print;
#define MP_STATE_PORT MP_STATE_VM
#define MICROPY_PORT_ROOT_POINTERS \
- const char *readline_hist[8]; \
mp_obj_t pin_irq_handler[16]; \
byte *uart0_rxbuf; \
diff --git a/ports/javascript/Makefile b/ports/javascript/Makefile
index aea9d6ec3..046d30333 100644
--- a/ports/javascript/Makefile
+++ b/ports/javascript/Makefile
@@ -30,7 +30,7 @@ SRC_C = \
mphalport.c \
modutime.c \
-SRC_QSTR += $(SRC_C)
+SRC_QSTR += $(SRC_C) $(SRC_SHARED)
OBJ += $(PY_O)
OBJ += $(addprefix $(BUILD)/, $(SRC_SHARED:.c=.o))
diff --git a/ports/javascript/mpconfigport.h b/ports/javascript/mpconfigport.h
index 4a6cb4588..01a61e391 100644
--- a/ports/javascript/mpconfigport.h
+++ b/ports/javascript/mpconfigport.h
@@ -182,6 +182,3 @@ typedef long mp_off_t;
#define MICROPY_HW_MCU_NAME "Emscripten"
#define MP_STATE_PORT MP_STATE_VM
-
-#define MICROPY_PORT_ROOT_POINTERS \
- const char *readline_hist[8];
diff --git a/ports/mimxrt/Makefile b/ports/mimxrt/Makefile
index 7ae3f9183..be1c95ba9 100644
--- a/ports/mimxrt/Makefile
+++ b/ports/mimxrt/Makefile
@@ -290,6 +290,7 @@ SRC_QSTR += \
modmimxrt.c \
modutime.c \
pin.c \
+ shared/readline/readline.c \
shared/runtime/mpirq.c \
shared/runtime/sys_stdio_mphal.c \
$(GEN_PINS_SRC)
diff --git a/ports/mimxrt/mpconfigport.h b/ports/mimxrt/mpconfigport.h
index 1dcaccad4..3bff3e474 100644
--- a/ports/mimxrt/mpconfigport.h
+++ b/ports/mimxrt/mpconfigport.h
@@ -242,7 +242,6 @@ extern const struct _mp_obj_type_t network_lan_type;
#endif
#define MICROPY_PORT_ROOT_POINTERS \
- const char *readline_hist[8]; \
struct _machine_timer_obj_t *timer_table[MICROPY_HW_PIT_NUM_CHANNELS]; \
void *machine_pin_irq_objects[MICROPY_HW_NUM_PIN_IRQS]; \
/* list of registered NICs */ \
diff --git a/ports/minimal/Makefile b/ports/minimal/Makefile
index fc3730e70..ac74925b5 100644
--- a/ports/minimal/Makefile
+++ b/ports/minimal/Makefile
@@ -68,6 +68,7 @@ SRC_C += $(SRC_MOD)
SRC_CXX += $(SRC_MOD_CXX)
+SRC_QSTR += shared/readline/readline.c
SRC_QSTR += $(SRC_MOD) $(SRC_MOD_CXX)
OBJ += $(PY_CORE_O) $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
diff --git a/ports/minimal/mpconfigport.h b/ports/minimal/mpconfigport.h
index 7d6a3aded..02312e2e4 100644
--- a/ports/minimal/mpconfigport.h
+++ b/ports/minimal/mpconfigport.h
@@ -41,6 +41,3 @@ typedef long mp_off_t;
#endif
#define MP_STATE_PORT MP_STATE_VM
-
-#define MICROPY_PORT_ROOT_POINTERS \
- const char *readline_hist[8];
diff --git a/ports/nrf/mpconfigport.h b/ports/nrf/mpconfigport.h
index 0698a52ce..fcbe71c5a 100644
--- a/ports/nrf/mpconfigport.h
+++ b/ports/nrf/mpconfigport.h
@@ -332,7 +332,6 @@ typedef long mp_off_t;
#endif
#define MICROPY_PORT_ROOT_POINTERS \
- const char *readline_hist[8]; \
mp_obj_t pin_class_mapper; \
mp_obj_t pin_class_map_dict; \
mp_obj_t pin_irq_handlers[NUM_OF_PINS]; \
diff --git a/ports/pic16bit/mpconfigport.h b/ports/pic16bit/mpconfigport.h
index e97a46502..e03fb81a6 100644
--- a/ports/pic16bit/mpconfigport.h
+++ b/ports/pic16bit/mpconfigport.h
@@ -92,7 +92,6 @@ typedef int mp_off_t;
#define MP_STATE_PORT MP_STATE_VM
#define MICROPY_PORT_ROOT_POINTERS \
- char *readline_hist[8]; \
mp_obj_t keyboard_interrupt_obj; \
#define MICROPY_MPHALPORT_H "pic16bit_mphal.h"
diff --git a/ports/powerpc/Makefile b/ports/powerpc/Makefile
index a1e6fa4da..f1ebd6764 100644
--- a/ports/powerpc/Makefile
+++ b/ports/powerpc/Makefile
@@ -42,6 +42,8 @@ SRC_C = \
shared/runtime/stdout_helpers.c \
$(BUILD)/_frozen_mpy.c \
+SRC_QSTR += shared/readline/readline.c
+
OBJ = $(PY_CORE_O)
OBJ += $(addprefix $(BUILD)/, $(SRC_C:.c=.o))
OBJ += $(BUILD)/head.o
diff --git a/ports/powerpc/mpconfigport.h b/ports/powerpc/mpconfigport.h
index 0b868e3da..084a461a4 100644
--- a/ports/powerpc/mpconfigport.h
+++ b/ports/powerpc/mpconfigport.h
@@ -112,9 +112,6 @@ typedef long mp_off_t;
#define MP_STATE_PORT MP_STATE_VM
-#define MICROPY_PORT_ROOT_POINTERS \
- const char *readline_hist[8];
-
// powerpc64 gcc doesn't seem to define these
// These are pointers, so make them 64 bit types
typedef long intptr_t;
diff --git a/ports/renesas-ra/mpconfigport.h b/ports/renesas-ra/mpconfigport.h
index 64caa69fd..11b106999 100644
--- a/ports/renesas-ra/mpconfigport.h
+++ b/ports/renesas-ra/mpconfigport.h
@@ -168,8 +168,6 @@
#endif
#define MICROPY_PORT_ROOT_POINTERS \
- const char *readline_hist[8]; \
- \
mp_obj_t pyb_hid_report_desc; \
\
mp_obj_t pyb_config_main; \
diff --git a/ports/rp2/CMakeLists.txt b/ports/rp2/CMakeLists.txt
index 202261f9c..8f7895459 100644
--- a/ports/rp2/CMakeLists.txt
+++ b/ports/rp2/CMakeLists.txt
@@ -130,6 +130,7 @@ set(MICROPY_SOURCE_PORT
set(MICROPY_SOURCE_QSTR
${MICROPY_SOURCE_PY}
+ ${MICROPY_DIR}/shared/readline/readline.c
${MICROPY_DIR}/shared/runtime/mpirq.c
${MICROPY_DIR}/shared/runtime/sys_stdio_mphal.c
${PROJECT_SOURCE_DIR}/machine_adc.c
diff --git a/ports/rp2/mpconfigport.h b/ports/rp2/mpconfigport.h
index 1a63476c7..1e8510484 100644
--- a/ports/rp2/mpconfigport.h
+++ b/ports/rp2/mpconfigport.h
@@ -231,7 +231,6 @@ extern const struct _mod_network_nic_type_t mod_network_nic_type_wiznet5k;
#endif
#define MICROPY_PORT_ROOT_POINTERS \
- const char *readline_hist[8]; \
void *machine_pin_irq_obj[30]; \
void *rp2_pio_irq_obj[2]; \
void *rp2_state_machine_irq_obj[8]; \
diff --git a/ports/samd/Makefile b/ports/samd/Makefile
index 17dd81169..b3d6d8b22 100644
--- a/ports/samd/Makefile
+++ b/ports/samd/Makefile
@@ -127,6 +127,7 @@ SRC_QSTR += \
machine_led.c \
modsamd.c \
samd_flash.c \
+ shared/readline/readline.c \
SRC_QSTR += $(SRC_MOD) $(SRC_CXX)
diff --git a/ports/samd/mpconfigport.h b/ports/samd/mpconfigport.h
index 1625496a2..96d34bf4d 100644
--- a/ports/samd/mpconfigport.h
+++ b/ports/samd/mpconfigport.h
@@ -99,9 +99,6 @@
#define mp_type_fileio mp_type_vfs_lfs1_fileio
#define mp_type_textio mp_type_vfs_lfs1_textio
-#define MICROPY_PORT_ROOT_POINTERS \
- const char *readline_hist[8];
-
#define MP_STATE_PORT MP_STATE_VM
// Miscellaneous settings
diff --git a/ports/stm32/mpconfigport.h b/ports/stm32/mpconfigport.h
index a87fe3768..4afad339b 100644
--- a/ports/stm32/mpconfigport.h
+++ b/ports/stm32/mpconfigport.h
@@ -258,8 +258,6 @@ struct _mp_bluetooth_btstack_root_pointers_t;
#endif
#define MICROPY_PORT_ROOT_POINTERS \
- const char *readline_hist[8]; \
- \
mp_obj_t pyb_hid_report_desc; \
\
mp_obj_t pyb_config_main; \
diff --git a/ports/teensy/mpconfigport.h b/ports/teensy/mpconfigport.h
index db1f56757..b870263df 100644
--- a/ports/teensy/mpconfigport.h
+++ b/ports/teensy/mpconfigport.h
@@ -42,7 +42,6 @@ extern const struct _mp_obj_module_t pyb_module;
#define MP_STATE_PORT MP_STATE_VM
#define MICROPY_PORT_ROOT_POINTERS \
- const char *readline_hist[8]; \
mp_obj_t pin_class_mapper; \
mp_obj_t pin_class_map_dict; \
struct _pyb_uart_obj_t *pyb_stdio_uart; \
diff --git a/ports/unix/mpconfigport.h b/ports/unix/mpconfigport.h
index 232bfb857..4594b8be9 100644
--- a/ports/unix/mpconfigport.h
+++ b/ports/unix/mpconfigport.h
@@ -129,6 +129,9 @@
#define MICROPY_READER_POSIX (1)
#define MICROPY_READER_VFS (1)
#define MICROPY_USE_READLINE_HISTORY (1)
+#ifndef MICROPY_READLINE_HISTORY_SIZE
+#define MICROPY_READLINE_HISTORY_SIZE 50
+#endif
#define MICROPY_HELPER_LEXER_UNIX (1)
#ifndef MICROPY_FLOAT_IMPL
#define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_DOUBLE)
@@ -302,7 +305,6 @@ struct _mp_bluetooth_nimble_malloc_t;
#endif
#define MICROPY_PORT_ROOT_POINTERS \
- const char *readline_hist[50]; \
void *mmap_region_head; \
MICROPY_BLUETOOTH_ROOT_POINTERS \
diff --git a/ports/windows/mpconfigport.h b/ports/windows/mpconfigport.h
index 47292b3bb..39f8c0059 100644
--- a/ports/windows/mpconfigport.h
+++ b/ports/windows/mpconfigport.h
@@ -33,6 +33,12 @@
#ifndef MICROPY_USE_READLINE
#define MICROPY_USE_READLINE (1)
#endif
+#ifndef MICROPY_USE_READLINE_HISTORY
+#define MICROPY_USE_READLINE_HISTORY (1)
+#endif
+#ifndef MICROPY_READLINE_HISTORY_SIZE
+#define MICROPY_READLINE_HISTORY_SIZE (50)
+#endif
#define MICROPY_ALLOC_PATH_MAX (260) // see minwindef.h for msvc or limits.h for mingw
#define MICROPY_PERSISTENT_CODE_LOAD (1)
@@ -52,7 +58,6 @@
#define MICROPY_DEBUG_PRINTERS (1)
#define MICROPY_READER_POSIX (1)
#define MICROPY_READER_VFS (1)
-#define MICROPY_USE_READLINE_HISTORY (1)
#define MICROPY_HELPER_REPL (1)
#define MICROPY_REPL_EMACS_KEYS (1)
#define MICROPY_REPL_AUTO_INDENT (1)
@@ -210,11 +215,6 @@ typedef long long mp_off_t;
typedef long mp_off_t;
#endif
-#if MICROPY_USE_READLINE == 1
-#define MICROPY_PORT_ROOT_POINTERS \
- char *readline_hist[50];
-#endif
-
#define MP_STATE_PORT MP_STATE_VM
#define MICROPY_MPHALPORT_H "windows_mphal.h"
diff --git a/ports/zephyr/mpconfigport.h b/ports/zephyr/mpconfigport.h
index 26610ccce..1be755baa 100644
--- a/ports/zephyr/mpconfigport.h
+++ b/ports/zephyr/mpconfigport.h
@@ -134,7 +134,6 @@ typedef long mp_off_t;
#define MP_STATE_PORT MP_STATE_VM
#define MICROPY_PORT_ROOT_POINTERS \
- const char *readline_hist[8]; \
void *machine_pin_irq_list; /* Linked list of pin irq objects */ \
struct _mp_bluetooth_zephyr_root_pointers_t *bluetooth_zephyr_root_pointers;
diff --git a/ports/zephyr/mpconfigport_minimal.h b/ports/zephyr/mpconfigport_minimal.h
index f0e57d756..e819d5cf4 100644
--- a/ports/zephyr/mpconfigport_minimal.h
+++ b/ports/zephyr/mpconfigport_minimal.h
@@ -83,6 +83,3 @@ typedef unsigned mp_uint_t; // must be pointer size
typedef long mp_off_t;
#define MP_STATE_PORT MP_STATE_VM
-
-#define MICROPY_PORT_ROOT_POINTERS \
- const char *readline_hist[8];
diff --git a/py/mpconfig.h b/py/mpconfig.h
index d70d39ae9..adaa3ec1f 100644
--- a/py/mpconfig.h
+++ b/py/mpconfig.h
@@ -699,6 +699,11 @@
#define MICROPY_REPL_EVENT_DRIVEN (0)
#endif
+// The number of items to keep in the readline history.
+#ifndef MICROPY_READLINE_HISTORY_SIZE
+#define MICROPY_READLINE_HISTORY_SIZE (8)
+#endif
+
// Whether to include lexer helper function for unix
#ifndef MICROPY_HELPER_LEXER_UNIX
#define MICROPY_HELPER_LEXER_UNIX (0)
diff --git a/shared/readline/readline.c b/shared/readline/readline.c
index 9b8961712..b85bbd5be 100644
--- a/shared/readline/readline.c
+++ b/shared/readline/readline.c
@@ -40,16 +40,19 @@
#define DEBUG_printf(...) (void)0
#endif
-#define READLINE_HIST_SIZE (MP_ARRAY_SIZE(MP_STATE_PORT(readline_hist)))
-
// flags for readline_t.auto_indent_state
#define AUTO_INDENT_ENABLED (0x01)
#define AUTO_INDENT_JUST_ADDED (0x02)
enum { ESEQ_NONE, ESEQ_ESC, ESEQ_ESC_BRACKET, ESEQ_ESC_BRACKET_DIGIT, ESEQ_ESC_O };
+#ifdef _MSC_VER
+// work around MSVC compiler bug: https://stackoverflow.com/q/62259834/1976323
+#pragma warning(disable : 4090)
+#endif
+
void readline_init0(void) {
- memset(MP_STATE_PORT(readline_hist), 0, READLINE_HIST_SIZE * sizeof(const char*));
+ memset(MP_STATE_PORT(readline_hist), 0, MICROPY_READLINE_HISTORY_SIZE * sizeof(const char*));
}
STATIC char *str_dup_maybe(const char *str) {
@@ -334,7 +337,7 @@ backward_kill_word:
up_arrow_key:
#endif
// up arrow
- if (rl.hist_cur + 1 < (int)READLINE_HIST_SIZE && MP_STATE_PORT(readline_hist)[rl.hist_cur + 1] != NULL) {
+ if (rl.hist_cur + 1 < MICROPY_READLINE_HISTORY_SIZE && MP_STATE_PORT(readline_hist)[rl.hist_cur + 1] != NULL) {
// increase hist num
rl.hist_cur += 1;
// set line to history
@@ -570,10 +573,12 @@ void readline_push_history(const char *line) {
// so update the history
char *most_recent_hist = str_dup_maybe(line);
if (most_recent_hist != NULL) {
- for (int i = READLINE_HIST_SIZE - 1; i > 0; i--) {
+ for (int i = MICROPY_READLINE_HISTORY_SIZE - 1; i > 0; i--) {
MP_STATE_PORT(readline_hist)[i] = MP_STATE_PORT(readline_hist)[i - 1];
}
MP_STATE_PORT(readline_hist)[0] = most_recent_hist;
}
}
}
+
+MP_REGISTER_ROOT_POINTER(const char *readline_hist[MICROPY_READLINE_HISTORY_SIZE]);