Skip to content

Commit 6e71cde

Browse files
committed
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 <[email protected]>
1 parent 5956466 commit 6e71cde

File tree

20 files changed

+2
-151
lines changed

20 files changed

+2
-151
lines changed

Diff for: ports/cc3200/mpconfigport.h

-9
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,6 @@
135135
#define mp_type_fileio mp_type_vfs_fat_fileio
136136
#define mp_type_textio mp_type_vfs_fat_textio
137137

138-
// use vfs's functions for import stat and builtin open
139-
#define mp_import_stat mp_vfs_import_stat
140-
#define mp_builtin_open mp_vfs_open
141-
#define mp_builtin_open_obj mp_vfs_open_obj
142-
143-
// extra built in names to add to the global namespace
144-
#define MICROPY_PORT_BUILTINS \
145-
{ MP_ROM_QSTR(MP_QSTR_open), MP_ROM_PTR(&mp_builtin_open_obj) }, \
146-
147138
// extra constants
148139
#define MICROPY_PORT_CONSTANTS \
149140
{ MP_ROM_QSTR(MP_QSTR_umachine), MP_ROM_PTR(&mp_module_machine) }, \

Diff for: ports/esp32/mpconfigport.h

-10
Original file line numberDiff line numberDiff line change
@@ -126,16 +126,6 @@
126126
#define mp_type_fileio mp_type_vfs_fat_fileio
127127
#define mp_type_textio mp_type_vfs_fat_textio
128128

129-
// use vfs's functions for import stat and builtin open
130-
#define mp_import_stat mp_vfs_import_stat
131-
#define mp_builtin_open mp_vfs_open
132-
#define mp_builtin_open_obj mp_vfs_open_obj
133-
134-
// extra built in names to add to the global namespace
135-
#define MICROPY_PORT_BUILTINS \
136-
{ MP_OBJ_NEW_QSTR(MP_QSTR_input), (mp_obj_t)&mp_builtin_input_obj }, \
137-
{ MP_OBJ_NEW_QSTR(MP_QSTR_open), (mp_obj_t)&mp_builtin_open_obj },
138-
139129
#define MP_STATE_PORT MP_STATE_VM
140130

141131
struct _machine_timer_obj_t;

Diff for: ports/esp8266/mpconfigport.h

-9
Original file line numberDiff line numberDiff line change
@@ -150,15 +150,6 @@ extern const struct _mp_print_t mp_debug_print;
150150
#define mp_type_textio mp_type_vfs_lfs2_textio
151151
#endif
152152

153-
// use vfs's functions for import stat and builtin open
154-
#define mp_import_stat mp_vfs_import_stat
155-
#define mp_builtin_open mp_vfs_open
156-
#define mp_builtin_open_obj mp_vfs_open_obj
157-
158-
// extra built in names to add to the global namespace
159-
#define MICROPY_PORT_BUILTINS \
160-
{ MP_ROM_QSTR(MP_QSTR_open), MP_ROM_PTR(&mp_builtin_open_obj) },
161-
162153
#define MP_STATE_PORT MP_STATE_VM
163154

164155
#define MICROPY_PORT_ROOT_POINTERS \

Diff for: ports/javascript/mpconfigport.h

-4
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,6 @@ typedef int mp_int_t; // must be pointer size
175175
typedef unsigned mp_uint_t; // must be pointer size
176176
typedef long mp_off_t;
177177

178-
// extra built in names to add to the global namespace
179-
#define MICROPY_PORT_BUILTINS \
180-
{ MP_ROM_QSTR(MP_QSTR_open), MP_ROM_PTR(&mp_builtin_open_obj) },
181-
182178
// We need to provide a declaration/definition of alloca()
183179
#include <alloca.h>
184180

Diff for: ports/mimxrt/mpconfigport.h

-8
Original file line numberDiff line numberDiff line change
@@ -188,11 +188,6 @@ uint32_t trng_random_u32(void);
188188
#define mp_type_fileio mp_type_vfs_lfs2_fileio
189189
#define mp_type_textio mp_type_vfs_lfs2_textio
190190

191-
// Use VFS's functions for import stat and builtin open
192-
#define mp_import_stat mp_vfs_import_stat
193-
#define mp_builtin_open mp_vfs_open
194-
#define mp_builtin_open_obj mp_vfs_open_obj
195-
196191
// Hooks to add builtins
197192

198193
__attribute__((always_inline)) static inline void enable_irq(uint32_t state) {
@@ -225,9 +220,6 @@ static inline void restore_irq_pri(uint32_t basepri) {
225220
#define MICROPY_BEGIN_ATOMIC_SECTION() disable_irq()
226221
#define MICROPY_END_ATOMIC_SECTION(state) enable_irq(state)
227222

228-
#define MICROPY_PORT_BUILTINS \
229-
{ MP_ROM_QSTR(MP_QSTR_open), MP_ROM_PTR(&mp_builtin_open_obj) },
230-
231223
#if defined(MICROPY_HW_ETH_MDC)
232224
extern const struct _mp_obj_type_t network_lan_type;
233225
#define MICROPY_HW_NIC_ETH { MP_ROM_QSTR(MP_QSTR_LAN), MP_ROM_PTR(&network_lan_type) },

Diff for: ports/minimal/main.c

-5
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,6 @@ mp_import_stat_t mp_import_stat(const char *path) {
8181
return MP_IMPORT_STAT_NO_EXIST;
8282
}
8383

84-
mp_obj_t mp_builtin_open(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) {
85-
return mp_const_none;
86-
}
87-
MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_open_obj, 1, mp_builtin_open);
88-
8984
void nlr_jump_fail(void *val) {
9085
while (1) {
9186
;

Diff for: ports/minimal/mpconfigport.h

-4
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@ typedef intptr_t mp_int_t; // must be pointer size
2525
typedef uintptr_t mp_uint_t; // must be pointer size
2626
typedef long mp_off_t;
2727

28-
// extra built in names to add to the global namespace
29-
#define MICROPY_PORT_BUILTINS \
30-
{ MP_ROM_QSTR(MP_QSTR_open), MP_ROM_PTR(&mp_builtin_open_obj) },
31-
3228
// We need to provide a declaration/definition of alloca()
3329
#include <alloca.h>
3430

Diff for: ports/nrf/mpconfigport.h

-7
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,6 @@
8585
#define mp_type_fileio fatfs_type_fileio
8686
#define mp_type_textio fatfs_type_textio
8787

88-
// use vfs's functions for import stat and builtin open
89-
#if MICROPY_VFS
90-
#define mp_import_stat mp_vfs_import_stat
91-
#define mp_builtin_open mp_vfs_open
92-
#define mp_builtin_open_obj mp_vfs_open_obj
93-
#endif
94-
9588
// Enable micro:bit filesystem by default.
9689
#ifndef MICROPY_MBFS
9790
#define MICROPY_MBFS (1)

Diff for: ports/qemu-arm/main.c

-9
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,6 @@ mp_lexer_t *mp_lexer_new_from_file(const char *filename) {
4545
mp_raise_OSError(MP_ENOENT);
4646
}
4747

48-
mp_import_stat_t mp_import_stat(const char *path) {
49-
return MP_IMPORT_STAT_NO_EXIST;
50-
}
51-
52-
mp_obj_t mp_builtin_open(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) {
53-
return mp_const_none;
54-
}
55-
MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_open_obj, 1, mp_builtin_open);
56-
5748
void nlr_jump_fail(void *val) {
5849
printf("uncaught NLR\n");
5950
exit(1);

Diff for: ports/qemu-arm/mpconfigport.h

-4
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,6 @@ typedef int32_t mp_int_t; // must be pointer size
6161
typedef uint32_t mp_uint_t; // must be pointer size
6262
typedef long mp_off_t;
6363

64-
// extra built in names to add to the global namespace
65-
#define MICROPY_PORT_BUILTINS \
66-
{ MP_ROM_QSTR(MP_QSTR_open), MP_ROM_PTR(&mp_builtin_open_obj) },
67-
6864
// We need to provide a declaration/definition of alloca()
6965
#include <alloca.h>
7066

Diff for: ports/qemu-arm/test_main.c

-10
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#include <malloc.h>
66
#include <setjmp.h>
77

8-
#include "py/builtin.h"
98
#include "py/compile.h"
109
#include "py/runtime.h"
1110
#include "py/stackctrl.h"
@@ -39,15 +38,6 @@ mp_lexer_t *mp_lexer_new_from_file(const char *filename) {
3938
mp_raise_OSError(MP_ENOENT);
4039
}
4140

42-
mp_import_stat_t mp_import_stat(const char *path) {
43-
return MP_IMPORT_STAT_NO_EXIST;
44-
}
45-
46-
mp_obj_t mp_builtin_open(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) {
47-
return mp_const_none;
48-
}
49-
MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_open_obj, 1, mp_builtin_open);
50-
5141
void nlr_jump_fail(void *val) {
5242
printf("uncaught NLR\n");
5343
exit(1);

Diff for: ports/renesas-ra/mpconfigport.h

-9
Original file line numberDiff line numberDiff line change
@@ -149,15 +149,6 @@
149149
#define mp_type_textio mp_type_vfs_lfs2_textio
150150
#endif
151151

152-
// use vfs's functions for import stat and builtin open
153-
#define mp_import_stat mp_vfs_import_stat
154-
#define mp_builtin_open mp_vfs_open
155-
#define mp_builtin_open_obj mp_vfs_open_obj
156-
157-
// extra built in names to add to the global namespace
158-
#define MICROPY_PORT_BUILTINS \
159-
{ MP_ROM_QSTR(MP_QSTR_open), MP_ROM_PTR(&mp_builtin_open_obj) },
160-
161152
#if MICROPY_PY_MACHINE
162153
#define MACHINE_BUILTIN_MODULE_CONSTANTS \
163154
{ MP_ROM_QSTR(MP_QSTR_umachine), MP_ROM_PTR(&mp_module_machine) }, \

Diff for: ports/rp2/mpconfigport.h

-9
Original file line numberDiff line numberDiff line change
@@ -125,15 +125,6 @@
125125
#define mp_type_textio mp_type_vfs_lfs2_textio
126126
#endif
127127

128-
// Use VFS's functions for import stat and builtin open
129-
#define mp_import_stat mp_vfs_import_stat
130-
#define mp_builtin_open_obj mp_vfs_open_obj
131-
132-
// Hooks to add builtins
133-
134-
#define MICROPY_PORT_BUILTINS \
135-
{ MP_ROM_QSTR(MP_QSTR_open), MP_ROM_PTR(&mp_builtin_open_obj) },
136-
137128
#if MICROPY_PY_NETWORK
138129
#define NETWORK_ROOT_POINTERS mp_obj_list_t mod_network_nic_list;
139130
#else

Diff for: ports/samd/main.c

-17
Original file line numberDiff line numberDiff line change
@@ -73,23 +73,6 @@ void gc_collect(void) {
7373
gc_collect_end();
7474
}
7575

76-
/*
77-
mp_lexer_t *mp_lexer_new_from_file(const char *filename) {
78-
mp_raise_OSError(MP_ENOENT);
79-
}
80-
*/
81-
82-
#if !MICROPY_VFS
83-
mp_import_stat_t mp_import_stat(const char *path) {
84-
return MP_IMPORT_STAT_NO_EXIST;
85-
}
86-
87-
mp_obj_t mp_builtin_open(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) {
88-
return mp_const_none;
89-
}
90-
MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_open_obj, 1, mp_builtin_open);
91-
#endif
92-
9376
void nlr_jump_fail(void *val) {
9477
for (;;) {
9578
}

Diff for: ports/samd/mpconfigport.h

-9
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,6 @@
9999
#define mp_type_fileio mp_type_vfs_lfs1_fileio
100100
#define mp_type_textio mp_type_vfs_lfs1_textio
101101

102-
// Use VFS's functions for import stat and builtin open
103-
#define mp_import_stat mp_vfs_import_stat
104-
#define mp_builtin_open_obj mp_vfs_open_obj
105-
106-
// Hooks to add builtins
107-
108-
#define MICROPY_PORT_BUILTINS \
109-
{ MP_ROM_QSTR(MP_QSTR_open), MP_ROM_PTR(&mp_builtin_open_obj) },
110-
111102
#define MICROPY_PORT_ROOT_POINTERS \
112103
const char *readline_hist[8];
113104

Diff for: ports/stm32/mpconfigport.h

-9
Original file line numberDiff line numberDiff line change
@@ -163,15 +163,6 @@
163163
#define mp_type_textio mp_type_vfs_lfs2_textio
164164
#endif
165165

166-
// use vfs's functions for import stat and builtin open
167-
#define mp_import_stat mp_vfs_import_stat
168-
#define mp_builtin_open mp_vfs_open
169-
#define mp_builtin_open_obj mp_vfs_open_obj
170-
171-
// extra built in names to add to the global namespace
172-
#define MICROPY_PORT_BUILTINS \
173-
{ MP_ROM_QSTR(MP_QSTR_open), MP_ROM_PTR(&mp_builtin_open_obj) },
174-
175166
#if MICROPY_PY_PYB
176167
extern const struct _mp_obj_module_t pyb_module;
177168
#define PYB_BUILTIN_MODULE_CONSTANTS \

Diff for: ports/unix/mpconfigport.h

-5
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,6 @@ extern const struct _mp_print_t mp_stderr_print;
214214
#define MICROPY_EMERGENCY_EXCEPTION_BUF_SIZE (256)
215215
#define MICROPY_ASYNC_KBD_INTR (1)
216216

217-
#define mp_import_stat mp_vfs_import_stat
218-
#define mp_builtin_open_obj mp_vfs_open_obj
219217
#define mp_type_fileio mp_type_vfs_posix_fileio
220218
#define mp_type_textio mp_type_vfs_posix_textio
221219

@@ -273,9 +271,6 @@ void mp_unix_mark_exec(void);
273271
#endif
274272
#endif
275273

276-
#define MICROPY_PORT_BUILTINS \
277-
{ MP_ROM_QSTR(MP_QSTR_open), MP_ROM_PTR(&mp_builtin_open_obj) },
278-
279274
#define MP_STATE_PORT MP_STATE_VM
280275

281276
#if MICROPY_PY_BLUETOOTH

Diff for: ports/unix/variants/minimal/mpconfigvariant.h

-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@
109109

110110
#define MICROPY_PORT_ROOT_POINTERS \
111111

112-
#define mp_import_stat mp_vfs_import_stat
113112
#define mp_type_fileio mp_type_vfs_posix_fileio
114113
#define mp_type_textio mp_type_vfs_posix_textio
115114

Diff for: ports/windows/mpconfigport.h

-5
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,6 @@ extern const struct _mp_print_t mp_stderr_print;
171171
#define MICROPY_EMERGENCY_EXCEPTION_BUF_SIZE (256)
172172
#define MICROPY_KBD_EXCEPTION (1)
173173

174-
#define mp_import_stat mp_vfs_import_stat
175-
#define mp_builtin_open_obj mp_vfs_open_obj
176174
#define mp_type_fileio mp_type_vfs_posix_fileio
177175
#define mp_type_textio mp_type_vfs_posix_textio
178176

@@ -212,9 +210,6 @@ typedef long long mp_off_t;
212210
typedef long mp_off_t;
213211
#endif
214212

215-
#define MICROPY_PORT_BUILTINS \
216-
{ MP_ROM_QSTR(MP_QSTR_open), MP_ROM_PTR(&mp_builtin_open_obj) },
217-
218213
#if MICROPY_USE_READLINE == 1
219214
#define MICROPY_PORT_ROOT_POINTERS \
220215
char *readline_hist[50];

Diff for: ports/zephyr/main.c

+2-8
Original file line numberDiff line numberDiff line change
@@ -195,22 +195,16 @@ mp_lexer_t *mp_lexer_new_from_file(const char *filename) {
195195
}
196196
#endif
197197

198+
#if !MICROPY_VFS
198199
mp_import_stat_t mp_import_stat(const char *path) {
199-
#if MICROPY_VFS
200-
return mp_vfs_import_stat(path);
201-
#else
202200
return MP_IMPORT_STAT_NO_EXIST;
203-
#endif
204201
}
205202

206203
mp_obj_t mp_builtin_open(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) {
207-
#if MICROPY_VFS
208-
return mp_vfs_open(n_args, args, kwargs);
209-
#else
210204
return mp_const_none;
211-
#endif
212205
}
213206
MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_open_obj, 1, mp_builtin_open);
207+
#endif
214208

215209
NORETURN void nlr_jump_fail(void *val) {
216210
while (1) {

0 commit comments

Comments
 (0)