From 6e71cde6aad2b2ed3d431d8d94c9bd2ee52e319d Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 25 May 2022 12:13:02 +1000 Subject: [PATCH] ports: Use default VFS config for import_stat and builtin_open. For ports with MICROPY_VFS and MICROPY_PY_IO enabled their configuration can now be simplified to use the defaults for mp_import_stat and mp_builtin_open. This commit makes no functional change, except for the following minor points: - the built-in "open" is removed from the minimal port (it previously did nothing) - the duplicate built-in "input" is removed from the esp32 port - qemu-arm now delegates to VFS import/open Signed-off-by: Damien George --- ports/cc3200/mpconfigport.h | 9 --------- ports/esp32/mpconfigport.h | 10 ---------- ports/esp8266/mpconfigport.h | 9 --------- ports/javascript/mpconfigport.h | 4 ---- ports/mimxrt/mpconfigport.h | 8 -------- ports/minimal/main.c | 5 ----- ports/minimal/mpconfigport.h | 4 ---- ports/nrf/mpconfigport.h | 7 ------- ports/qemu-arm/main.c | 9 --------- ports/qemu-arm/mpconfigport.h | 4 ---- ports/qemu-arm/test_main.c | 10 ---------- ports/renesas-ra/mpconfigport.h | 9 --------- ports/rp2/mpconfigport.h | 9 --------- ports/samd/main.c | 17 ----------------- ports/samd/mpconfigport.h | 9 --------- ports/stm32/mpconfigport.h | 9 --------- ports/unix/mpconfigport.h | 5 ----- ports/unix/variants/minimal/mpconfigvariant.h | 1 - ports/windows/mpconfigport.h | 5 ----- ports/zephyr/main.c | 10 ++-------- 20 files changed, 2 insertions(+), 151 deletions(-) diff --git a/ports/cc3200/mpconfigport.h b/ports/cc3200/mpconfigport.h index a3af89674a..58ec80a9f5 100644 --- a/ports/cc3200/mpconfigport.h +++ b/ports/cc3200/mpconfigport.h @@ -135,15 +135,6 @@ #define mp_type_fileio mp_type_vfs_fat_fileio #define mp_type_textio mp_type_vfs_fat_textio -// use vfs's functions for import stat and builtin open -#define mp_import_stat mp_vfs_import_stat -#define mp_builtin_open mp_vfs_open -#define mp_builtin_open_obj mp_vfs_open_obj - -// extra built in names to add to the global namespace -#define MICROPY_PORT_BUILTINS \ - { MP_ROM_QSTR(MP_QSTR_open), MP_ROM_PTR(&mp_builtin_open_obj) }, \ - // extra constants #define MICROPY_PORT_CONSTANTS \ { MP_ROM_QSTR(MP_QSTR_umachine), MP_ROM_PTR(&mp_module_machine) }, \ diff --git a/ports/esp32/mpconfigport.h b/ports/esp32/mpconfigport.h index a64d6de995..6f42413305 100644 --- a/ports/esp32/mpconfigport.h +++ b/ports/esp32/mpconfigport.h @@ -126,16 +126,6 @@ #define mp_type_fileio mp_type_vfs_fat_fileio #define mp_type_textio mp_type_vfs_fat_textio -// use vfs's functions for import stat and builtin open -#define mp_import_stat mp_vfs_import_stat -#define mp_builtin_open mp_vfs_open -#define mp_builtin_open_obj mp_vfs_open_obj - -// extra built in names to add to the global namespace -#define MICROPY_PORT_BUILTINS \ - { MP_OBJ_NEW_QSTR(MP_QSTR_input), (mp_obj_t)&mp_builtin_input_obj }, \ - { MP_OBJ_NEW_QSTR(MP_QSTR_open), (mp_obj_t)&mp_builtin_open_obj }, - #define MP_STATE_PORT MP_STATE_VM struct _machine_timer_obj_t; diff --git a/ports/esp8266/mpconfigport.h b/ports/esp8266/mpconfigport.h index a64bc8f86d..583d3648af 100644 --- a/ports/esp8266/mpconfigport.h +++ b/ports/esp8266/mpconfigport.h @@ -150,15 +150,6 @@ extern const struct _mp_print_t mp_debug_print; #define mp_type_textio mp_type_vfs_lfs2_textio #endif -// use vfs's functions for import stat and builtin open -#define mp_import_stat mp_vfs_import_stat -#define mp_builtin_open mp_vfs_open -#define mp_builtin_open_obj mp_vfs_open_obj - -// extra built in names to add to the global namespace -#define MICROPY_PORT_BUILTINS \ - { MP_ROM_QSTR(MP_QSTR_open), MP_ROM_PTR(&mp_builtin_open_obj) }, - #define MP_STATE_PORT MP_STATE_VM #define MICROPY_PORT_ROOT_POINTERS \ diff --git a/ports/javascript/mpconfigport.h b/ports/javascript/mpconfigport.h index 1d356a0a25..4a6cb45883 100644 --- a/ports/javascript/mpconfigport.h +++ b/ports/javascript/mpconfigport.h @@ -175,10 +175,6 @@ typedef int mp_int_t; // must be pointer size typedef unsigned mp_uint_t; // must be pointer size typedef long mp_off_t; -// extra built in names to add to the global namespace -#define MICROPY_PORT_BUILTINS \ - { MP_ROM_QSTR(MP_QSTR_open), MP_ROM_PTR(&mp_builtin_open_obj) }, - // We need to provide a declaration/definition of alloca() #include diff --git a/ports/mimxrt/mpconfigport.h b/ports/mimxrt/mpconfigport.h index 05de0306b4..1dcaccad47 100644 --- a/ports/mimxrt/mpconfigport.h +++ b/ports/mimxrt/mpconfigport.h @@ -188,11 +188,6 @@ uint32_t trng_random_u32(void); #define mp_type_fileio mp_type_vfs_lfs2_fileio #define mp_type_textio mp_type_vfs_lfs2_textio -// Use VFS's functions for import stat and builtin open -#define mp_import_stat mp_vfs_import_stat -#define mp_builtin_open mp_vfs_open -#define mp_builtin_open_obj mp_vfs_open_obj - // Hooks to add builtins __attribute__((always_inline)) static inline void enable_irq(uint32_t state) { @@ -225,9 +220,6 @@ static inline void restore_irq_pri(uint32_t basepri) { #define MICROPY_BEGIN_ATOMIC_SECTION() disable_irq() #define MICROPY_END_ATOMIC_SECTION(state) enable_irq(state) -#define MICROPY_PORT_BUILTINS \ - { MP_ROM_QSTR(MP_QSTR_open), MP_ROM_PTR(&mp_builtin_open_obj) }, - #if defined(MICROPY_HW_ETH_MDC) extern const struct _mp_obj_type_t network_lan_type; #define MICROPY_HW_NIC_ETH { MP_ROM_QSTR(MP_QSTR_LAN), MP_ROM_PTR(&network_lan_type) }, diff --git a/ports/minimal/main.c b/ports/minimal/main.c index dbde33915a..2893276586 100644 --- a/ports/minimal/main.c +++ b/ports/minimal/main.c @@ -81,11 +81,6 @@ mp_import_stat_t mp_import_stat(const char *path) { return MP_IMPORT_STAT_NO_EXIST; } -mp_obj_t mp_builtin_open(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) { - return mp_const_none; -} -MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_open_obj, 1, mp_builtin_open); - void nlr_jump_fail(void *val) { while (1) { ; diff --git a/ports/minimal/mpconfigport.h b/ports/minimal/mpconfigport.h index c9f3998762..7d6a3adedc 100644 --- a/ports/minimal/mpconfigport.h +++ b/ports/minimal/mpconfigport.h @@ -25,10 +25,6 @@ typedef intptr_t mp_int_t; // must be pointer size typedef uintptr_t mp_uint_t; // must be pointer size typedef long mp_off_t; -// extra built in names to add to the global namespace -#define MICROPY_PORT_BUILTINS \ - { MP_ROM_QSTR(MP_QSTR_open), MP_ROM_PTR(&mp_builtin_open_obj) }, - // We need to provide a declaration/definition of alloca() #include diff --git a/ports/nrf/mpconfigport.h b/ports/nrf/mpconfigport.h index 05e35956d9..874748c2e4 100644 --- a/ports/nrf/mpconfigport.h +++ b/ports/nrf/mpconfigport.h @@ -85,13 +85,6 @@ #define mp_type_fileio fatfs_type_fileio #define mp_type_textio fatfs_type_textio -// use vfs's functions for import stat and builtin open -#if MICROPY_VFS -#define mp_import_stat mp_vfs_import_stat -#define mp_builtin_open mp_vfs_open -#define mp_builtin_open_obj mp_vfs_open_obj -#endif - // Enable micro:bit filesystem by default. #ifndef MICROPY_MBFS #define MICROPY_MBFS (1) diff --git a/ports/qemu-arm/main.c b/ports/qemu-arm/main.c index 8c49d0c780..45da65f2a4 100644 --- a/ports/qemu-arm/main.c +++ b/ports/qemu-arm/main.c @@ -45,15 +45,6 @@ mp_lexer_t *mp_lexer_new_from_file(const char *filename) { mp_raise_OSError(MP_ENOENT); } -mp_import_stat_t mp_import_stat(const char *path) { - return MP_IMPORT_STAT_NO_EXIST; -} - -mp_obj_t mp_builtin_open(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) { - return mp_const_none; -} -MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_open_obj, 1, mp_builtin_open); - void nlr_jump_fail(void *val) { printf("uncaught NLR\n"); exit(1); diff --git a/ports/qemu-arm/mpconfigport.h b/ports/qemu-arm/mpconfigport.h index 879ad7eaaf..8809d17154 100644 --- a/ports/qemu-arm/mpconfigport.h +++ b/ports/qemu-arm/mpconfigport.h @@ -61,10 +61,6 @@ typedef int32_t mp_int_t; // must be pointer size typedef uint32_t mp_uint_t; // must be pointer size typedef long mp_off_t; -// extra built in names to add to the global namespace -#define MICROPY_PORT_BUILTINS \ - { MP_ROM_QSTR(MP_QSTR_open), MP_ROM_PTR(&mp_builtin_open_obj) }, - // We need to provide a declaration/definition of alloca() #include diff --git a/ports/qemu-arm/test_main.c b/ports/qemu-arm/test_main.c index 3a89b3f131..673311d1e5 100644 --- a/ports/qemu-arm/test_main.c +++ b/ports/qemu-arm/test_main.c @@ -5,7 +5,6 @@ #include #include -#include "py/builtin.h" #include "py/compile.h" #include "py/runtime.h" #include "py/stackctrl.h" @@ -39,15 +38,6 @@ mp_lexer_t *mp_lexer_new_from_file(const char *filename) { mp_raise_OSError(MP_ENOENT); } -mp_import_stat_t mp_import_stat(const char *path) { - return MP_IMPORT_STAT_NO_EXIST; -} - -mp_obj_t mp_builtin_open(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) { - return mp_const_none; -} -MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_open_obj, 1, mp_builtin_open); - void nlr_jump_fail(void *val) { printf("uncaught NLR\n"); exit(1); diff --git a/ports/renesas-ra/mpconfigport.h b/ports/renesas-ra/mpconfigport.h index e66ca6b184..02292a1188 100644 --- a/ports/renesas-ra/mpconfigport.h +++ b/ports/renesas-ra/mpconfigport.h @@ -149,15 +149,6 @@ #define mp_type_textio mp_type_vfs_lfs2_textio #endif -// use vfs's functions for import stat and builtin open -#define mp_import_stat mp_vfs_import_stat -#define mp_builtin_open mp_vfs_open -#define mp_builtin_open_obj mp_vfs_open_obj - -// extra built in names to add to the global namespace -#define MICROPY_PORT_BUILTINS \ - { MP_ROM_QSTR(MP_QSTR_open), MP_ROM_PTR(&mp_builtin_open_obj) }, - #if MICROPY_PY_MACHINE #define MACHINE_BUILTIN_MODULE_CONSTANTS \ { MP_ROM_QSTR(MP_QSTR_umachine), MP_ROM_PTR(&mp_module_machine) }, \ diff --git a/ports/rp2/mpconfigport.h b/ports/rp2/mpconfigport.h index 704247dfbe..f71ddce7c5 100644 --- a/ports/rp2/mpconfigport.h +++ b/ports/rp2/mpconfigport.h @@ -125,15 +125,6 @@ #define mp_type_textio mp_type_vfs_lfs2_textio #endif -// Use VFS's functions for import stat and builtin open -#define mp_import_stat mp_vfs_import_stat -#define mp_builtin_open_obj mp_vfs_open_obj - -// Hooks to add builtins - -#define MICROPY_PORT_BUILTINS \ - { MP_ROM_QSTR(MP_QSTR_open), MP_ROM_PTR(&mp_builtin_open_obj) }, - #if MICROPY_PY_NETWORK #define NETWORK_ROOT_POINTERS mp_obj_list_t mod_network_nic_list; #else diff --git a/ports/samd/main.c b/ports/samd/main.c index 63fe4013a4..d8c1c596c5 100644 --- a/ports/samd/main.c +++ b/ports/samd/main.c @@ -73,23 +73,6 @@ void gc_collect(void) { gc_collect_end(); } -/* -mp_lexer_t *mp_lexer_new_from_file(const char *filename) { - mp_raise_OSError(MP_ENOENT); -} -*/ - -#if !MICROPY_VFS -mp_import_stat_t mp_import_stat(const char *path) { - return MP_IMPORT_STAT_NO_EXIST; -} - -mp_obj_t mp_builtin_open(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) { - return mp_const_none; -} -MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_open_obj, 1, mp_builtin_open); -#endif - void nlr_jump_fail(void *val) { for (;;) { } diff --git a/ports/samd/mpconfigport.h b/ports/samd/mpconfigport.h index 613b8cd5a9..1625496a2e 100644 --- a/ports/samd/mpconfigport.h +++ b/ports/samd/mpconfigport.h @@ -99,15 +99,6 @@ #define mp_type_fileio mp_type_vfs_lfs1_fileio #define mp_type_textio mp_type_vfs_lfs1_textio -// Use VFS's functions for import stat and builtin open -#define mp_import_stat mp_vfs_import_stat -#define mp_builtin_open_obj mp_vfs_open_obj - -// Hooks to add builtins - -#define MICROPY_PORT_BUILTINS \ - { MP_ROM_QSTR(MP_QSTR_open), MP_ROM_PTR(&mp_builtin_open_obj) }, - #define MICROPY_PORT_ROOT_POINTERS \ const char *readline_hist[8]; diff --git a/ports/stm32/mpconfigport.h b/ports/stm32/mpconfigport.h index 484dd842c4..00b60b9833 100644 --- a/ports/stm32/mpconfigport.h +++ b/ports/stm32/mpconfigport.h @@ -163,15 +163,6 @@ #define mp_type_textio mp_type_vfs_lfs2_textio #endif -// use vfs's functions for import stat and builtin open -#define mp_import_stat mp_vfs_import_stat -#define mp_builtin_open mp_vfs_open -#define mp_builtin_open_obj mp_vfs_open_obj - -// extra built in names to add to the global namespace -#define MICROPY_PORT_BUILTINS \ - { MP_ROM_QSTR(MP_QSTR_open), MP_ROM_PTR(&mp_builtin_open_obj) }, - #if MICROPY_PY_PYB extern const struct _mp_obj_module_t pyb_module; #define PYB_BUILTIN_MODULE_CONSTANTS \ diff --git a/ports/unix/mpconfigport.h b/ports/unix/mpconfigport.h index 524b165231..ca050b414b 100644 --- a/ports/unix/mpconfigport.h +++ b/ports/unix/mpconfigport.h @@ -214,8 +214,6 @@ extern const struct _mp_print_t mp_stderr_print; #define MICROPY_EMERGENCY_EXCEPTION_BUF_SIZE (256) #define MICROPY_ASYNC_KBD_INTR (1) -#define mp_import_stat mp_vfs_import_stat -#define mp_builtin_open_obj mp_vfs_open_obj #define mp_type_fileio mp_type_vfs_posix_fileio #define mp_type_textio mp_type_vfs_posix_textio @@ -273,9 +271,6 @@ void mp_unix_mark_exec(void); #endif #endif -#define MICROPY_PORT_BUILTINS \ - { MP_ROM_QSTR(MP_QSTR_open), MP_ROM_PTR(&mp_builtin_open_obj) }, - #define MP_STATE_PORT MP_STATE_VM #if MICROPY_PY_BLUETOOTH diff --git a/ports/unix/variants/minimal/mpconfigvariant.h b/ports/unix/variants/minimal/mpconfigvariant.h index f6be446920..60d194b6a1 100644 --- a/ports/unix/variants/minimal/mpconfigvariant.h +++ b/ports/unix/variants/minimal/mpconfigvariant.h @@ -109,7 +109,6 @@ #define MICROPY_PORT_ROOT_POINTERS \ -#define mp_import_stat mp_vfs_import_stat #define mp_type_fileio mp_type_vfs_posix_fileio #define mp_type_textio mp_type_vfs_posix_textio diff --git a/ports/windows/mpconfigport.h b/ports/windows/mpconfigport.h index ecaa520e81..47292b3bb6 100644 --- a/ports/windows/mpconfigport.h +++ b/ports/windows/mpconfigport.h @@ -171,8 +171,6 @@ extern const struct _mp_print_t mp_stderr_print; #define MICROPY_EMERGENCY_EXCEPTION_BUF_SIZE (256) #define MICROPY_KBD_EXCEPTION (1) -#define mp_import_stat mp_vfs_import_stat -#define mp_builtin_open_obj mp_vfs_open_obj #define mp_type_fileio mp_type_vfs_posix_fileio #define mp_type_textio mp_type_vfs_posix_textio @@ -212,9 +210,6 @@ typedef long long mp_off_t; typedef long mp_off_t; #endif -#define MICROPY_PORT_BUILTINS \ - { MP_ROM_QSTR(MP_QSTR_open), MP_ROM_PTR(&mp_builtin_open_obj) }, - #if MICROPY_USE_READLINE == 1 #define MICROPY_PORT_ROOT_POINTERS \ char *readline_hist[50]; diff --git a/ports/zephyr/main.c b/ports/zephyr/main.c index ed1ac560e1..4f735b671f 100644 --- a/ports/zephyr/main.c +++ b/ports/zephyr/main.c @@ -195,22 +195,16 @@ mp_lexer_t *mp_lexer_new_from_file(const char *filename) { } #endif +#if !MICROPY_VFS mp_import_stat_t mp_import_stat(const char *path) { - #if MICROPY_VFS - return mp_vfs_import_stat(path); - #else return MP_IMPORT_STAT_NO_EXIST; - #endif } mp_obj_t mp_builtin_open(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) { - #if MICROPY_VFS - return mp_vfs_open(n_args, args, kwargs); - #else return mp_const_none; - #endif } MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_open_obj, 1, mp_builtin_open); +#endif NORETURN void nlr_jump_fail(void *val) { while (1) {