Skip to content

Commit 92484d8

Browse files
jonfosterdpgeorge
authored andcommitted
all: Use new mp_obj_new_str_from_cstr() function.
Use new function mp_obj_new_str_from_cstr() where appropriate. It simplifies the code, and makes it smaller too. Signed-off-by: Jon Foster <jon@jon-foster.co.uk>
1 parent 289b2dd commit 92484d8

28 files changed

+40
-40
lines changed

extmod/modlwip.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ mp_obj_t lwip_format_inet_addr(const ip_addr_t *ip, mp_uint_t port) {
373373
char ipstr[IPADDR_STRLEN_MAX];
374374
ipaddr_ntoa_r(ip, ipstr, sizeof(ipstr));
375375
mp_obj_t tuple[2] = {
376-
tuple[0] = mp_obj_new_str(ipstr, strlen(ipstr)),
376+
tuple[0] = mp_obj_new_str_from_cstr(ipstr),
377377
tuple[1] = mp_obj_new_int(port),
378378
};
379379
return mp_obj_new_tuple(2, tuple);

extmod/modnetwork.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_network_country_obj, 0, 1, network_count
127127

128128
mp_obj_t mod_network_hostname(size_t n_args, const mp_obj_t *args) {
129129
if (n_args == 0) {
130-
return mp_obj_new_str(mod_network_hostname_data, strlen(mod_network_hostname_data));
130+
return mp_obj_new_str_from_cstr(mod_network_hostname_data);
131131
} else {
132132
size_t len;
133133
const char *str = mp_obj_str_get_data(args[0], &len);

extmod/modopenamp.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ static void openamp_ns_callback(struct rpmsg_device *rdev, const char *name, uin
263263
// the Name Service (NS) announcement containing the name of the channel.
264264
virtio_dev_obj_t *virtio_device = metal_container_of(rdev, virtio_dev_obj_t, rvdev);
265265
if (virtio_device->ns_callback != mp_const_none) {
266-
mp_call_function_2(virtio_device->ns_callback, mp_obj_new_int(dest), mp_obj_new_str(name, strlen(name)));
266+
mp_call_function_2(virtio_device->ns_callback, mp_obj_new_int(dest), mp_obj_new_str_from_cstr(name));
267267
}
268268
}
269269

extmod/modopenamp_remoteproc_store.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ void *mp_openamp_remoteproc_store_alloc(void) {
7070
static int openamp_remoteproc_store_open(void *store, const char *path, const void **image_data) {
7171
metal_log(METAL_LOG_DEBUG, "store_open(): %s\n", path);
7272
mp_obj_t args[2] = {
73-
mp_obj_new_str(path, strlen(path)),
73+
mp_obj_new_str_from_cstr(path),
7474
MP_OBJ_NEW_QSTR(MP_QSTR_rb),
7575
};
7676

extmod/modtls_mbedtls.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ static mp_obj_t ssl_context_get_ciphers(mp_obj_t self_in) {
307307
mp_obj_t list = mp_obj_new_list(0, NULL);
308308
for (const int *cipher_list = mbedtls_ssl_list_ciphersuites(); *cipher_list; ++cipher_list) {
309309
const char *cipher_name = mbedtls_ssl_get_ciphersuite_name(*cipher_list);
310-
mp_obj_list_append(list, MP_OBJ_FROM_PTR(mp_obj_new_str(cipher_name, strlen(cipher_name))));
310+
mp_obj_list_append(list, MP_OBJ_FROM_PTR(mp_obj_new_str_from_cstr(cipher_name)));
311311
}
312312
return list;
313313
}
@@ -572,8 +572,8 @@ static mp_obj_t mod_ssl_cipher(mp_obj_t o_in) {
572572
mp_obj_ssl_socket_t *o = MP_OBJ_TO_PTR(o_in);
573573
const char *cipher_suite = mbedtls_ssl_get_ciphersuite(&o->ssl);
574574
const char *tls_version = mbedtls_ssl_get_version(&o->ssl);
575-
mp_obj_t tuple[2] = {mp_obj_new_str(cipher_suite, strlen(cipher_suite)),
576-
mp_obj_new_str(tls_version, strlen(tls_version))};
575+
mp_obj_t tuple[2] = {mp_obj_new_str_from_cstr(cipher_suite),
576+
mp_obj_new_str_from_cstr(tls_version)};
577577

578578
return mp_obj_new_tuple(2, tuple);
579579
}

extmod/modwebrepl.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ static void handle_op(mp_obj_webrepl_t *self) {
146146
// Handle operations requiring opened file
147147

148148
mp_obj_t open_args[2] = {
149-
mp_obj_new_str(self->hdr.fname, strlen(self->hdr.fname)),
149+
mp_obj_new_str_from_cstr(self->hdr.fname),
150150
MP_OBJ_NEW_QSTR(MP_QSTR_rb)
151151
};
152152

extmod/network_esp_hosted.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ static mp_obj_t network_esp_hosted_config(size_t n_args, const mp_obj_t *args, m
230230
case MP_QSTR_essid: {
231231
esp_hosted_netinfo_t netinfo;
232232
esp_hosted_wifi_netinfo(&netinfo);
233-
return mp_obj_new_str(netinfo.ssid, strlen(netinfo.ssid));
233+
return mp_obj_new_str_from_cstr(netinfo.ssid);
234234
}
235235
case MP_QSTR_security: {
236236
esp_hosted_netinfo_t netinfo;

extmod/network_lwip.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ mp_obj_t mod_network_ipconfig(size_t n_args, const mp_obj_t *args, mp_map_t *kwa
113113
case MP_QSTR_dns: {
114114
char addr_str[IPADDR_STRLEN_MAX];
115115
ipaddr_ntoa_r(dns_getserver(0), addr_str, sizeof(addr_str));
116-
return mp_obj_new_str(addr_str, strlen(addr_str));
116+
return mp_obj_new_str_from_cstr(addr_str);
117117
}
118118
case MP_QSTR_prefer: {
119119
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
219219
char addr_str[IPADDR_STRLEN_MAX];
220220
ipaddr_ntoa_r(netif_ip_addr6(netif, i), addr_str, sizeof(addr_str));
221221
mp_obj_t tuple[4] = {
222-
mp_obj_new_str(addr_str, strlen(addr_str)),
222+
mp_obj_new_str_from_cstr(addr_str),
223223
MP_OBJ_NEW_SMALL_INT(netif_ip6_addr_state(netif, i)),
224224
MP_OBJ_NEW_SMALL_INT(netif_ip6_addr_pref_life(netif, i)), // preferred
225225
MP_OBJ_NEW_SMALL_INT(netif_ip6_addr_valid_life(netif, i))

extmod/network_ninaw10.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ static mp_obj_t network_ninaw10_config(size_t n_args, const mp_obj_t *args, mp_m
536536
case MP_QSTR_ssid: {
537537
nina_netinfo_t netinfo;
538538
nina_netinfo(&netinfo);
539-
return mp_obj_new_str(netinfo.ssid, strlen(netinfo.ssid));
539+
return mp_obj_new_str_from_cstr(netinfo.ssid);
540540
}
541541
case MP_QSTR_security: {
542542
nina_netinfo_t netinfo;

extmod/vfs.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ mp_import_stat_t mp_vfs_import_stat(const char *path) {
139139
}
140140

141141
// delegate to vfs.stat() method
142-
mp_obj_t path_o = mp_obj_new_str(path_out, strlen(path_out));
142+
mp_obj_t path_o = mp_obj_new_str_from_cstr(path_out);
143143
mp_obj_t stat;
144144
nlr_buf_t nlr;
145145
if (nlr_push(&nlr) == 0) {

extmod/vfs_fat.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ static mp_obj_t mp_vfs_fat_ilistdir_it_iternext(mp_obj_t self_in) {
144144
// make 4-tuple with info about this entry
145145
mp_obj_tuple_t *t = MP_OBJ_TO_PTR(mp_obj_new_tuple(4, NULL));
146146
if (self->is_str) {
147-
t->items[0] = mp_obj_new_str(fn, strlen(fn));
147+
t->items[0] = mp_obj_new_str_from_cstr(fn);
148148
} else {
149149
t->items[0] = mp_obj_new_bytes((const byte *)fn, strlen(fn));
150150
}
@@ -291,7 +291,7 @@ static mp_obj_t fat_vfs_getcwd(mp_obj_t vfs_in) {
291291
if (res != FR_OK) {
292292
mp_raise_OSError(fresult_to_errno_table[res]);
293293
}
294-
return mp_obj_new_str(buf, strlen(buf));
294+
return mp_obj_new_str_from_cstr(buf);
295295
}
296296
static MP_DEFINE_CONST_FUN_OBJ_1(fat_vfs_getcwd_obj, fat_vfs_getcwd);
297297

extmod/vfs_lfsx.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ static mp_obj_t MP_VFS_LFSx(ilistdir_it_iternext)(mp_obj_t self_in) {
192192
// make 4-tuple with info about this entry
193193
mp_obj_tuple_t *t = MP_OBJ_TO_PTR(mp_obj_new_tuple(4, NULL));
194194
if (self->is_str) {
195-
t->items[0] = mp_obj_new_str(info.name, strlen(info.name));
195+
t->items[0] = mp_obj_new_str_from_cstr(info.name);
196196
} else {
197197
t->items[0] = mp_obj_new_bytes((const byte *)info.name, strlen(info.name));
198198
}

extmod/vfs_posix.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ static mp_obj_t vfs_posix_getcwd(mp_obj_t self_in) {
194194
}
195195
#endif
196196
}
197-
return mp_obj_new_str(ret, strlen(ret));
197+
return mp_obj_new_str_from_cstr(ret);
198198
}
199199
static MP_DEFINE_CONST_FUN_OBJ_1(vfs_posix_getcwd_obj, vfs_posix_getcwd);
200200

@@ -234,7 +234,7 @@ static mp_obj_t vfs_posix_ilistdir_it_iternext(mp_obj_t self_in) {
234234
mp_obj_tuple_t *t = MP_OBJ_TO_PTR(mp_obj_new_tuple(3, NULL));
235235

236236
if (self->is_str) {
237-
t->items[0] = mp_obj_new_str(fn, strlen(fn));
237+
t->items[0] = mp_obj_new_str_from_cstr(fn);
238238
} else {
239239
t->items[0] = mp_obj_new_bytes((const byte *)fn, strlen(fn));
240240
}

ports/cc3200/mods/modwlan.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -1185,7 +1185,7 @@ static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(wlan_mode_obj, 1, 2, wlan_mode);
11851185
static mp_obj_t wlan_ssid(size_t n_args, const mp_obj_t *args) {
11861186
wlan_obj_t *self = args[0];
11871187
if (n_args == 1) {
1188-
return mp_obj_new_str((const char *)self->ssid, strlen((const char *)self->ssid));
1188+
return mp_obj_new_str_from_cstr((const char *)self->ssid);
11891189
} else {
11901190
size_t len;
11911191
const char *ssid = mp_obj_str_get_data(args[1], &len);
@@ -1205,7 +1205,7 @@ static mp_obj_t wlan_auth(size_t n_args, const mp_obj_t *args) {
12051205
} else {
12061206
mp_obj_t security[2];
12071207
security[0] = mp_obj_new_int(self->auth);
1208-
security[1] = mp_obj_new_str((const char *)self->key, strlen((const char *)self->key));
1208+
security[1] = mp_obj_new_str_from_cstr((const char *)self->key);
12091209
return mp_obj_new_tuple(2, security);
12101210
}
12111211
} else {
@@ -1309,7 +1309,7 @@ static MP_DEFINE_CONST_FUN_OBJ_KW(wlan_irq_obj, 1, wlan_irq);
13091309
// mp_obj_t connections = mp_obj_new_list(0, NULL);
13101310
//
13111311
// if (wlan_is_connected()) {
1312-
// device[0] = mp_obj_new_str((const char *)wlan_obj.ssid_o, strlen((const char *)wlan_obj.ssid_o));
1312+
// device[0] = mp_obj_new_str_from_cstr((const char *)wlan_obj.ssid_o);
13131313
// device[1] = mp_obj_new_bytes((const byte *)wlan_obj.bssid, SL_BSSID_LENGTH);
13141314
// // add the device to the list
13151315
// mp_obj_list_append(connections, mp_obj_new_tuple(MP_ARRAY_SIZE(device), device));

ports/esp32/esp32_partition.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ static mp_obj_t esp32_partition_info(mp_obj_t self_in) {
156156
MP_OBJ_NEW_SMALL_INT(self->part->subtype),
157157
mp_obj_new_int_from_uint(self->part->address),
158158
mp_obj_new_int_from_uint(self->part->size),
159-
mp_obj_new_str(&self->part->label[0], strlen(&self->part->label[0])),
159+
mp_obj_new_str_from_cstr(&self->part->label[0]),
160160
mp_obj_new_bool(self->part->encrypted),
161161
};
162162
return mp_obj_new_tuple(6, tuple);

ports/esp32/modsocket.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -951,7 +951,7 @@ static mp_obj_t esp_socket_getaddrinfo(size_t n_args, const mp_obj_t *args) {
951951
mp_obj_new_int(resi->ai_family),
952952
mp_obj_new_int(resi->ai_socktype),
953953
mp_obj_new_int(resi->ai_protocol),
954-
mp_obj_new_str(resi->ai_canonname, strlen(resi->ai_canonname)),
954+
mp_obj_new_str_from_cstr(resi->ai_canonname),
955955
mp_const_none
956956
};
957957

@@ -962,7 +962,7 @@ static mp_obj_t esp_socket_getaddrinfo(size_t n_args, const mp_obj_t *args) {
962962
char buf[16];
963963
ip4addr_ntoa_r(&ip4_addr, buf, sizeof(buf));
964964
mp_obj_t inaddr_objs[2] = {
965-
mp_obj_new_str(buf, strlen(buf)),
965+
mp_obj_new_str_from_cstr(buf),
966966
mp_obj_new_int(ntohs(addr->sin_port))
967967
};
968968
addrinfo_objs[4] = mp_obj_new_tuple(2, inaddr_objs);

ports/esp32/network_common.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ mp_obj_t esp_ifname(esp_netif_t *netif) {
328328
char ifname[NETIF_NAMESIZE + 1] = {0};
329329
mp_obj_t ret = mp_const_none;
330330
if (esp_netif_get_netif_impl_name(netif, ifname) == ESP_OK && ifname[0] != 0) {
331-
ret = mp_obj_new_str((char *)ifname, strlen(ifname));
331+
ret = mp_obj_new_str_from_cstr((char *)ifname);
332332
}
333333
return ret;
334334
}

ports/esp32/network_ppp.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ static mp_obj_t ppp_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs
344344
char ifname[NETIF_NAMESIZE + 1] = {0};
345345
netif_index_to_name(netif_get_index(pppif), ifname);
346346
if (ifname[0] != 0) {
347-
val = mp_obj_new_str((char *)ifname, strlen(ifname));
347+
val = mp_obj_new_str_from_cstr((char *)ifname);
348348
}
349349
}
350350
break;

ports/esp32/network_wlan.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ static mp_obj_t network_wlan_config(size_t n_args, const mp_obj_t *args, mp_map_
640640
case MP_QSTR_essid:
641641
switch (self->if_id) {
642642
case ESP_IF_WIFI_STA:
643-
val = mp_obj_new_str((char *)cfg.sta.ssid, strlen((char *)cfg.sta.ssid));
643+
val = mp_obj_new_str_from_cstr((char *)cfg.sta.ssid);
644644
break;
645645
case ESP_IF_WIFI_AP:
646646
val = mp_obj_new_str((char *)cfg.ap.ssid, cfg.ap.ssid_len);

ports/esp8266/network_wlan.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ static mp_obj_t esp_config(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs
626626
case MP_QSTR_ssid:
627627
case MP_QSTR_essid:
628628
if (self->if_id == STATION_IF) {
629-
val = mp_obj_new_str((char *)cfg.sta.ssid, strlen((char *)cfg.sta.ssid));
629+
val = mp_obj_new_str_from_cstr((char *)cfg.sta.ssid);
630630
} else {
631631
val = mp_obj_new_str((char *)cfg.ap.ssid, cfg.ap.ssid_len);
632632
}

ports/unix/coverage.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ static mp_obj_t extra_coverage(void) {
388388
mp_printf(&mp_plat_print, "# str\n");
389389

390390
// intern string
391-
mp_printf(&mp_plat_print, "%d\n", mp_obj_is_qstr(mp_obj_str_intern(mp_obj_new_str("intern me", 9))));
391+
mp_printf(&mp_plat_print, "%d\n", mp_obj_is_qstr(mp_obj_str_intern(mp_obj_new_str_from_cstr("intern me"))));
392392
}
393393

394394
// bytearray
@@ -471,12 +471,12 @@ static mp_obj_t extra_coverage(void) {
471471
// call mp_call_function_1_protected
472472
mp_call_function_1_protected(MP_OBJ_FROM_PTR(&mp_builtin_abs_obj), MP_OBJ_NEW_SMALL_INT(1));
473473
// call mp_call_function_1_protected with invalid args
474-
mp_call_function_1_protected(MP_OBJ_FROM_PTR(&mp_builtin_abs_obj), mp_obj_new_str("abc", 3));
474+
mp_call_function_1_protected(MP_OBJ_FROM_PTR(&mp_builtin_abs_obj), mp_obj_new_str_from_cstr("abc"));
475475

476476
// call mp_call_function_2_protected
477477
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));
478478
// call mp_call_function_2_protected with invalid args
479-
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));
479+
mp_call_function_2_protected(MP_OBJ_FROM_PTR(&mp_builtin_divmod_obj), mp_obj_new_str_from_cstr("abc"), mp_obj_new_str_from_cstr("abc"));
480480

481481
// mp_obj_int_get_checked with mp_obj_int_t that has a value that is a small integer
482482
mp_printf(&mp_plat_print, "%d\n", mp_obj_int_get_checked(mp_obj_int_new_mpz()));
@@ -733,7 +733,7 @@ static mp_obj_t extra_coverage(void) {
733733
// mp_obj_is_integer accepts ints and booleans
734734
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)));
735735
mp_printf(&mp_plat_print, "%d %d\n", mp_obj_is_integer(mp_const_true), mp_obj_is_integer(mp_const_false));
736-
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));
736+
mp_printf(&mp_plat_print, "%d %d\n", mp_obj_is_integer(mp_obj_new_str_from_cstr("1")), mp_obj_is_integer(mp_const_none));
737737

738738
// mp_obj_is_int accepts small int and object ints
739739
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)));

ports/unix/main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ MP_NOINLINE int main_(int argc, char **argv) {
639639
return invalid_args();
640640
}
641641
mp_obj_t import_args[4];
642-
import_args[0] = mp_obj_new_str(argv[a + 1], strlen(argv[a + 1]));
642+
import_args[0] = mp_obj_new_str_from_cstr(argv[a + 1]);
643643
import_args[1] = import_args[2] = mp_const_none;
644644
// Ask __import__ to handle imported module specially - set its __name__
645645
// to __main__, and also return this leaf module, not top-level package

ports/unix/modffi.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ static mp_obj_t return_ffi_value(ffi_union_t *val, char type) {
174174
if (!s) {
175175
return mp_const_none;
176176
}
177-
return mp_obj_new_str(s, strlen(s));
177+
return mp_obj_new_str_from_cstr(s);
178178
}
179179
case 'v':
180180
return mp_const_none;

ports/unix/modjni.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ static mp_obj_t new_jobject(jobject jo) {
337337
return mp_const_none;
338338
} else if (JJ(IsInstanceOf, jo, String_class)) {
339339
const char *s = JJ(GetStringUTFChars, jo, NULL);
340-
mp_obj_t ret = mp_obj_new_str(s, strlen(s));
340+
mp_obj_t ret = mp_obj_new_str_from_cstr(s);
341341
JJ(ReleaseStringUTFChars, jo, s);
342342
return ret;
343343
} else if (JJ(IsInstanceOf, jo, Class_class)) {

ports/unix/modos.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ static mp_obj_t mp_os_getenv(size_t n_args, const mp_obj_t *args) {
4040
}
4141
return mp_const_none;
4242
}
43-
return mp_obj_new_str(s, strlen(s));
43+
return mp_obj_new_str_from_cstr(s);
4444
}
4545
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_os_getenv_obj, 1, 2, mp_os_getenv);
4646

ports/zephyr/main.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ static void vfs_init(void) {
103103
int ret = 0;
104104

105105
#ifdef CONFIG_DISK_DRIVER_SDMMC
106-
mp_obj_t args[] = { mp_obj_new_str(CONFIG_SDMMC_VOLUME_NAME, strlen(CONFIG_SDMMC_VOLUME_NAME)) };
106+
mp_obj_t args[] = { mp_obj_new_str_from_cstr(CONFIG_SDMMC_VOLUME_NAME) };
107107
bdev = MP_OBJ_TYPE_GET_SLOT(&zephyr_disk_access_type, make_new)(&zephyr_disk_access_type, ARRAY_SIZE(args), 0, args);
108108
mount_point_str = "/sd";
109109
#elif defined(CONFIG_FLASH_MAP) && FLASH_AREA_LABEL_EXISTS(storage)
@@ -113,7 +113,7 @@ static void vfs_init(void) {
113113
#endif
114114

115115
if ((bdev != NULL)) {
116-
mount_point = mp_obj_new_str(mount_point_str, strlen(mount_point_str));
116+
mount_point = mp_obj_new_str_from_cstr(mount_point_str);
117117
ret = mp_vfs_mount_and_chdir_protected(bdev, mount_point);
118118
// TODO: if this failed, make a new file system and try to mount again
119119
}

ports/zephyr/modsocket.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ static mp_obj_t format_inet_addr(struct sockaddr *addr, mp_obj_t port) {
9292
net_addr_ntop(addr->sa_family, &sockaddr_in6->sin6_addr, buf, sizeof(buf));
9393
mp_obj_tuple_t *tuple = mp_obj_new_tuple(addr->sa_family == AF_INET ? 2 : 4, NULL);
9494

95-
tuple->items[0] = mp_obj_new_str(buf, strlen(buf));
95+
tuple->items[0] = mp_obj_new_str_from_cstr(buf);
9696
// We employ the fact that port offset is the same for IPv4 & IPv6
9797
// not filled in
9898
// tuple->items[1] = mp_obj_new_int(ntohs(((struct sockaddr_in*)addr)->sin_port));

py/binary.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ mp_obj_t mp_binary_get_val(char struct_type, char val_type, byte *p_base, byte *
338338
return (mp_obj_t)(mp_uint_t)val;
339339
} else if (val_type == 'S') {
340340
const char *s_val = (const char *)(uintptr_t)(mp_uint_t)val;
341-
return mp_obj_new_str(s_val, strlen(s_val));
341+
return mp_obj_new_str_from_cstr(s_val);
342342
#if MICROPY_PY_BUILTINS_FLOAT
343343
} else if (val_type == 'e') {
344344
return mp_obj_new_float_from_f(mp_decode_half_float(val));

0 commit comments

Comments
 (0)