5 Commits

Author SHA1 Message Date
webreflection
c72a3e528d webassembly/objpyproxy: Avoid throwing on implicit symbols access.
Some checks failed
unix port / macos (push) Has been cancelled
unix port / qemu_mips (push) Has been cancelled
unix port / qemu_arm (push) Has been cancelled
unix port / qemu_riscv64 (push) Has been cancelled
unix port / sanitize_address (push) Has been cancelled
unix port / sanitize_undefined (push) Has been cancelled
webassembly port / build (push) Has been cancelled
windows port / build-vs (Debug, x64, dev, 2017, [15, 16)) (push) Has been cancelled
windows port / build-vs (Debug, x64, dev, 2022, [17, 18)) (push) Has been cancelled
windows port / build-vs (Debug, x86, dev, 2017, [15, 16)) (push) Has been cancelled
windows port / build-vs (Debug, x86, dev, 2022, [17, 18)) (push) Has been cancelled
windows port / build-vs (Release, x64, dev, 2017, [15, 16)) (push) Has been cancelled
windows port / build-vs (Release, x64, dev, 2019, [16, 17)) (push) Has been cancelled
windows port / build-vs (Release, x64, dev, 2022, [17, 18)) (push) Has been cancelled
windows port / build-vs (Release, x64, standard, 2017, [15, 16)) (push) Has been cancelled
windows port / build-vs (Release, x64, standard, 2019, [16, 17)) (push) Has been cancelled
windows port / build-vs (Release, x64, standard, 2022, [17, 18)) (push) Has been cancelled
windows port / build-vs (Release, x86, dev, 2017, [15, 16)) (push) Has been cancelled
windows port / build-vs (Release, x86, dev, 2019, [16, 17)) (push) Has been cancelled
windows port / build-vs (Release, x86, dev, 2022, [17, 18)) (push) Has been cancelled
windows port / build-vs (Release, x86, standard, 2017, [15, 16)) (push) Has been cancelled
windows port / build-vs (Release, x86, standard, 2019, [16, 17)) (push) Has been cancelled
windows port / build-vs (Release, x86, standard, 2022, [17, 18)) (push) Has been cancelled
windows port / build-mingw (i686, mingw32, dev) (push) Has been cancelled
windows port / build-mingw (i686, mingw32, standard) (push) Has been cancelled
windows port / build-mingw (x86_64, mingw64, dev) (push) Has been cancelled
windows port / build-mingw (x86_64, mingw64, standard) (push) Has been cancelled
windows port / cross-build-on-linux (push) Has been cancelled
zephyr port / build (push) Has been cancelled
Python code lint and formatting with ruff / ruff (push) Has been cancelled
This commit improves get handling by guarding against implicit unknown
symbols accessed directly by specific JS native APIs.

Fixes issue #17657.

Signed-off-by: Andrea Giammarchi <andrea.giammarchi@gmail.com>
2025-07-17 14:37:53 +10:00
Anson Mansfield
554f114f18 examples/rp2/pio_uart_rx.py: Fix use of PIO constants.
Running the unmodified `pio_uart_rx.py` example by uploading the file and
importing it doesn't succeed, and instead emits a NameError at line 26.

Signed-off-by: Anson Mansfield <amansfield@mantaro.com>
2025-07-17 14:31:42 +10:00
Damien George
0b698b8241 rp2/mpnetworkport: Deregister all sys timeouts when netif is removed.
When mDNS is active on a netif it registers a lot of timeouts, namely:

    mdns_probe_and_announce
    mdns_handle_tc_question

    mdns_multicast_probe_timeout_reset_ipv4
    mdns_multicast_timeout_25ttl_reset_ipv4
    mdns_multicast_timeout_reset_ipv4
    mdns_send_multicast_msg_delayed_ipv4
    mdns_send_unicast_msg_delayed_ipv4

    mdns_multicast_probe_timeout_reset_ipv6
    mdns_multicast_timeout_25ttl_reset_ipv6
    mdns_multicast_timeout_reset_ipv6
    mdns_send_multicast_msg_delayed_ipv6
    mdns_send_unicast_msg_delayed_ipv6

These may still be active after a netif is removed, and if they are called
they will find that the mDNS state pointer in the netif is NULL and they
will crash.

These functions could be explicitly removed using `sys_untimeout()`, but
`mdns_handle_tc_question()` is static so it's not possible to access it.
Instead use the new `sys_untimeout_all_with_arg()` helper to deregister all
timeout callbacks when a netif is removed.

Fixes issue #17621.

Signed-off-by: Damien George <damien@micropython.org>
2025-07-17 13:39:10 +10:00
Damien George
cf490ed346 extmod/network_lwip: Add sys_untimeout_all_with_arg helper function.
Really lwIP should provide this, to deregister all callbacks on the given
netif.

Signed-off-by: Damien George <damien@micropython.org>
2025-07-17 13:38:58 +10:00
Damien George
8504391766 alif/lwip_inc: Refactor lwipopts.h to use extmod's common options.
This change is a no-op for the firmware.

Signed-off-by: Damien George <damien@micropython.org>
2025-07-17 13:28:24 +10:00
9 changed files with 76 additions and 65 deletions

View File

@@ -23,7 +23,7 @@ PIO_RX_PIN = Pin(3, Pin.IN, Pin.PULL_UP)
@asm_pio(
autopush=True,
push_thresh=8,
in_shiftdir=rp2.PIO.SHIFT_RIGHT,
in_shiftdir=PIO.SHIFT_RIGHT,
fifo_join=PIO.JOIN_RX,
)
def uart_rx_mini():
@@ -42,7 +42,7 @@ def uart_rx_mini():
@asm_pio(
in_shiftdir=rp2.PIO.SHIFT_RIGHT,
in_shiftdir=PIO.SHIFT_RIGHT,
)
def uart_rx():
# fmt: off

View File

@@ -28,6 +28,9 @@
#include "py/mpconfig.h"
// This is needed to access `next_timeout` via `sys_timeouts_get_next_timeout()`.
#define LWIP_TESTMODE 1
// This sys-arch protection is not needed.
// Ports either protect lwIP code with flags, or run it at PendSV priority.
#define SYS_ARCH_DECL_PROTECT(lev) do { } while (0)

View File

@@ -82,6 +82,9 @@ extern const struct _mp_obj_type_t mp_network_ppp_lwip_type;
#endif
struct netif;
void sys_untimeout_all_with_arg(void *arg);
void mod_network_lwip_init(void);
void mod_network_lwip_poll_wrapper(uint32_t ticks_ms);
mp_obj_t mod_network_nic_ifconfig(struct netif *netif, size_t n_args, const mp_obj_t *args);

View File

@@ -52,6 +52,19 @@ int mp_mod_network_prefer_dns_use_ip_version = 4;
// Implementations of network methods that can be used by any interface.
// This follows sys_untimeout but removes all timeouts with the given argument.
void sys_untimeout_all_with_arg(void *arg) {
for (struct sys_timeo **t = sys_timeouts_get_next_timeout(); *t != NULL;) {
if ((*t)->arg == arg) {
struct sys_timeo *next = (*t)->next;
memp_free(MEMP_SYS_TIMEOUT, *t);
*t = next;
} else {
t = &(*t)->next;
}
}
}
// This function provides the implementation of nic.ifconfig, is deprecated and will be removed.
// Use network.ipconfig and nic.ipconfig instead.
mp_obj_t mod_network_nic_ifconfig(struct netif *netif, size_t n_args, const mp_obj_t *args) {

View File

@@ -1,49 +1,13 @@
#ifndef MICROPY_INCLUDED_ALIF_LWIP_LWIPOPTS_H
#define MICROPY_INCLUDED_ALIF_LWIP_LWIPOPTS_H
#include <stdint.h>
// This protection is not needed, instead we execute all lwIP code at PendSV priority
#define SYS_ARCH_DECL_PROTECT(lev) do { } while (0)
#define SYS_ARCH_PROTECT(lev) do { } while (0)
#define SYS_ARCH_UNPROTECT(lev) do { } while (0)
#define NO_SYS 1
#define SYS_LIGHTWEIGHT_PROT 1
#define MEM_ALIGNMENT 4
#define LWIP_CHKSUM_ALGORITHM 3
#define LWIP_CHECKSUM_CTRL_PER_NETIF 1
#define LWIP_ARP 1
#define LWIP_ETHERNET 1
#define LWIP_RAW 1
#define LWIP_NETCONN 0
#define LWIP_SOCKET 0
#define LWIP_STATS 0
#define LWIP_NETIF_HOSTNAME 1
#define LWIP_NETIF_EXT_STATUS_CALLBACK 1
#define LWIP_LOOPIF_MULTICAST 1
#define LWIP_LOOPBACK_MAX_PBUFS 8
#define LWIP_IPV6 0
#define LWIP_DHCP 1
#define LWIP_DHCP_CHECK_LINK_UP 1
#define LWIP_DHCP_DOES_ACD_CHECK 0 // to speed DHCP up
#define LWIP_DNS 1
#define LWIP_DNS_SUPPORT_MDNS_QUERIES 1
#define LWIP_MDNS_RESPONDER 1
#define LWIP_IGMP 1
#define LWIP_NUM_NETIF_CLIENT_DATA LWIP_MDNS_RESPONDER
#define MEMP_NUM_UDP_PCB (4 + LWIP_MDNS_RESPONDER)
#define MEMP_NUM_SYS_TIMEOUT (LWIP_NUM_SYS_TIMEOUT_INTERNAL + LWIP_MDNS_RESPONDER)
#define SO_REUSE 1
#define TCP_LISTEN_BACKLOG 1
extern uint64_t se_services_rand64(void);
#define LWIP_RAND() se_services_rand64()
#define MEM_SIZE (16 * 1024)
@@ -55,6 +19,9 @@ extern uint64_t se_services_rand64(void);
#define TCP_QUEUE_OOSEQ (1)
#define MEMP_NUM_TCP_SEG (2 * TCP_SND_QUEUELEN)
typedef uint32_t sys_prot_t;
// Include common lwIP configuration.
#include "extmod/lwip-include/lwipopts_common.h"
uint64_t se_services_rand64(void);
#endif // MICROPY_INCLUDED_ALIF_LWIP_LWIPOPTS_H

View File

@@ -30,6 +30,7 @@
#if MICROPY_PY_LWIP
#include "extmod/modnetwork.h"
#include "shared/runtime/softtimer.h"
#include "lwip/netif.h"
#include "lwip/timeouts.h"
@@ -183,6 +184,10 @@ static void mp_network_netif_status_cb(struct netif *netif, netif_nsc_reason_t r
mp_network_soft_timer.mode = SOFT_TIMER_MODE_PERIODIC;
soft_timer_reinsert(&mp_network_soft_timer, LWIP_TICK_RATE_MS);
}
if (reason == LWIP_NSC_NETIF_REMOVED) {
sys_untimeout_all_with_arg(netif);
}
}
#endif // MICROPY_PY_LWIP

View File

@@ -165,34 +165,35 @@ const py_proxy_handler = {
if (prop === "_ref") {
return target._ref;
}
if (prop === "then") {
return null;
}
if (prop === Symbol.iterator) {
// Get the Python object iterator, and return a JavaScript generator.
const iter_ref = Module.ccall(
"proxy_c_to_js_get_iter",
"number",
["number"],
[target._ref],
);
return function* () {
const value = Module._malloc(3 * 4);
while (true) {
const valid = Module.ccall(
"proxy_c_to_js_iternext",
"number",
["number", "pointer"],
[iter_ref, value],
);
if (!valid) {
break;
// ignore both then and all symbols but Symbol.iterator
if (prop === "then" || typeof prop !== "string") {
if (prop === Symbol.iterator) {
// Get the Python object iterator, and return a JavaScript generator.
const iter_ref = Module.ccall(
"proxy_c_to_js_get_iter",
"number",
["number"],
[target._ref],
);
return function* () {
const value = Module._malloc(3 * 4);
while (true) {
const valid = Module.ccall(
"proxy_c_to_js_iternext",
"number",
["number", "pointer"],
[iter_ref, value],
);
if (!valid) {
break;
}
yield proxy_convert_mp_to_js_obj_jsside(value);
}
yield proxy_convert_mp_to_js_obj_jsside(value);
}
Module._free(value);
};
Module._free(value);
};
}
return undefined;
}
const value = Module._malloc(3 * 4);

View File

@@ -0,0 +1,14 @@
// Test `<py-obj> get <attr>` on the JavaScript side, which tests PyProxy.get.
const mp = await (await import(process.argv[2])).loadMicroPython();
mp.runPython(`
x = {"a": 1}
`);
const x = mp.globals.get("x");
console.log(x.a === 1);
console.log(x.b === undefined);
console.log(typeof x[Symbol.iterator] === "function");
console.log(x[Symbol.toStringTag] === undefined);
console.log(x.then === undefined);

View File

@@ -0,0 +1,5 @@
true
true
true
true
true