diff --git a/py/binary.c b/py/binary.c index 3f1d7f2867..65688272aa 100644 --- a/py/binary.c +++ b/py/binary.c @@ -26,6 +26,7 @@ #include #include +#include #include #include @@ -37,6 +38,10 @@ // Helpers to work with binary-encoded data +#ifndef alignof +#define alignof(type) offsetof(struct { char c; type t; }, t) +#endif + int mp_binary_get_size(char struct_type, char val_type, uint *palign) { int size = 0; int align = 1; @@ -68,16 +73,20 @@ int mp_binary_get_size(char struct_type, char val_type, uint *palign) { case 'b': case 'B': align = size = 1; break; case 'h': case 'H': - align = size = sizeof(short); break; + align = alignof(short); + size = sizeof(short); break; case 'i': case 'I': - align = size = sizeof(int); break; + align = alignof(int); + size = sizeof(int); break; case 'l': case 'L': - align = size = sizeof(long); break; + align = alignof(long); + size = sizeof(long); break; case 'q': case 'Q': - // TODO: This is for x86 - align = sizeof(int); size = sizeof(long long); break; + align = alignof(long long); + size = sizeof(long long); break; case 'P': case 'O': case 'S': - align = size = sizeof(void*); break; + align = alignof(void*); + size = sizeof(void*); break; } } } diff --git a/py/objstr.c b/py/objstr.c index 6ec997f4bf..9d34609882 100644 --- a/py/objstr.c +++ b/py/objstr.c @@ -472,6 +472,9 @@ STATIC mp_obj_t str_split(uint n_args, const mp_obj_t *args) { } else { // sep given + if (mp_obj_get_type(sep) != self_type) { + arg_type_mixup(); + } uint sep_len; const char *sep_str = mp_obj_str_get_data(sep, &sep_len); diff --git a/unix/modsocket.c b/unix/modsocket.c index d5b8e11c24..7eae1d8bf9 100644 --- a/unix/modsocket.c +++ b/unix/modsocket.c @@ -45,6 +45,7 @@ #include "obj.h" #include "objtuple.h" #include "objarray.h" +#include "objstr.h" #include "runtime.h" #include "stream.h" #include "builtin.h" @@ -179,11 +180,11 @@ STATIC mp_obj_t socket_recv(uint n_args, const mp_obj_t *args) { flags = MP_OBJ_SMALL_INT_VALUE(args[2]); } - char *buf = m_new(char, sz); + byte *buf = m_new(byte, sz); int out_sz = recv(self->fd, buf, sz, flags); RAISE_ERRNO(out_sz, errno); - mp_obj_t ret = MP_OBJ_NEW_QSTR(qstr_from_strn(buf, out_sz)); + mp_obj_t ret = mp_obj_new_str_of_type(&mp_type_bytes, buf, out_sz); m_del(char, buf, sz); return ret; }