Skip to content

Commit

Permalink
ports: Use default VFS config for import_stat and builtin_open.
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
dpgeorge committed May 25, 2022
1 parent 5956466 commit 6e71cde
Show file tree
Hide file tree
Showing 20 changed files with 2 additions and 151 deletions.
9 changes: 0 additions & 9 deletions ports/cc3200/mpconfigport.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) }, \
Expand Down
10 changes: 0 additions & 10 deletions ports/esp32/mpconfigport.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 0 additions & 9 deletions ports/esp8266/mpconfigport.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
4 changes: 0 additions & 4 deletions ports/javascript/mpconfigport.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <alloca.h>

Expand Down
8 changes: 0 additions & 8 deletions ports/mimxrt/mpconfigport.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) },
Expand Down
5 changes: 0 additions & 5 deletions ports/minimal/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
;
Expand Down
4 changes: 0 additions & 4 deletions ports/minimal/mpconfigport.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <alloca.h>

Expand Down
7 changes: 0 additions & 7 deletions ports/nrf/mpconfigport.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 0 additions & 9 deletions ports/qemu-arm/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 0 additions & 4 deletions ports/qemu-arm/mpconfigport.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <alloca.h>

Expand Down
10 changes: 0 additions & 10 deletions ports/qemu-arm/test_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <malloc.h>
#include <setjmp.h>

#include "py/builtin.h"
#include "py/compile.h"
#include "py/runtime.h"
#include "py/stackctrl.h"
Expand Down Expand Up @@ -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);
Expand Down
9 changes: 0 additions & 9 deletions ports/renesas-ra/mpconfigport.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) }, \
Expand Down
9 changes: 0 additions & 9 deletions ports/rp2/mpconfigport.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 0 additions & 17 deletions ports/samd/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 (;;) {
}
Expand Down
9 changes: 0 additions & 9 deletions ports/samd/mpconfigport.h
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down
9 changes: 0 additions & 9 deletions ports/stm32/mpconfigport.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
5 changes: 0 additions & 5 deletions ports/unix/mpconfigport.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion ports/unix/variants/minimal/mpconfigvariant.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 0 additions & 5 deletions ports/windows/mpconfigport.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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];
Expand Down
10 changes: 2 additions & 8 deletions ports/zephyr/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 6e71cde

Please sign in to comment.