← index #9842PR #12301
Related · medium · value 1.826
QUERY · ISSUE

mpy-ld.py: preprocess c source before trying to find qstr-s

openby TsXoropened 2022-11-05updated 2022-11-05
enhancement

Currently, mpy-ld.py only directly search for MP_QSTR_* keywords in the source file declared in Makefile, in some situations, it will fail to find MP_QSTR_* keywords and make it fail to build:

  • It's too ugly to put all my source code in only one file, so I put some code which uses MP_QSTR_* in another file and includes it.
  • MP_QSTR_* expression is constructed with a macro.

I think expanding users' includes and macros with something like pcpp may help.

CANDIDATE · PULL REQUEST

py/dynruntime.h: Implement MP_OBJ_NEW_QSTR.

mergedby jimmoopened 2023-08-25updated 2023-09-01
py-core

Because mpy_ld.py doesn't know the target object representation, it emits
instances of MP_OBJ_NEW_QSTR(MP_QSTR_Foo) as const string objects, rather
than qstrs. However this doesn't work for map keys (e.g. for a locals dict)
because the map has all_keys_are_qstrs flag is set (and also auto-complete
requires the map keys to be qstrs).

Instead, emit them as regular qstrs, and make a functioning MP_OBJ_NEW_QSTR
function available (via native_to_obj, also used for e.g. making
integers).

Remove the now-unused code from mpy_ld.py to generate the constant object
table.

As this is a native ABI change, bump the .mpy sub-version to 6.2.

This fixes the issue discovered here: https://github.com/micropython/micropython/pull/11648#discussion_r1289541157

This work was funded through GitHub Sponsors.

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied