Merge branch 'master' of github.com:micropython/micropython
This commit is contained in:
commit
6e6bcccdc1
21
py/binary.c
21
py/binary.c
@ -26,6 +26,7 @@
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user