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
esp32: socket.bind() fails with a strange error. #9410
Comments
Thanks for the report. When frozen, that tuple used as the argument to bind turns in to: static const mp_obj_int_t const_obj__boot_0_1 = {{&mp_type_int}, {.neg=0, .fixed_dig=1, .alloc=1, .len=1, .dig=(uint16_t*)(const uint16_t[]){0x3039}}};
static const mp_rom_obj_tuple_t const_obj__boot_0 = {{&mp_type_tuple}, 2, {
MP_ROM_QSTR(MP_QSTR_0_dot_0_dot_0_dot_0),
MP_ROM_PTR(&const_obj__boot_0_1),
}}; You can see that the port number is encoded as a big int. The code for bind that extracts the port number assumes it's a small int: static int _socket_getaddrinfo2(const mp_obj_t host, const mp_obj_t portx, struct addrinfo **resp) {
const struct addrinfo hints = {
.ai_family = AF_INET,
.ai_socktype = SOCK_STREAM,
};
mp_obj_t port = portx;
if (mp_obj_is_small_int(port)) {
... So the fix is to change that Also, it should probable be frozen as a small int, so that would be a good thing to improve as well. |
Thank you for the swift reply. It's always impressive to see how you know every little detail and dependency of MicroPython. |
Thanks for confirming. I will fix it. |
All I can say: I am impressed! |
Because the value may be a big integer, which is still a valid type to use. Fixes issue #9410. Signed-off-by: Damien George <damien@micropython.org>
Fixed by 3abcfb9 |
Because the value may be a big integer, which is still a valid type to use. Fixes issue micropython#9410. Signed-off-by: Damien George <damien@micropython.org>
Because the value may be a big integer, which is still a valid type to use. Fixes issue micropython#9410. Signed-off-by: Damien George <damien@micropython.org>
Firmware version:
MicroPython v1.19.1-443-g30e50ab19 on 2022-09-25; ESP32 module with ESP32
orMicroPython v1.19.1-443-g30e50ab19 on 2022-09-25; ESP32 module (spiram) with ESP32
esp-idf version 4.4
This little script:
Causes the error:
But only if it is executed as frozen bytecode. Importing it as .py or .mpy file from the file system succeeds. Changing the last line to:
or using a symbol (but not a const) for the port number works as well.
Thanks to @uraich for pointing at that error.
The text was updated successfully, but these errors were encountered: