kopia lustrzana https://github.com/micropython/micropython
Porównaj commity
12 Commity
e88c8feadf
...
85ca6238ea
Autor | SHA1 | Data |
---|---|---|
jonfoster | 85ca6238ea | |
Damien George | 49ce7a6075 | |
Angus Gratton | 6877987002 | |
Angus Gratton | 4bed614e70 | |
Vonasmic | ce491ab0d1 | |
stijn | 40f7e9ce20 | |
Michiel W. Beijen | 3129b69e0f | |
Simon Wood | 19844b4983 | |
J. Neuschäfer | f76cf29402 | |
Angus Gratton | d11ca092f7 | |
Jon Foster | 6121f6890c | |
Jon Foster | 0d25513098 |
|
@ -8,9 +8,15 @@ on:
|
|||
- 'tools/**'
|
||||
- 'py/**'
|
||||
- 'extmod/**'
|
||||
- 'shared/**'
|
||||
- 'lib/**'
|
||||
- 'ports/bare-arm/**'
|
||||
- 'ports/mimxrt/**'
|
||||
- 'ports/minimal/**'
|
||||
- 'ports/rp2/**'
|
||||
- 'ports/samd/**'
|
||||
- 'ports/stm32/**'
|
||||
- 'ports/unix/**'
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.ref }}
|
||||
|
|
|
@ -88,10 +88,11 @@ jobs:
|
|||
(cd ports/unix && gcov -o build-coverage/py ../../py/*.c || true)
|
||||
(cd ports/unix && gcov -o build-coverage/extmod ../../extmod/*.c || true)
|
||||
- name: Upload coverage to Codecov
|
||||
uses: codecov/codecov-action@v3
|
||||
uses: codecov/codecov-action@v4
|
||||
with:
|
||||
fail_ci_if_error: true
|
||||
verbose: true
|
||||
token: ${{ secrets.CODECOV_TOKEN }}
|
||||
- name: Print failures
|
||||
if: failure()
|
||||
run: tests/run-tests.py --print-failures
|
||||
|
|
|
@ -130,15 +130,25 @@ Methods
|
|||
|
||||
Second argument is a memoryview to read the USB control request
|
||||
data for this stage. The memoryview is only valid until the
|
||||
callback function returns.
|
||||
callback function returns. Data in this memoryview will be the same
|
||||
across each of the three stages of a single transfer.
|
||||
|
||||
A successful transfer consists of this callback being called in sequence
|
||||
for the three stages. Generally speaking, if a device wants to do
|
||||
something in response to a control request then it's best to wait until
|
||||
the ACK stage to confirm the host controller completed the transfer as
|
||||
expected.
|
||||
|
||||
The callback should return one of the following values:
|
||||
|
||||
- ``False`` to stall the endpoint and reject the transfer.
|
||||
- ``False`` to stall the endpoint and reject the transfer. It won't
|
||||
proceed to any remaining stages.
|
||||
- ``True`` to continue the transfer to the next stage.
|
||||
- A buffer object to provide data for this stage of the transfer.
|
||||
This should be a writable buffer for an ``OUT`` direction transfer, or a
|
||||
readable buffer with data for an ``IN`` direction transfer.
|
||||
- A buffer object can be returned at the SETUP stage when the transfer
|
||||
will send or receive additional data. Typically this is the case when
|
||||
the ``wLength`` field in the request has a non-zero value. This should
|
||||
be a writable buffer for an ``OUT`` direction transfer, or a readable
|
||||
buffer with data for an ``IN`` direction transfer.
|
||||
|
||||
- ``xfer_cb`` - This callback is called whenever a non-control
|
||||
transfer submitted by calling :func:`USBDevice.submit_xfer` completes.
|
||||
|
|
|
@ -361,7 +361,7 @@ mp_obj_t lwip_format_inet_addr(const ip_addr_t *ip, mp_uint_t port) {
|
|||
char ipstr[IPADDR_STRLEN_MAX];
|
||||
ipaddr_ntoa_r(ip, ipstr, sizeof(ipstr));
|
||||
mp_obj_t tuple[2] = {
|
||||
tuple[0] = mp_obj_new_str(ipstr, strlen(ipstr)),
|
||||
tuple[0] = mp_obj_new_str_0(ipstr),
|
||||
tuple[1] = mp_obj_new_int(port),
|
||||
};
|
||||
return mp_obj_new_tuple(2, tuple);
|
||||
|
|
|
@ -127,7 +127,7 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_network_country_obj, 0, 1, network_count
|
|||
|
||||
mp_obj_t mod_network_hostname(size_t n_args, const mp_obj_t *args) {
|
||||
if (n_args == 0) {
|
||||
return mp_obj_new_str(mod_network_hostname_data, strlen(mod_network_hostname_data));
|
||||
return mp_obj_new_str_0(mod_network_hostname_data);
|
||||
} else {
|
||||
size_t len;
|
||||
const char *str = mp_obj_str_get_data(args[0], &len);
|
||||
|
|
|
@ -263,7 +263,7 @@ static void openamp_ns_callback(struct rpmsg_device *rdev, const char *name, uin
|
|||
// the Name Service (NS) announcement containing the name of the channel.
|
||||
virtio_dev_obj_t *virtio_device = metal_container_of(rdev, virtio_dev_obj_t, rvdev);
|
||||
if (virtio_device->ns_callback != mp_const_none) {
|
||||
mp_call_function_2(virtio_device->ns_callback, mp_obj_new_int(dest), mp_obj_new_str(name, strlen(name)));
|
||||
mp_call_function_2(virtio_device->ns_callback, mp_obj_new_int(dest), mp_obj_new_str_0(name));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -70,7 +70,7 @@ void *mp_openamp_remoteproc_store_alloc(void) {
|
|||
static int openamp_remoteproc_store_open(void *store, const char *path, const void **image_data) {
|
||||
metal_log(METAL_LOG_DEBUG, "store_open(): %s\n", path);
|
||||
mp_obj_t args[2] = {
|
||||
mp_obj_new_str(path, strlen(path)),
|
||||
mp_obj_new_str_0(path),
|
||||
MP_OBJ_NEW_QSTR(MP_QSTR_rb),
|
||||
};
|
||||
|
||||
|
|
|
@ -307,7 +307,7 @@ static mp_obj_t ssl_context_get_ciphers(mp_obj_t self_in) {
|
|||
mp_obj_t list = mp_obj_new_list(0, NULL);
|
||||
for (const int *cipher_list = mbedtls_ssl_list_ciphersuites(); *cipher_list; ++cipher_list) {
|
||||
const char *cipher_name = mbedtls_ssl_get_ciphersuite_name(*cipher_list);
|
||||
mp_obj_list_append(list, MP_OBJ_FROM_PTR(mp_obj_new_str(cipher_name, strlen(cipher_name))));
|
||||
mp_obj_list_append(list, MP_OBJ_FROM_PTR(mp_obj_new_str_0(cipher_name)));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
@ -572,8 +572,8 @@ static mp_obj_t mod_ssl_cipher(mp_obj_t o_in) {
|
|||
mp_obj_ssl_socket_t *o = MP_OBJ_TO_PTR(o_in);
|
||||
const char *cipher_suite = mbedtls_ssl_get_ciphersuite(&o->ssl);
|
||||
const char *tls_version = mbedtls_ssl_get_version(&o->ssl);
|
||||
mp_obj_t tuple[2] = {mp_obj_new_str(cipher_suite, strlen(cipher_suite)),
|
||||
mp_obj_new_str(tls_version, strlen(tls_version))};
|
||||
mp_obj_t tuple[2] = {mp_obj_new_str_0(cipher_suite),
|
||||
mp_obj_new_str_0(tls_version)};
|
||||
|
||||
return mp_obj_new_tuple(2, tuple);
|
||||
}
|
||||
|
|
|
@ -146,7 +146,7 @@ static void handle_op(mp_obj_webrepl_t *self) {
|
|||
// Handle operations requiring opened file
|
||||
|
||||
mp_obj_t open_args[2] = {
|
||||
mp_obj_new_str(self->hdr.fname, strlen(self->hdr.fname)),
|
||||
mp_obj_new_str_0(self->hdr.fname),
|
||||
MP_OBJ_NEW_QSTR(MP_QSTR_rb)
|
||||
};
|
||||
|
||||
|
|
|
@ -230,7 +230,7 @@ static mp_obj_t network_esp_hosted_config(size_t n_args, const mp_obj_t *args, m
|
|||
case MP_QSTR_essid: {
|
||||
esp_hosted_netinfo_t netinfo;
|
||||
esp_hosted_wifi_netinfo(&netinfo);
|
||||
return mp_obj_new_str(netinfo.ssid, strlen(netinfo.ssid));
|
||||
return mp_obj_new_str_0(netinfo.ssid);
|
||||
}
|
||||
case MP_QSTR_security: {
|
||||
esp_hosted_netinfo_t netinfo;
|
||||
|
|
|
@ -113,7 +113,7 @@ mp_obj_t mod_network_ipconfig(size_t n_args, const mp_obj_t *args, mp_map_t *kwa
|
|||
case MP_QSTR_dns: {
|
||||
char addr_str[IPADDR_STRLEN_MAX];
|
||||
ipaddr_ntoa_r(dns_getserver(0), addr_str, sizeof(addr_str));
|
||||
return mp_obj_new_str(addr_str, strlen(addr_str));
|
||||
return mp_obj_new_str_0(addr_str);
|
||||
}
|
||||
case MP_QSTR_prefer: {
|
||||
return MP_OBJ_NEW_SMALL_INT(mp_mod_network_prefer_dns_use_ip_version);
|
||||
|
@ -219,7 +219,7 @@ mp_obj_t mod_network_nic_ipconfig(struct netif *netif, size_t n_args, const mp_o
|
|||
char addr_str[IPADDR_STRLEN_MAX];
|
||||
ipaddr_ntoa_r(netif_ip_addr6(netif, i), addr_str, sizeof(addr_str));
|
||||
mp_obj_t tuple[4] = {
|
||||
mp_obj_new_str(addr_str, strlen(addr_str)),
|
||||
mp_obj_new_str_0(addr_str),
|
||||
MP_OBJ_NEW_SMALL_INT(netif_ip6_addr_state(netif, i)),
|
||||
MP_OBJ_NEW_SMALL_INT(netif_ip6_addr_pref_life(netif, i)), // preferred
|
||||
MP_OBJ_NEW_SMALL_INT(netif_ip6_addr_valid_life(netif, i))
|
||||
|
|
|
@ -386,7 +386,7 @@ static mp_obj_t network_ninaw10_config(size_t n_args, const mp_obj_t *args, mp_m
|
|||
case MP_QSTR_ssid: {
|
||||
nina_netinfo_t netinfo;
|
||||
nina_netinfo(&netinfo);
|
||||
return mp_obj_new_str(netinfo.ssid, strlen(netinfo.ssid));
|
||||
return mp_obj_new_str_0(netinfo.ssid);
|
||||
}
|
||||
case MP_QSTR_security: {
|
||||
nina_netinfo_t netinfo;
|
||||
|
|
|
@ -139,7 +139,7 @@ mp_import_stat_t mp_vfs_import_stat(const char *path) {
|
|||
}
|
||||
|
||||
// delegate to vfs.stat() method
|
||||
mp_obj_t path_o = mp_obj_new_str(path_out, strlen(path_out));
|
||||
mp_obj_t path_o = mp_obj_new_str_0(path_out);
|
||||
mp_obj_t stat;
|
||||
nlr_buf_t nlr;
|
||||
if (nlr_push(&nlr) == 0) {
|
||||
|
|
|
@ -144,7 +144,7 @@ static mp_obj_t mp_vfs_fat_ilistdir_it_iternext(mp_obj_t self_in) {
|
|||
// make 4-tuple with info about this entry
|
||||
mp_obj_tuple_t *t = MP_OBJ_TO_PTR(mp_obj_new_tuple(4, NULL));
|
||||
if (self->is_str) {
|
||||
t->items[0] = mp_obj_new_str(fn, strlen(fn));
|
||||
t->items[0] = mp_obj_new_str_0(fn);
|
||||
} else {
|
||||
t->items[0] = mp_obj_new_bytes((const byte *)fn, strlen(fn));
|
||||
}
|
||||
|
@ -291,7 +291,7 @@ static mp_obj_t fat_vfs_getcwd(mp_obj_t vfs_in) {
|
|||
if (res != FR_OK) {
|
||||
mp_raise_OSError(fresult_to_errno_table[res]);
|
||||
}
|
||||
return mp_obj_new_str(buf, strlen(buf));
|
||||
return mp_obj_new_str_0(buf);
|
||||
}
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(fat_vfs_getcwd_obj, fat_vfs_getcwd);
|
||||
|
||||
|
|
|
@ -192,7 +192,7 @@ static mp_obj_t MP_VFS_LFSx(ilistdir_it_iternext)(mp_obj_t self_in) {
|
|||
// make 4-tuple with info about this entry
|
||||
mp_obj_tuple_t *t = MP_OBJ_TO_PTR(mp_obj_new_tuple(4, NULL));
|
||||
if (self->is_str) {
|
||||
t->items[0] = mp_obj_new_str(info.name, strlen(info.name));
|
||||
t->items[0] = mp_obj_new_str_0(info.name);
|
||||
} else {
|
||||
t->items[0] = mp_obj_new_bytes((const byte *)info.name, strlen(info.name));
|
||||
}
|
||||
|
|
|
@ -194,7 +194,7 @@ static mp_obj_t vfs_posix_getcwd(mp_obj_t self_in) {
|
|||
}
|
||||
#endif
|
||||
}
|
||||
return mp_obj_new_str(ret, strlen(ret));
|
||||
return mp_obj_new_str_0(ret);
|
||||
}
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(vfs_posix_getcwd_obj, vfs_posix_getcwd);
|
||||
|
||||
|
@ -234,7 +234,7 @@ static mp_obj_t vfs_posix_ilistdir_it_iternext(mp_obj_t self_in) {
|
|||
mp_obj_tuple_t *t = MP_OBJ_TO_PTR(mp_obj_new_tuple(3, NULL));
|
||||
|
||||
if (self->is_str) {
|
||||
t->items[0] = mp_obj_new_str(fn, strlen(fn));
|
||||
t->items[0] = mp_obj_new_str_0(fn);
|
||||
} else {
|
||||
t->items[0] = mp_obj_new_bytes((const byte *)fn, strlen(fn));
|
||||
}
|
||||
|
|
|
@ -1074,7 +1074,7 @@ static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(wlan_mode_obj, 1, 2, wlan_mode);
|
|||
static mp_obj_t wlan_ssid(size_t n_args, const mp_obj_t *args) {
|
||||
wlan_obj_t *self = args[0];
|
||||
if (n_args == 1) {
|
||||
return mp_obj_new_str((const char *)self->ssid, strlen((const char *)self->ssid));
|
||||
return mp_obj_new_str_0((const char *)self->ssid);
|
||||
} else {
|
||||
size_t len;
|
||||
const char *ssid = mp_obj_str_get_data(args[1], &len);
|
||||
|
@ -1094,7 +1094,7 @@ static mp_obj_t wlan_auth(size_t n_args, const mp_obj_t *args) {
|
|||
} else {
|
||||
mp_obj_t security[2];
|
||||
security[0] = mp_obj_new_int(self->auth);
|
||||
security[1] = mp_obj_new_str((const char *)self->key, strlen((const char *)self->key));
|
||||
security[1] = mp_obj_new_str_0((const char *)self->key);
|
||||
return mp_obj_new_tuple(2, security);
|
||||
}
|
||||
} else {
|
||||
|
@ -1198,7 +1198,7 @@ static MP_DEFINE_CONST_FUN_OBJ_KW(wlan_irq_obj, 1, wlan_irq);
|
|||
// mp_obj_t connections = mp_obj_new_list(0, NULL);
|
||||
//
|
||||
// if (wlan_is_connected()) {
|
||||
// device[0] = mp_obj_new_str((const char *)wlan_obj.ssid_o, strlen((const char *)wlan_obj.ssid_o));
|
||||
// device[0] = mp_obj_new_str_0((const char *)wlan_obj.ssid_o);
|
||||
// device[1] = mp_obj_new_bytes((const byte *)wlan_obj.bssid, SL_BSSID_LENGTH);
|
||||
// // add the device to the list
|
||||
// mp_obj_list_append(connections, mp_obj_new_tuple(MP_ARRAY_SIZE(device), device));
|
||||
|
|
|
@ -156,7 +156,7 @@ static mp_obj_t esp32_partition_info(mp_obj_t self_in) {
|
|||
MP_OBJ_NEW_SMALL_INT(self->part->subtype),
|
||||
mp_obj_new_int_from_uint(self->part->address),
|
||||
mp_obj_new_int_from_uint(self->part->size),
|
||||
mp_obj_new_str(&self->part->label[0], strlen(&self->part->label[0])),
|
||||
mp_obj_new_str_0(&self->part->label[0]),
|
||||
mp_obj_new_bool(self->part->encrypted),
|
||||
};
|
||||
return mp_obj_new_tuple(6, tuple);
|
||||
|
|
|
@ -941,7 +941,7 @@ static mp_obj_t esp_socket_getaddrinfo(size_t n_args, const mp_obj_t *args) {
|
|||
mp_obj_new_int(resi->ai_family),
|
||||
mp_obj_new_int(resi->ai_socktype),
|
||||
mp_obj_new_int(resi->ai_protocol),
|
||||
mp_obj_new_str(resi->ai_canonname, strlen(resi->ai_canonname)),
|
||||
mp_obj_new_str_0(resi->ai_canonname),
|
||||
mp_const_none
|
||||
};
|
||||
|
||||
|
@ -952,7 +952,7 @@ static mp_obj_t esp_socket_getaddrinfo(size_t n_args, const mp_obj_t *args) {
|
|||
char buf[16];
|
||||
ip4addr_ntoa_r(&ip4_addr, buf, sizeof(buf));
|
||||
mp_obj_t inaddr_objs[2] = {
|
||||
mp_obj_new_str(buf, strlen(buf)),
|
||||
mp_obj_new_str_0(buf),
|
||||
mp_obj_new_int(ntohs(addr->sin_port))
|
||||
};
|
||||
addrinfo_objs[4] = mp_obj_new_tuple(2, inaddr_objs);
|
||||
|
|
|
@ -158,7 +158,7 @@ mp_obj_t esp_ifname(esp_netif_t *netif) {
|
|||
char ifname[NETIF_NAMESIZE + 1] = {0};
|
||||
mp_obj_t ret = mp_const_none;
|
||||
if (esp_netif_get_netif_impl_name(netif, ifname) == ESP_OK && ifname[0] != 0) {
|
||||
ret = mp_obj_new_str((char *)ifname, strlen(ifname));
|
||||
ret = mp_obj_new_str_0((char *)ifname);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -308,7 +308,7 @@ static mp_obj_t ppp_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs
|
|||
char ifname[NETIF_NAMESIZE + 1] = {0};
|
||||
netif_index_to_name(netif_get_index(pppif), ifname);
|
||||
if (ifname[0] != 0) {
|
||||
val = mp_obj_new_str((char *)ifname, strlen(ifname));
|
||||
val = mp_obj_new_str_0((char *)ifname);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -640,7 +640,7 @@ static mp_obj_t network_wlan_config(size_t n_args, const mp_obj_t *args, mp_map_
|
|||
case MP_QSTR_essid:
|
||||
switch (self->if_id) {
|
||||
case ESP_IF_WIFI_STA:
|
||||
val = mp_obj_new_str((char *)cfg.sta.ssid, strlen((char *)cfg.sta.ssid));
|
||||
val = mp_obj_new_str_0((char *)cfg.sta.ssid);
|
||||
break;
|
||||
case ESP_IF_WIFI_AP:
|
||||
val = mp_obj_new_str((char *)cfg.ap.ssid, cfg.ap.ssid_len);
|
||||
|
|
|
@ -456,7 +456,7 @@ static mp_obj_t esp_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs
|
|||
case MP_QSTR_ssid:
|
||||
case MP_QSTR_essid:
|
||||
if (self->if_id == STATION_IF) {
|
||||
val = mp_obj_new_str((char *)cfg.sta.ssid, strlen((char *)cfg.sta.ssid));
|
||||
val = mp_obj_new_str_0((char *)cfg.sta.ssid);
|
||||
} else {
|
||||
val = mp_obj_new_str((char *)cfg.ap.ssid, cfg.ap.ssid_len);
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ You can also build the standard CMake way. The final firmware is found in
|
|||
the top-level of the CMake build directory (`build` by default) and is
|
||||
called `firmware.uf2`.
|
||||
|
||||
If you are using a different board other than a Rasoberry Pi Pico, then you should
|
||||
If you are using a board other than a Raspberry Pi Pico, you should
|
||||
pass the board name to the build; e.g. for Raspberry Pi Pico W:
|
||||
|
||||
$ make BOARD=RPI_PICO_W submodules
|
||||
|
|
|
@ -127,10 +127,10 @@ static void mp_machine_lightsleep(size_t n_args, const mp_obj_t *args) {
|
|||
|
||||
const uint32_t xosc_hz = XOSC_MHZ * 1000000;
|
||||
|
||||
uint32_t my_interrupts = save_and_disable_interrupts();
|
||||
uint32_t my_interrupts = mp_thread_begin_atomic_section();
|
||||
#if MICROPY_PY_NETWORK_CYW43
|
||||
if (cyw43_has_pending && cyw43_poll != NULL) {
|
||||
restore_interrupts(my_interrupts);
|
||||
mp_thread_end_atomic_section(my_interrupts);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
@ -165,8 +165,15 @@ static void mp_machine_lightsleep(size_t n_args, const mp_obj_t *args) {
|
|||
} else {
|
||||
uint32_t sleep_en0 = clocks_hw->sleep_en0;
|
||||
uint32_t sleep_en1 = clocks_hw->sleep_en1;
|
||||
bool timer3_enabled = irq_is_enabled(3);
|
||||
|
||||
clocks_hw->sleep_en0 = CLOCKS_SLEEP_EN0_CLK_RTC_RTC_BITS;
|
||||
if (use_timer_alarm) {
|
||||
// Make sure ALARM3/IRQ3 is enabled on _this_ core
|
||||
timer_hw->inte |= 1 << 3;
|
||||
if (!timer3_enabled) {
|
||||
irq_set_enabled(3, true);
|
||||
}
|
||||
// Use timer alarm to wake.
|
||||
clocks_hw->sleep_en1 = CLOCKS_SLEEP_EN1_CLK_SYS_TIMER_BITS;
|
||||
timer_hw->alarm[3] = timer_hw->timerawl + delay_ms * 1000;
|
||||
|
@ -177,6 +184,9 @@ static void mp_machine_lightsleep(size_t n_args, const mp_obj_t *args) {
|
|||
scb_hw->scr |= M0PLUS_SCR_SLEEPDEEP_BITS;
|
||||
__wfi();
|
||||
scb_hw->scr &= ~M0PLUS_SCR_SLEEPDEEP_BITS;
|
||||
if (!timer3_enabled) {
|
||||
irq_set_enabled(3, false);
|
||||
}
|
||||
clocks_hw->sleep_en0 = sleep_en0;
|
||||
clocks_hw->sleep_en1 = sleep_en1;
|
||||
}
|
||||
|
@ -186,7 +196,7 @@ static void mp_machine_lightsleep(size_t n_args, const mp_obj_t *args) {
|
|||
|
||||
// Bring back all clocks.
|
||||
clocks_init();
|
||||
restore_interrupts(my_interrupts);
|
||||
mp_thread_end_atomic_section(my_interrupts);
|
||||
}
|
||||
|
||||
NORETURN static void mp_machine_deepsleep(size_t n_args, const mp_obj_t *args) {
|
||||
|
|
|
@ -387,7 +387,7 @@ static mp_obj_t extra_coverage(void) {
|
|||
mp_printf(&mp_plat_print, "# str\n");
|
||||
|
||||
// intern string
|
||||
mp_printf(&mp_plat_print, "%d\n", mp_obj_is_qstr(mp_obj_str_intern(mp_obj_new_str("intern me", 9))));
|
||||
mp_printf(&mp_plat_print, "%d\n", mp_obj_is_qstr(mp_obj_str_intern(mp_obj_new_str_0("intern me"))));
|
||||
}
|
||||
|
||||
// bytearray
|
||||
|
@ -463,12 +463,12 @@ static mp_obj_t extra_coverage(void) {
|
|||
// call mp_call_function_1_protected
|
||||
mp_call_function_1_protected(MP_OBJ_FROM_PTR(&mp_builtin_abs_obj), MP_OBJ_NEW_SMALL_INT(1));
|
||||
// call mp_call_function_1_protected with invalid args
|
||||
mp_call_function_1_protected(MP_OBJ_FROM_PTR(&mp_builtin_abs_obj), mp_obj_new_str("abc", 3));
|
||||
mp_call_function_1_protected(MP_OBJ_FROM_PTR(&mp_builtin_abs_obj), mp_obj_new_str_0("abc"));
|
||||
|
||||
// call mp_call_function_2_protected
|
||||
mp_call_function_2_protected(MP_OBJ_FROM_PTR(&mp_builtin_divmod_obj), MP_OBJ_NEW_SMALL_INT(1), MP_OBJ_NEW_SMALL_INT(1));
|
||||
// call mp_call_function_2_protected with invalid args
|
||||
mp_call_function_2_protected(MP_OBJ_FROM_PTR(&mp_builtin_divmod_obj), mp_obj_new_str("abc", 3), mp_obj_new_str("abc", 3));
|
||||
mp_call_function_2_protected(MP_OBJ_FROM_PTR(&mp_builtin_divmod_obj), mp_obj_new_str_0("abc"), mp_obj_new_str_0("abc"));
|
||||
|
||||
// mp_obj_int_get_uint_checked with non-negative small-int
|
||||
mp_printf(&mp_plat_print, "%d\n", (int)mp_obj_int_get_uint_checked(MP_OBJ_NEW_SMALL_INT(1)));
|
||||
|
@ -722,7 +722,7 @@ static mp_obj_t extra_coverage(void) {
|
|||
// mp_obj_is_integer accepts ints and booleans
|
||||
mp_printf(&mp_plat_print, "%d %d\n", mp_obj_is_integer(MP_OBJ_NEW_SMALL_INT(1)), mp_obj_is_integer(mp_obj_new_int_from_ll(1)));
|
||||
mp_printf(&mp_plat_print, "%d %d\n", mp_obj_is_integer(mp_const_true), mp_obj_is_integer(mp_const_false));
|
||||
mp_printf(&mp_plat_print, "%d %d\n", mp_obj_is_integer(mp_obj_new_str("1", 1)), mp_obj_is_integer(mp_const_none));
|
||||
mp_printf(&mp_plat_print, "%d %d\n", mp_obj_is_integer(mp_obj_new_str_0("1")), mp_obj_is_integer(mp_const_none));
|
||||
|
||||
// mp_obj_is_int accepts small int and object ints
|
||||
mp_printf(&mp_plat_print, "%d %d\n", mp_obj_is_int(MP_OBJ_NEW_SMALL_INT(1)), mp_obj_is_int(mp_obj_new_int_from_ll(1)));
|
||||
|
|
|
@ -639,7 +639,7 @@ MP_NOINLINE int main_(int argc, char **argv) {
|
|||
return invalid_args();
|
||||
}
|
||||
mp_obj_t import_args[4];
|
||||
import_args[0] = mp_obj_new_str(argv[a + 1], strlen(argv[a + 1]));
|
||||
import_args[0] = mp_obj_new_str_0(argv[a + 1]);
|
||||
import_args[1] = import_args[2] = mp_const_none;
|
||||
// Ask __import__ to handle imported module specially - set its __name__
|
||||
// to __main__, and also return this leaf module, not top-level package
|
||||
|
|
|
@ -174,7 +174,7 @@ static mp_obj_t return_ffi_value(ffi_union_t *val, char type) {
|
|||
if (!s) {
|
||||
return mp_const_none;
|
||||
}
|
||||
return mp_obj_new_str(s, strlen(s));
|
||||
return mp_obj_new_str_0(s);
|
||||
}
|
||||
case 'v':
|
||||
return mp_const_none;
|
||||
|
|
|
@ -337,7 +337,7 @@ static mp_obj_t new_jobject(jobject jo) {
|
|||
return mp_const_none;
|
||||
} else if (JJ(IsInstanceOf, jo, String_class)) {
|
||||
const char *s = JJ(GetStringUTFChars, jo, NULL);
|
||||
mp_obj_t ret = mp_obj_new_str(s, strlen(s));
|
||||
mp_obj_t ret = mp_obj_new_str_0(s);
|
||||
JJ(ReleaseStringUTFChars, jo, s);
|
||||
return ret;
|
||||
} else if (JJ(IsInstanceOf, jo, Class_class)) {
|
||||
|
|
|
@ -40,7 +40,7 @@ static mp_obj_t mp_os_getenv(size_t n_args, const mp_obj_t *args) {
|
|||
}
|
||||
return mp_const_none;
|
||||
}
|
||||
return mp_obj_new_str(s, strlen(s));
|
||||
return mp_obj_new_str_0(s);
|
||||
}
|
||||
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_os_getenv_obj, 1, 2, mp_os_getenv);
|
||||
|
||||
|
|
|
@ -103,7 +103,7 @@ static void vfs_init(void) {
|
|||
int ret = 0;
|
||||
|
||||
#ifdef CONFIG_DISK_DRIVER_SDMMC
|
||||
mp_obj_t args[] = { mp_obj_new_str(CONFIG_SDMMC_VOLUME_NAME, strlen(CONFIG_SDMMC_VOLUME_NAME)) };
|
||||
mp_obj_t args[] = { mp_obj_new_str_0(CONFIG_SDMMC_VOLUME_NAME) };
|
||||
bdev = MP_OBJ_TYPE_GET_SLOT(&zephyr_disk_access_type, make_new)(&zephyr_disk_access_type, ARRAY_SIZE(args), 0, args);
|
||||
mount_point_str = "/sd";
|
||||
#elif defined(CONFIG_FLASH_MAP) && FLASH_AREA_LABEL_EXISTS(storage)
|
||||
|
@ -113,7 +113,7 @@ static void vfs_init(void) {
|
|||
#endif
|
||||
|
||||
if ((bdev != NULL)) {
|
||||
mount_point = mp_obj_new_str(mount_point_str, strlen(mount_point_str));
|
||||
mount_point = mp_obj_new_str_0(mount_point_str);
|
||||
ret = mp_vfs_mount_and_chdir_protected(bdev, mount_point);
|
||||
// TODO: if this failed, make a new file system and try to mount again
|
||||
}
|
||||
|
|
|
@ -92,7 +92,7 @@ static mp_obj_t format_inet_addr(struct sockaddr *addr, mp_obj_t port) {
|
|||
net_addr_ntop(addr->sa_family, &sockaddr_in6->sin6_addr, buf, sizeof(buf));
|
||||
mp_obj_tuple_t *tuple = mp_obj_new_tuple(addr->sa_family == AF_INET ? 2 : 4, NULL);
|
||||
|
||||
tuple->items[0] = mp_obj_new_str(buf, strlen(buf));
|
||||
tuple->items[0] = mp_obj_new_str_0(buf);
|
||||
// We employ the fact that port offset is the same for IPv4 & IPv6
|
||||
// not filled in
|
||||
// tuple->items[1] = mp_obj_new_int(ntohs(((struct sockaddr_in*)addr)->sin_port));
|
||||
|
|
|
@ -338,7 +338,7 @@ mp_obj_t mp_binary_get_val(char struct_type, char val_type, byte *p_base, byte *
|
|||
return (mp_obj_t)(mp_uint_t)val;
|
||||
} else if (val_type == 'S') {
|
||||
const char *s_val = (const char *)(uintptr_t)(mp_uint_t)val;
|
||||
return mp_obj_new_str(s_val, strlen(s_val));
|
||||
return mp_obj_new_str_0(s_val);
|
||||
#if MICROPY_PY_BUILTINS_FLOAT
|
||||
} else if (val_type == 'e') {
|
||||
return mp_obj_new_float_from_f(mp_decode_half_float(val));
|
||||
|
|
29
py/obj.h
29
py/obj.h
|
@ -753,20 +753,20 @@ typedef struct _mp_obj_full_type_t {
|
|||
// Do not use these directly, instead use MP_DEFINE_CONST_OBJ_TYPE.
|
||||
// Generated with:
|
||||
// for i in range(13):
|
||||
// print(f"#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_{i}(_struct_type, _typename, _name, _flags{''.join(f', f{j+1}, v{j+1}' for j in range(i))}) const _struct_type _typename = {{ .base = {{ &mp_type_type }}, .name = _name, .flags = _flags{''.join(f', .slot_index_##f{j+1} = {j+1}' for j in range(i))}{', .slots = { ' + ''.join(f'v{j+1}, ' for j in range(i)) + '}' if i else '' } }}")
|
||||
#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_0(_struct_type, _typename, _name, _flags) const _struct_type _typename = { .base = { &mp_type_type }, .name = _name, .flags = _flags }
|
||||
#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_1(_struct_type, _typename, _name, _flags, f1, v1) const _struct_type _typename = { .base = { &mp_type_type }, .name = _name, .flags = _flags, .slot_index_##f1 = 1, .slots = { v1, } }
|
||||
#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_2(_struct_type, _typename, _name, _flags, f1, v1, f2, v2) const _struct_type _typename = { .base = { &mp_type_type }, .name = _name, .flags = _flags, .slot_index_##f1 = 1, .slot_index_##f2 = 2, .slots = { v1, v2, } }
|
||||
#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_3(_struct_type, _typename, _name, _flags, f1, v1, f2, v2, f3, v3) const _struct_type _typename = { .base = { &mp_type_type }, .name = _name, .flags = _flags, .slot_index_##f1 = 1, .slot_index_##f2 = 2, .slot_index_##f3 = 3, .slots = { v1, v2, v3, } }
|
||||
#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_4(_struct_type, _typename, _name, _flags, f1, v1, f2, v2, f3, v3, f4, v4) const _struct_type _typename = { .base = { &mp_type_type }, .name = _name, .flags = _flags, .slot_index_##f1 = 1, .slot_index_##f2 = 2, .slot_index_##f3 = 3, .slot_index_##f4 = 4, .slots = { v1, v2, v3, v4, } }
|
||||
#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_5(_struct_type, _typename, _name, _flags, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5) const _struct_type _typename = { .base = { &mp_type_type }, .name = _name, .flags = _flags, .slot_index_##f1 = 1, .slot_index_##f2 = 2, .slot_index_##f3 = 3, .slot_index_##f4 = 4, .slot_index_##f5 = 5, .slots = { v1, v2, v3, v4, v5, } }
|
||||
#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_6(_struct_type, _typename, _name, _flags, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5, f6, v6) const _struct_type _typename = { .base = { &mp_type_type }, .name = _name, .flags = _flags, .slot_index_##f1 = 1, .slot_index_##f2 = 2, .slot_index_##f3 = 3, .slot_index_##f4 = 4, .slot_index_##f5 = 5, .slot_index_##f6 = 6, .slots = { v1, v2, v3, v4, v5, v6, } }
|
||||
#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_7(_struct_type, _typename, _name, _flags, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5, f6, v6, f7, v7) const _struct_type _typename = { .base = { &mp_type_type }, .name = _name, .flags = _flags, .slot_index_##f1 = 1, .slot_index_##f2 = 2, .slot_index_##f3 = 3, .slot_index_##f4 = 4, .slot_index_##f5 = 5, .slot_index_##f6 = 6, .slot_index_##f7 = 7, .slots = { v1, v2, v3, v4, v5, v6, v7, } }
|
||||
#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_8(_struct_type, _typename, _name, _flags, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5, f6, v6, f7, v7, f8, v8) const _struct_type _typename = { .base = { &mp_type_type }, .name = _name, .flags = _flags, .slot_index_##f1 = 1, .slot_index_##f2 = 2, .slot_index_##f3 = 3, .slot_index_##f4 = 4, .slot_index_##f5 = 5, .slot_index_##f6 = 6, .slot_index_##f7 = 7, .slot_index_##f8 = 8, .slots = { v1, v2, v3, v4, v5, v6, v7, v8, } }
|
||||
#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_9(_struct_type, _typename, _name, _flags, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5, f6, v6, f7, v7, f8, v8, f9, v9) const _struct_type _typename = { .base = { &mp_type_type }, .name = _name, .flags = _flags, .slot_index_##f1 = 1, .slot_index_##f2 = 2, .slot_index_##f3 = 3, .slot_index_##f4 = 4, .slot_index_##f5 = 5, .slot_index_##f6 = 6, .slot_index_##f7 = 7, .slot_index_##f8 = 8, .slot_index_##f9 = 9, .slots = { v1, v2, v3, v4, v5, v6, v7, v8, v9, } }
|
||||
#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_10(_struct_type, _typename, _name, _flags, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5, f6, v6, f7, v7, f8, v8, f9, v9, f10, v10) const _struct_type _typename = { .base = { &mp_type_type }, .name = _name, .flags = _flags, .slot_index_##f1 = 1, .slot_index_##f2 = 2, .slot_index_##f3 = 3, .slot_index_##f4 = 4, .slot_index_##f5 = 5, .slot_index_##f6 = 6, .slot_index_##f7 = 7, .slot_index_##f8 = 8, .slot_index_##f9 = 9, .slot_index_##f10 = 10, .slots = { v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, } }
|
||||
#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_11(_struct_type, _typename, _name, _flags, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5, f6, v6, f7, v7, f8, v8, f9, v9, f10, v10, f11, v11) const _struct_type _typename = { .base = { &mp_type_type }, .name = _name, .flags = _flags, .slot_index_##f1 = 1, .slot_index_##f2 = 2, .slot_index_##f3 = 3, .slot_index_##f4 = 4, .slot_index_##f5 = 5, .slot_index_##f6 = 6, .slot_index_##f7 = 7, .slot_index_##f8 = 8, .slot_index_##f9 = 9, .slot_index_##f10 = 10, .slot_index_##f11 = 11, .slots = { v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, } }
|
||||
#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_12(_struct_type, _typename, _name, _flags, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5, f6, v6, f7, v7, f8, v8, f9, v9, f10, v10, f11, v11, f12, v12) const _struct_type _typename = { .base = { &mp_type_type }, .name = _name, .flags = _flags, .slot_index_##f1 = 1, .slot_index_##f2 = 2, .slot_index_##f3 = 3, .slot_index_##f4 = 4, .slot_index_##f5 = 5, .slot_index_##f6 = 6, .slot_index_##f7 = 7, .slot_index_##f8 = 8, .slot_index_##f9 = 9, .slot_index_##f10 = 10, .slot_index_##f11 = 11, .slot_index_##f12 = 12, .slots = { v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, } }
|
||||
// print(f"#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_{i}(_struct_type, _typename, _name, _flags{''.join(f', f{j+1}, v{j+1}' for j in range(i))}) const _struct_type _typename = {{ .base = {{ &mp_type_type }}, .flags = _flags, .name = _name{''.join(f', .slot_index_##f{j+1} = {j+1}' for j in range(i))}{', .slots = { ' + ''.join(f'v{j+1}, ' for j in range(i)) + '}' if i else '' } }}")
|
||||
#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_0(_struct_type, _typename, _name, _flags) const _struct_type _typename = { .base = { &mp_type_type }, .flags = _flags, .name = _name }
|
||||
#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_1(_struct_type, _typename, _name, _flags, f1, v1) const _struct_type _typename = { .base = { &mp_type_type }, .flags = _flags, .name = _name, .slot_index_##f1 = 1, .slots = { v1, } }
|
||||
#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_2(_struct_type, _typename, _name, _flags, f1, v1, f2, v2) const _struct_type _typename = { .base = { &mp_type_type }, .flags = _flags, .name = _name, .slot_index_##f1 = 1, .slot_index_##f2 = 2, .slots = { v1, v2, } }
|
||||
#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_3(_struct_type, _typename, _name, _flags, f1, v1, f2, v2, f3, v3) const _struct_type _typename = { .base = { &mp_type_type }, .flags = _flags, .name = _name, .slot_index_##f1 = 1, .slot_index_##f2 = 2, .slot_index_##f3 = 3, .slots = { v1, v2, v3, } }
|
||||
#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_4(_struct_type, _typename, _name, _flags, f1, v1, f2, v2, f3, v3, f4, v4) const _struct_type _typename = { .base = { &mp_type_type }, .flags = _flags, .name = _name, .slot_index_##f1 = 1, .slot_index_##f2 = 2, .slot_index_##f3 = 3, .slot_index_##f4 = 4, .slots = { v1, v2, v3, v4, } }
|
||||
#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_5(_struct_type, _typename, _name, _flags, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5) const _struct_type _typename = { .base = { &mp_type_type }, .flags = _flags, .name = _name, .slot_index_##f1 = 1, .slot_index_##f2 = 2, .slot_index_##f3 = 3, .slot_index_##f4 = 4, .slot_index_##f5 = 5, .slots = { v1, v2, v3, v4, v5, } }
|
||||
#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_6(_struct_type, _typename, _name, _flags, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5, f6, v6) const _struct_type _typename = { .base = { &mp_type_type }, .flags = _flags, .name = _name, .slot_index_##f1 = 1, .slot_index_##f2 = 2, .slot_index_##f3 = 3, .slot_index_##f4 = 4, .slot_index_##f5 = 5, .slot_index_##f6 = 6, .slots = { v1, v2, v3, v4, v5, v6, } }
|
||||
#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_7(_struct_type, _typename, _name, _flags, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5, f6, v6, f7, v7) const _struct_type _typename = { .base = { &mp_type_type }, .flags = _flags, .name = _name, .slot_index_##f1 = 1, .slot_index_##f2 = 2, .slot_index_##f3 = 3, .slot_index_##f4 = 4, .slot_index_##f5 = 5, .slot_index_##f6 = 6, .slot_index_##f7 = 7, .slots = { v1, v2, v3, v4, v5, v6, v7, } }
|
||||
#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_8(_struct_type, _typename, _name, _flags, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5, f6, v6, f7, v7, f8, v8) const _struct_type _typename = { .base = { &mp_type_type }, .flags = _flags, .name = _name, .slot_index_##f1 = 1, .slot_index_##f2 = 2, .slot_index_##f3 = 3, .slot_index_##f4 = 4, .slot_index_##f5 = 5, .slot_index_##f6 = 6, .slot_index_##f7 = 7, .slot_index_##f8 = 8, .slots = { v1, v2, v3, v4, v5, v6, v7, v8, } }
|
||||
#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_9(_struct_type, _typename, _name, _flags, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5, f6, v6, f7, v7, f8, v8, f9, v9) const _struct_type _typename = { .base = { &mp_type_type }, .flags = _flags, .name = _name, .slot_index_##f1 = 1, .slot_index_##f2 = 2, .slot_index_##f3 = 3, .slot_index_##f4 = 4, .slot_index_##f5 = 5, .slot_index_##f6 = 6, .slot_index_##f7 = 7, .slot_index_##f8 = 8, .slot_index_##f9 = 9, .slots = { v1, v2, v3, v4, v5, v6, v7, v8, v9, } }
|
||||
#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_10(_struct_type, _typename, _name, _flags, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5, f6, v6, f7, v7, f8, v8, f9, v9, f10, v10) const _struct_type _typename = { .base = { &mp_type_type }, .flags = _flags, .name = _name, .slot_index_##f1 = 1, .slot_index_##f2 = 2, .slot_index_##f3 = 3, .slot_index_##f4 = 4, .slot_index_##f5 = 5, .slot_index_##f6 = 6, .slot_index_##f7 = 7, .slot_index_##f8 = 8, .slot_index_##f9 = 9, .slot_index_##f10 = 10, .slots = { v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, } }
|
||||
#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_11(_struct_type, _typename, _name, _flags, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5, f6, v6, f7, v7, f8, v8, f9, v9, f10, v10, f11, v11) const _struct_type _typename = { .base = { &mp_type_type }, .flags = _flags, .name = _name, .slot_index_##f1 = 1, .slot_index_##f2 = 2, .slot_index_##f3 = 3, .slot_index_##f4 = 4, .slot_index_##f5 = 5, .slot_index_##f6 = 6, .slot_index_##f7 = 7, .slot_index_##f8 = 8, .slot_index_##f9 = 9, .slot_index_##f10 = 10, .slot_index_##f11 = 11, .slots = { v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, } }
|
||||
#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_12(_struct_type, _typename, _name, _flags, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5, f6, v6, f7, v7, f8, v8, f9, v9, f10, v10, f11, v11, f12, v12) const _struct_type _typename = { .base = { &mp_type_type }, .flags = _flags, .name = _name, .slot_index_##f1 = 1, .slot_index_##f2 = 2, .slot_index_##f3 = 3, .slot_index_##f4 = 4, .slot_index_##f5 = 5, .slot_index_##f6 = 6, .slot_index_##f7 = 7, .slot_index_##f8 = 8, .slot_index_##f9 = 9, .slot_index_##f10 = 10, .slot_index_##f11 = 11, .slot_index_##f12 = 12, .slots = { v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, } }
|
||||
|
||||
// Because the mp_obj_type_t instances are in (zero-initialised) ROM, we take
|
||||
// slot_index_foo=0 to mean that the slot is unset. This also simplifies checking
|
||||
|
@ -971,6 +971,7 @@ mp_obj_t mp_obj_new_int_from_str_len(const char **str, size_t len, bool neg, uns
|
|||
mp_obj_t mp_obj_new_int_from_ll(long long val); // this must return a multi-precision integer object (or raise an overflow exception)
|
||||
mp_obj_t mp_obj_new_int_from_ull(unsigned long long val); // this must return a multi-precision integer object (or raise an overflow exception)
|
||||
mp_obj_t mp_obj_new_str(const char *data, size_t len); // will check utf-8 (raises UnicodeError)
|
||||
mp_obj_t mp_obj_new_str_0(const char *data); // will check utf-8 (raises UnicodeError)
|
||||
mp_obj_t mp_obj_new_str_via_qstr(const char *data, size_t len); // input data must be valid utf-8
|
||||
mp_obj_t mp_obj_new_str_from_vstr(vstr_t *vstr); // will check utf-8 (raises UnicodeError)
|
||||
#if MICROPY_PY_BUILTINS_STR_UNICODE && MICROPY_PY_BUILTINS_STR_UNICODE_CHECK
|
||||
|
|
|
@ -424,6 +424,13 @@ static mp_obj_t array_extend(mp_obj_t self_in, mp_obj_t arg_in) {
|
|||
if (self->free < len) {
|
||||
self->items = m_renew(byte, self->items, (self->len + self->free) * sz, (self->len + len) * sz);
|
||||
self->free = 0;
|
||||
|
||||
if (self_in == arg_in) {
|
||||
// Get arg_bufinfo again in case self->items has moved
|
||||
//
|
||||
// (Note not possible to handle case that arg_in is a memoryview into self)
|
||||
mp_get_buffer_raise(arg_in, &arg_bufinfo, MP_BUFFER_READ);
|
||||
}
|
||||
} else {
|
||||
self->free -= len;
|
||||
}
|
||||
|
@ -456,7 +463,8 @@ static mp_obj_t array_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value
|
|||
#if MICROPY_PY_ARRAY_SLICE_ASSIGN
|
||||
// Assign
|
||||
size_t src_len;
|
||||
void *src_items;
|
||||
uint8_t *src_items;
|
||||
size_t src_offs = 0;
|
||||
size_t item_sz = mp_binary_get_size('@', o->typecode & TYPECODE_MASK, NULL);
|
||||
if (mp_obj_is_obj(value) && MP_OBJ_TYPE_GET_SLOT_OR_NULL(((mp_obj_base_t *)MP_OBJ_TO_PTR(value))->type, subscr) == array_subscr) {
|
||||
// value is array, bytearray or memoryview
|
||||
|
@ -469,7 +477,7 @@ static mp_obj_t array_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value
|
|||
src_items = src_slice->items;
|
||||
#if MICROPY_PY_BUILTINS_MEMORYVIEW
|
||||
if (mp_obj_is_type(value, &mp_type_memoryview)) {
|
||||
src_items = (uint8_t *)src_items + (src_slice->memview_offset * item_sz);
|
||||
src_offs = src_slice->memview_offset * item_sz;
|
||||
}
|
||||
#endif
|
||||
} else if (mp_obj_is_type(value, &mp_type_bytes)) {
|
||||
|
@ -504,13 +512,17 @@ static mp_obj_t array_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value
|
|||
// TODO: alloc policy; at the moment we go conservative
|
||||
o->items = m_renew(byte, o->items, (o->len + o->free) * item_sz, (o->len + len_adj) * item_sz);
|
||||
o->free = len_adj;
|
||||
// m_renew may have moved o->items
|
||||
if (src_items == dest_items) {
|
||||
src_items = o->items;
|
||||
}
|
||||
dest_items = o->items;
|
||||
}
|
||||
mp_seq_replace_slice_grow_inplace(dest_items, o->len,
|
||||
slice.start, slice.stop, src_items, src_len, len_adj, item_sz);
|
||||
slice.start, slice.stop, src_items + src_offs, src_len, len_adj, item_sz);
|
||||
} else {
|
||||
mp_seq_replace_slice_no_grow(dest_items, o->len,
|
||||
slice.start, slice.stop, src_items, src_len, item_sz);
|
||||
slice.start, slice.stop, src_items + src_offs, src_len, item_sz);
|
||||
// Clear "freed" elements at the end of list
|
||||
// TODO: This is actually only needed for typecode=='O'
|
||||
mp_seq_clear(dest_items, o->len + len_adj, o->len, item_sz);
|
||||
|
|
|
@ -56,14 +56,14 @@ void mp_obj_fun_bc_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest);
|
|||
#if MICROPY_EMIT_NATIVE
|
||||
|
||||
static inline mp_obj_t mp_obj_new_fun_native(const mp_obj_t *def_args, const void *fun_data, const mp_module_context_t *mc, struct _mp_raw_code_t *const *child_table) {
|
||||
mp_obj_fun_bc_t *o = MP_OBJ_TO_PTR(mp_obj_new_fun_bc(def_args, (const byte *)fun_data, mc, child_table));
|
||||
mp_obj_fun_bc_t *o = (mp_obj_fun_bc_t *)MP_OBJ_TO_PTR(mp_obj_new_fun_bc(def_args, (const byte *)fun_data, mc, child_table));
|
||||
o->base.type = &mp_type_fun_native;
|
||||
return MP_OBJ_FROM_PTR(o);
|
||||
}
|
||||
|
||||
static inline mp_obj_t mp_obj_new_fun_viper(const void *fun_data, const mp_module_context_t *mc, struct _mp_raw_code_t *const *child_table) {
|
||||
mp_obj_fun_bc_t *o = mp_obj_malloc(mp_obj_fun_bc_t, &mp_type_fun_viper);
|
||||
o->bytecode = fun_data;
|
||||
o->bytecode = (const byte *)fun_data;
|
||||
o->context = mc;
|
||||
o->child_table = child_table;
|
||||
return MP_OBJ_FROM_PTR(o);
|
||||
|
@ -101,9 +101,9 @@ static inline void *mp_obj_fun_native_get_generator_resume(const mp_obj_fun_bc_t
|
|||
|
||||
#if MICROPY_EMIT_INLINE_ASM
|
||||
static inline mp_obj_t mp_obj_new_fun_asm(size_t n_args, const void *fun_data, mp_uint_t type_sig) {
|
||||
mp_obj_fun_asm_t *o = mp_obj_malloc(mp_obj_fun_asm_t, &mp_type_fun_asm);
|
||||
mp_obj_fun_asm_t *o = (mp_obj_fun_asm_t *)mp_obj_malloc(mp_obj_fun_asm_t, &mp_type_fun_asm);
|
||||
o->n_args = n_args;
|
||||
o->fun_data = fun_data;
|
||||
o->fun_data = (const byte *)fun_data;
|
||||
o->type_sig = type_sig;
|
||||
return MP_OBJ_FROM_PTR(o);
|
||||
}
|
||||
|
|
|
@ -2308,6 +2308,10 @@ mp_obj_t mp_obj_new_str(const char *data, size_t len) {
|
|||
}
|
||||
}
|
||||
|
||||
mp_obj_t mp_obj_new_str_0(const char *data) {
|
||||
return mp_obj_new_str(data, strlen(data));
|
||||
}
|
||||
|
||||
mp_obj_t mp_obj_str_intern(mp_obj_t str) {
|
||||
GET_STR_DATA_LEN(str, data, len);
|
||||
return mp_obj_new_str_via_qstr((const char *)data, len);
|
||||
|
|
|
@ -295,6 +295,7 @@ static bool runtime_dev_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_cont
|
|||
mp_obj_usb_device_t *usbd = MP_OBJ_TO_PTR(MP_STATE_VM(usbd));
|
||||
tusb_dir_t dir = request->bmRequestType_bit.direction;
|
||||
mp_buffer_info_t buf_info;
|
||||
bool result;
|
||||
|
||||
if (!usbd) {
|
||||
return false;
|
||||
|
@ -319,7 +320,7 @@ static bool runtime_dev_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_cont
|
|||
|
||||
// Check if callback returned any data to submit
|
||||
if (mp_get_buffer(cb_res, &buf_info, dir == TUSB_DIR_IN ? MP_BUFFER_READ : MP_BUFFER_RW)) {
|
||||
bool result = tud_control_xfer(USBD_RHPORT,
|
||||
result = tud_control_xfer(USBD_RHPORT,
|
||||
request,
|
||||
buf_info.buf,
|
||||
buf_info.len);
|
||||
|
@ -328,17 +329,21 @@ static bool runtime_dev_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_cont
|
|||
// Keep buffer object alive until the transfer completes
|
||||
usbd->xfer_data[0][dir] = cb_res;
|
||||
}
|
||||
|
||||
return result;
|
||||
} else {
|
||||
// Expect True or False to stall or continue
|
||||
result = mp_obj_is_true(cb_res);
|
||||
|
||||
if (stage == CONTROL_STAGE_ACK) {
|
||||
if (stage == CONTROL_STAGE_SETUP && result) {
|
||||
// If no additional data but callback says to continue transfer then
|
||||
// queue a status response.
|
||||
tud_control_status(rhport, request);
|
||||
} else if (stage == CONTROL_STAGE_ACK) {
|
||||
// Allow data to be GCed once it's no longer in use
|
||||
usbd->xfer_data[0][dir] = mp_const_none;
|
||||
}
|
||||
return mp_obj_is_true(cb_res);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static bool runtime_dev_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes) {
|
||||
|
|
|
@ -15,4 +15,11 @@ print(b)
|
|||
|
||||
# this inplace add tests the code when the buffer doesn't need to be increased
|
||||
b = bytearray()
|
||||
b += b''
|
||||
b += b""
|
||||
|
||||
# extend a bytearray from itself
|
||||
b = bytearray(b"abcdefgh")
|
||||
for _ in range(4):
|
||||
c = bytearray(b) # extra allocation, as above
|
||||
b.extend(b)
|
||||
print(b)
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
# add a bytearray to itself
|
||||
# This is not supported by CPython as of 3.11.18.
|
||||
|
||||
b = bytearray(b"123456789")
|
||||
for _ in range(4):
|
||||
c = bytearray(b) # extra allocation increases chance 'b' has to relocate
|
||||
b += b
|
||||
print(b)
|
|
@ -0,0 +1 @@
|
|||
bytearray(b'123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789')
|
|
@ -18,7 +18,7 @@ l = bytearray(x)
|
|||
l[1:3] = bytearray()
|
||||
print(l)
|
||||
l = bytearray(x)
|
||||
#del l[1:3]
|
||||
# del l[1:3]
|
||||
print(l)
|
||||
|
||||
l = bytearray(x)
|
||||
|
@ -28,7 +28,7 @@ l = bytearray(x)
|
|||
l[:3] = bytearray()
|
||||
print(l)
|
||||
l = bytearray(x)
|
||||
#del l[:3]
|
||||
# del l[:3]
|
||||
print(l)
|
||||
|
||||
l = bytearray(x)
|
||||
|
@ -38,7 +38,7 @@ l = bytearray(x)
|
|||
l[:-3] = bytearray()
|
||||
print(l)
|
||||
l = bytearray(x)
|
||||
#del l[:-3]
|
||||
# del l[:-3]
|
||||
print(l)
|
||||
|
||||
# slice assignment that extends the array
|
||||
|
@ -61,8 +61,14 @@ b[1:1] = b"12345"
|
|||
print(b)
|
||||
|
||||
# Growth of bytearray via slice extension
|
||||
b = bytearray(b'12345678')
|
||||
b.append(57) # expand and add a bit of unused space at end of the bytearray
|
||||
b = bytearray(b"12345678")
|
||||
b.append(57) # expand and add a bit of unused space at end of the bytearray
|
||||
for i in range(400):
|
||||
b[-1:] = b'ab' # grow slowly into the unused space
|
||||
b[-1:] = b"ab" # grow slowly into the unused space
|
||||
print(len(b), b)
|
||||
|
||||
# Growth of bytearray via slice extension from itself
|
||||
b = bytearray(b"1234567")
|
||||
for i in range(3):
|
||||
b[-1:] = b
|
||||
print(len(b), b)
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
"""
|
||||
categories: Types,memoryview
|
||||
description: memoryview can become invalid if its target is resized
|
||||
cause: CPython prevents a ``bytearray`` or ``io.bytesIO`` object from changing size while there is a ``memoryview`` object that references it. MicroPython requires the programmer to manually ensure that an object is not resized while any ``memoryview`` references it.
|
||||
|
||||
In the worst case scenario, resizing an object which is the target of a memoryview can cause the memoryview(s) to reference invalid freed memory (a use-after-free bug) and corrupt the MicroPython runtime.
|
||||
workaround: Do not change the size of any ``bytearray`` or ``io.bytesIO`` object that has a ``memoryview`` assigned to it.
|
||||
"""
|
||||
b = bytearray(b"abcdefg")
|
||||
m = memoryview(b)
|
||||
b.extend(b"hijklmnop")
|
||||
print(b, bytes(m))
|
Ładowanie…
Reference in New Issue