Skip to content

Commit 5ce1a03

Browse files
committed
py/makemoduledefs.py: Automatically declare delegation attr functions.
So that the delegation functions don't need to be put somewhere global, like in mpconfigport.h. That would otherwise make it hard for extension modules to use delegation. Signed-off-by: Damien George <[email protected]>
1 parent 44295c9 commit 5ce1a03

File tree

5 files changed

+11
-10
lines changed

5 files changed

+11
-10
lines changed

py/builtin.h

-2
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,6 @@ extern const mp_obj_module_t mp_module___main__;
132132
extern const mp_obj_module_t mp_module_builtins;
133133
extern const mp_obj_module_t mp_module_sys;
134134

135-
void mp_module_sys_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest);
136-
137135
// Modules needed by the parser when MICROPY_COMP_MODULE_CONST is enabled.
138136
extern const mp_obj_module_t mp_module_errno;
139137
extern const mp_obj_module_t mp_module_uctypes;

py/makemoduledefs.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,10 @@ def generate_module_delegations(delegations):
106106
if not delegations:
107107
return
108108

109-
print("\n#define MICROPY_MODULE_DELEGATIONS \\")
109+
print()
110+
for obj_module, fun_name in delegations:
111+
print("extern void {}(mp_obj_t self_in, qstr attr, mp_obj_t *dest);".format(fun_name))
112+
print("#define MICROPY_MODULE_DELEGATIONS \\")
110113
for obj_module, fun_name in delegations:
111114
print(
112115
" {{ MP_ROM_PTR(&{obj_module}), {fun_name} }}, \\".format(

py/modsys.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ MP_REGISTER_ROOT_POINTER(mp_obj_t sys_exitfunc);
336336
#if MICROPY_PY_SYS_ATTR_DELEGATION
337337
// Contains mutable sys attributes.
338338
MP_REGISTER_ROOT_POINTER(mp_obj_t sys_mutable[MP_SYS_MUTABLE_NUM]);
339-
MP_REGISTER_MODULE_DELEGATION(mp_module_sys, &mp_module_sys_attr);
339+
MP_REGISTER_MODULE_DELEGATION(mp_module_sys, mp_module_sys_attr);
340340
#endif
341341

342342
#endif // MICROPY_PY_SYS

py/objmodule.c

-6
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,6 @@
3434
#include "py/runtime.h"
3535
#include "py/builtin.h"
3636

37-
#ifndef NO_QSTR
38-
// Only include module definitions when not doing qstr extraction, because the
39-
// qstr extraction stage also generates this module definition header file.
40-
#include "genhdr/moduledefs.h"
41-
#endif
42-
4337
STATIC void module_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
4438
(void)kind;
4539
mp_obj_module_t *self = MP_OBJ_TO_PTR(self_in);

py/objmodule.h

+6
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@
2828

2929
#include "py/obj.h"
3030

31+
#ifndef NO_QSTR
32+
// Only include module definitions when not doing qstr extraction, because the
33+
// qstr extraction stage also generates this module definition header file.
34+
#include "genhdr/moduledefs.h"
35+
#endif
36+
3137
extern const mp_map_t mp_builtin_module_map;
3238
extern const mp_map_t mp_builtin_extensible_module_map;
3339

0 commit comments

Comments
 (0)