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>
pull/8922/head
David Lechner 2022-07-01 14:06:10 -05:00 zatwierdzone przez Damien George
rodzic fc3d7ae11b
commit 81dbea1ce3
28 zmienionych plików z 31 dodań i 46 usunięć

Wyświetl plik

@ -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.

Wyświetl plik

@ -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
//////////////////////////////////////////

Wyświetl plik

@ -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; \

Wyświetl plik

@ -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]; \

Wyświetl plik

@ -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; \

Wyświetl plik

@ -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))

Wyświetl plik

@ -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];

Wyświetl plik

@ -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)

Wyświetl plik

@ -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 */ \

Wyświetl plik

@ -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))

Wyświetl plik

@ -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];

Wyświetl plik

@ -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]; \

Wyświetl plik

@ -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"

Wyświetl plik

@ -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

Wyświetl plik

@ -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;

Wyświetl plik

@ -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; \

Wyświetl plik

@ -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

Wyświetl plik

@ -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]; \

Wyświetl plik

@ -127,6 +127,7 @@ SRC_QSTR += \
machine_led.c \
modsamd.c \
samd_flash.c \
shared/readline/readline.c \
SRC_QSTR += $(SRC_MOD) $(SRC_CXX)

Wyświetl plik

@ -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

Wyświetl plik

@ -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; \

Wyświetl plik

@ -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; \

Wyświetl plik

@ -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 \

Wyświetl plik

@ -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"

Wyświetl plik

@ -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;

Wyświetl plik

@ -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];

Wyświetl plik

@ -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)

Wyświetl plik

@ -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]);