Skip to content

Commit 6e6bccc

Browse files
committed
Merge branch 'master' of github.com:micropython/micropython
2 parents 101d87d + 0c54985 commit 6e6bccc

3 files changed

Lines changed: 21 additions & 8 deletions

File tree

py/binary.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
#include <stdint.h>
2828
#include <stdlib.h>
29+
#include <stddef.h>
2930
#include <string.h>
3031
#include <assert.h>
3132

@@ -37,6 +38,10 @@
3738

3839
// Helpers to work with binary-encoded data
3940

41+
#ifndef alignof
42+
#define alignof(type) offsetof(struct { char c; type t; }, t)
43+
#endif
44+
4045
int mp_binary_get_size(char struct_type, char val_type, uint *palign) {
4146
int size = 0;
4247
int align = 1;
@@ -68,16 +73,20 @@ int mp_binary_get_size(char struct_type, char val_type, uint *palign) {
6873
case 'b': case 'B':
6974
align = size = 1; break;
7075
case 'h': case 'H':
71-
align = size = sizeof(short); break;
76+
align = alignof(short);
77+
size = sizeof(short); break;
7278
case 'i': case 'I':
73-
align = size = sizeof(int); break;
79+
align = alignof(int);
80+
size = sizeof(int); break;
7481
case 'l': case 'L':
75-
align = size = sizeof(long); break;
82+
align = alignof(long);
83+
size = sizeof(long); break;
7684
case 'q': case 'Q':
77-
// TODO: This is for x86
78-
align = sizeof(int); size = sizeof(long long); break;
85+
align = alignof(long long);
86+
size = sizeof(long long); break;
7987
case 'P': case 'O': case 'S':
80-
align = size = sizeof(void*); break;
88+
align = alignof(void*);
89+
size = sizeof(void*); break;
8190
}
8291
}
8392
}

py/objstr.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,9 @@ STATIC mp_obj_t str_split(uint n_args, const mp_obj_t *args) {
472472

473473
} else {
474474
// sep given
475+
if (mp_obj_get_type(sep) != self_type) {
476+
arg_type_mixup();
477+
}
475478

476479
uint sep_len;
477480
const char *sep_str = mp_obj_str_get_data(sep, &sep_len);

unix/modsocket.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include "obj.h"
4646
#include "objtuple.h"
4747
#include "objarray.h"
48+
#include "objstr.h"
4849
#include "runtime.h"
4950
#include "stream.h"
5051
#include "builtin.h"
@@ -179,11 +180,11 @@ STATIC mp_obj_t socket_recv(uint n_args, const mp_obj_t *args) {
179180
flags = MP_OBJ_SMALL_INT_VALUE(args[2]);
180181
}
181182

182-
char *buf = m_new(char, sz);
183+
byte *buf = m_new(byte, sz);
183184
int out_sz = recv(self->fd, buf, sz, flags);
184185
RAISE_ERRNO(out_sz, errno);
185186

186-
mp_obj_t ret = MP_OBJ_NEW_QSTR(qstr_from_strn(buf, out_sz));
187+
mp_obj_t ret = mp_obj_new_str_of_type(&mp_type_bytes, buf, out_sz);
187188
m_del(char, buf, sz);
188189
return ret;
189190
}

0 commit comments

Comments
 (0)