summaryrefslogtreecommitdiff
path: root/shared-module
diff options
context:
space:
mode:
Diffstat (limited to 'shared-module')
-rw-r--r--shared-module/msgpack/__init__.c21
-rw-r--r--shared-module/os/__init__.c2
-rw-r--r--shared-module/sdcardio/SDCard.c4
3 files changed, 18 insertions, 9 deletions
diff --git a/shared-module/msgpack/__init__.c b/shared-module/msgpack/__init__.c
index 39178d46e..103003174 100644
--- a/shared-module/msgpack/__init__.c
+++ b/shared-module/msgpack/__init__.c
@@ -255,11 +255,6 @@ STATIC void pack(mp_obj_t obj, msgpack_stream_t *s, mp_obj_t default_handler) {
mp_buffer_info_t bufinfo;
mp_get_buffer_raise(ext->data, &bufinfo, MP_BUFFER_READ);
pack_ext(s, ext->code, bufinfo.buf, bufinfo.len);
- } else if (MP_OBJ_IS_TYPE(obj, &mp_type_bytes)) {
- // bytes
- mp_buffer_info_t bufinfo;
- mp_get_buffer_raise(obj, &bufinfo, MP_BUFFER_READ);
- pack_bin(s, bufinfo.buf, bufinfo.len);
} else if (MP_OBJ_IS_TYPE(obj, &mp_type_tuple)) {
// tuple
mp_obj_tuple_t *self = MP_OBJ_TO_PTR(obj);
@@ -297,7 +292,11 @@ STATIC void pack(mp_obj_t obj, msgpack_stream_t *s, mp_obj_t default_handler) {
} else if (obj == mp_const_true) {
write1(s, 0xc3);
} else {
- if (default_handler != mp_const_none) {
+ mp_buffer_info_t bufinfo;
+ if (mp_get_buffer(obj, &bufinfo, MP_BUFFER_READ)) {
+ // bytes (bin type)
+ pack_bin(s, bufinfo.buf, bufinfo.len);
+ } else if (default_handler != mp_const_none) {
// set default_handler to mp_const_none to avoid infinite recursion
// this also precludes some valid outputs
pack(mp_call_function_1(default_handler, obj), s, mp_const_none);
@@ -332,7 +331,15 @@ STATIC mp_obj_t unpack_bytes(msgpack_stream_t *s, size_t size) {
vstr_t vstr;
vstr_init_len(&vstr, size);
byte *p = (byte*)vstr.buf;
- read(s, p, size);
+ // read in chunks: (some drivers - e.g. UART) limit the
+ // maximum number of bytes that can be read at once
+ // read(s, p, size);
+ while (size > 0) {
+ int n = size > 256 ? 256 : size;
+ read(s, p, n);
+ size -= n;
+ p += n;
+ }
return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
}
diff --git a/shared-module/os/__init__.c b/shared-module/os/__init__.c
index 39cf40fda..159b54e31 100644
--- a/shared-module/os/__init__.c
+++ b/shared-module/os/__init__.c
@@ -42,6 +42,7 @@
// Version of mp_vfs_lookup_path that takes and returns uPy string objects.
STATIC mp_vfs_mount_t *lookup_path(const char* path, mp_obj_t *path_out) {
const char *p_out;
+ *path_out = mp_const_none;
mp_vfs_mount_t *vfs = mp_vfs_lookup_path(path, &p_out);
if (vfs != MP_VFS_NONE && vfs != MP_VFS_ROOT) {
*path_out = mp_obj_new_str_of_type(&mp_type_str,
@@ -53,6 +54,7 @@ STATIC mp_vfs_mount_t *lookup_path(const char* path, mp_obj_t *path_out) {
// Strip off trailing slashes to please underlying libraries
STATIC mp_vfs_mount_t *lookup_dir_path(const char* path, mp_obj_t *path_out) {
const char *p_out;
+ *path_out = mp_const_none;
mp_vfs_mount_t *vfs = mp_vfs_lookup_path(path, &p_out);
if (vfs != MP_VFS_NONE && vfs != MP_VFS_ROOT) {
size_t len = strlen(p_out);
diff --git a/shared-module/sdcardio/SDCard.c b/shared-module/sdcardio/SDCard.c
index 9e861279d..1712f58ee 100644
--- a/shared-module/sdcardio/SDCard.c
+++ b/shared-module/sdcardio/SDCard.c
@@ -375,7 +375,7 @@ int common_hal_sdcardio_sdcard_readblocks(sdcardio_sdcard_obj_t *self, uint32_t
return r;
}
-int _write(sdcardio_sdcard_obj_t *self, uint8_t token, void *buf, size_t size) {
+STATIC int _write(sdcardio_sdcard_obj_t *self, uint8_t token, void *buf, size_t size) {
wait_for_ready(self);
uint8_t cmd[2];
@@ -420,7 +420,7 @@ int _write(sdcardio_sdcard_obj_t *self, uint8_t token, void *buf, size_t size) {
return 0;
}
-int writeblocks(sdcardio_sdcard_obj_t *self, uint32_t start_block, mp_buffer_info_t *buf) {
+STATIC int writeblocks(sdcardio_sdcard_obj_t *self, uint32_t start_block, mp_buffer_info_t *buf) {
common_hal_sdcardio_check_for_deinit(self);
uint32_t nblocks = buf->len / 512;
if (nblocks == 1) {