Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

qstrs behave differently between REPL and frozen modules -- demonstrated by network_wlan.c bugs. #8052

Closed
envirocoder opened this issue Nov 30, 2021 · 3 comments

Comments

@envirocoder
Copy link

envirocoder commented Nov 30, 2021

The following code doesn't work in _boot.py but does when run from the repl.

import network
ap = network.WLAN(network.AP_IF)
print(ap.config('mac'))
print(ap.config('dhcp_hostname'))

resulting in the error:

Traceback (most recent call last):
  File "_boot.py", line 4, in <module>
ValueError: unknown config param

I think this is related to string interning. Looking in corresponding generated frozen_content.c:

    0x16, MP_QSTR_ap & 0xff, MP_QSTR_ap >> 8, 
    0x11, MP_QSTR_print & 0xff, MP_QSTR_print >> 8, 
    0x11, MP_QSTR_ap & 0xff, MP_QSTR_ap >> 8, 
    0x14, MP_QSTR_config & 0xff, MP_QSTR_config >> 8, 
    0x10, MP_QSTR_mac & 0xff, MP_QSTR_mac >> 8, 
    0x36, 0x01, 
    0x34, 0x01, 
    0x59, 
    0x11, MP_QSTR_print & 0xff, MP_QSTR_print >> 8, 
    0x11, MP_QSTR_ap & 0xff, MP_QSTR_ap >> 8, 
    0x14, MP_QSTR_config & 0xff, MP_QSTR_config >> 8, 
    0x23, 0x00, 
    0x36, 0x01, 
    0x34, 0x01, 
    0x59, 
    0x51, 
    0x63, 
};
STATIC const mp_obj_str_t const_obj__boot__lt_module_gt__0 = {{&mp_type_str}, 18850, 13, (const byte*)"\x64\x68\x63\x70\x5f\x68\x6f\x73\x74\x6e\x61\x6d\x65"};

It appears MP_QSTR_mac is treated differently than \x64\x68\x63\x70\x5f\x68\x6f\x73\x74\x6e\x61\x6d\x65 (dhcp_hostname).

I think this means that the reference to case QS(MP_QSTR_dhcp_hostname): on

case QS(MP_QSTR_dhcp_hostname): {
doesn't match.

I found this when adding my own code to the network_wlan -- initially I thought it was my bug (see https://forum.micropython.org/viewtopic.php?f=3&t=11519) but I now think its something wider.

While, as was pointed out to me, only literals shorter than length 10 are supposed to be QSTRs, in this behaviour they're looked up from strings on the REPL but not from frozen.

@envirocoder envirocoder changed the title freezing of network_wlan.c broken. qstrs behave differently between REPL and frozen modules -- demonstrated by network_wlan.c broken. Dec 1, 2021
@envirocoder envirocoder changed the title qstrs behave differently between REPL and frozen modules -- demonstrated by network_wlan.c broken. qstrs behave differently between REPL and frozen modules -- demonstrated by network_wlan.c bugs. Dec 1, 2021
@dpgeorge
Copy link
Member

Thanks for the report. This was previously an issue on esp8266 and was fixed on that port, see #3442

dpgeorge added a commit to dpgeorge/micropython that referenced this issue Dec 10, 2021
Following on from a previous fix for the same problem made in
3a431fb.

Fixes issue micropython#8052.

Signed-off-by: Damien George <damien@micropython.org>
@dpgeorge
Copy link
Member

See #8077 for a fix.

dpgeorge added a commit to dpgeorge/micropython that referenced this issue Dec 14, 2021
Following on from a previous fix for the same problem made in
3a431fb.

Fixes issue micropython#8052.

Signed-off-by: Damien George <damien@micropython.org>
@dpgeorge
Copy link
Member

Fixed by 5adb1fa

leifbirger pushed a commit to leifbirger/micropython that referenced this issue Jun 14, 2023
Following on from a previous fix for the same problem made in
3a431fb.

Fixes issue micropython#8052.

Signed-off-by: Damien George <damien@micropython.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants