41 #define alignof(type) offsetof(struct { char c; type t; }, t) 47 switch (struct_type) {
60 case 'P':
case 'O':
case 'S':
61 size =
sizeof(
void*);
break;
63 size =
sizeof(float);
break;
65 size =
sizeof(double);
break;
79 align = size = 1;
break;
81 align =
alignof(short);
82 size =
sizeof(short);
break;
85 size =
sizeof(int);
break;
87 align =
alignof(long);
88 size =
sizeof(long);
break;
90 align =
alignof(
long long);
91 size =
sizeof(
long long);
break;
92 case 'P':
case 'O':
case 'S':
93 align =
alignof(
void*);
94 size =
sizeof(
void*);
break;
96 align =
alignof(float);
97 size =
sizeof(float);
break;
99 align =
alignof(double);
100 size =
sizeof(double);
break;
109 if (palign !=
NULL) {
119 val = ((
signed char*)p)[index];
123 val = ((
unsigned char*)p)[index];
126 val = ((
short*)p)[index];
129 val = ((
unsigned short*)p)[index];
139 #if MICROPY_LONGINT_IMPL != MICROPY_LONGINT_IMPL_NONE 145 #if MICROPY_PY_BUILTINS_FLOAT 147 return mp_obj_new_float(((
float*)p)[index]);
149 return mp_obj_new_float(((
double*)p)[index]);
177 for (
uint i = 0; i < size; i++) {
186 #define is_signed(typecode) (typecode > 'Z') 192 if (struct_type ==
'@') {
195 #if MP_ENDIANNESS_LITTLE 205 if (val_type ==
'O') {
207 }
else if (val_type ==
'S') {
210 #if MICROPY_PY_BUILTINS_FLOAT 211 }
else if (val_type ==
'f') {
212 union {
uint32_t i;
float f; } fpu = {val};
213 return mp_obj_new_float(fpu.f);
214 }
else if (val_type ==
'd') {
215 union {
uint64_t i;
double f; } fpu = {val};
216 return mp_obj_new_float(fpu.f);
234 if (MP_ENDIANNESS_LITTLE && !big_endian) {
235 memcpy(dest, &val, val_sz);
241 if (MP_ENDIANNESS_LITTLE) {
242 src = (
const byte*)&val + val_sz;
257 if (struct_type ==
'@') {
260 if (MP_ENDIANNESS_LITTLE) {
273 #if MICROPY_PY_BUILTINS_FLOAT 275 union {
uint32_t i;
float f; } fp_sp;
276 fp_sp.f = mp_obj_get_float(val_in);
282 fp_dp.f = mp_obj_get_float(val_in);
286 int be = struct_type ==
'>';
289 val = fp_dp.i32[MP_ENDIANNESS_LITTLE ^ be];
295 #if MICROPY_LONGINT_IMPL != MICROPY_LONGINT_IMPL_NONE 304 if (BYTES_PER_WORD < 8 && size >
sizeof(val)) {
307 if (struct_type ==
'>') {
308 p += size -
sizeof(val);
319 #if MICROPY_PY_BUILTINS_FLOAT 321 ((
float*)p)[index] = mp_obj_get_float(val_in);
324 ((
double*)p)[index] = mp_obj_get_float(val_in);
332 #if MICROPY_LONGINT_IMPL != MICROPY_LONGINT_IMPL_NONE 336 size, (
uint8_t*)p + index * size);
347 ((
signed char*)p)[index] = val;
351 ((
unsigned char*)p)[index] = val;
354 ((
short*)p)[index] = val;
357 ((
unsigned short*)p)[index] = val;
360 ((
int*)p)[index] = val;
363 ((
unsigned int*)p)[index] = val;
366 ((
long*)p)[index] = val;
369 ((
unsigned long*)p)[index] = val;
371 #if MICROPY_LONGINT_IMPL != MICROPY_LONGINT_IMPL_NONE 373 ((
long long*)p)[index] = val;
376 ((
unsigned long long*)p)[index] = val;
379 #if MICROPY_PY_BUILTINS_FLOAT 381 ((
float*)p)[index] = val;
384 ((
double*)p)[index] = val;
389 ((
void**)p)[index] = (
void*)(
uintptr_t)val;
#define MP_ALIGN(ptr, alignment)
void * memset(void *b, int c, size_t len)
void mp_binary_set_val(char struct_type, char val_type, mp_obj_t val_in, byte **ptr)
#define MP_OBJ_IS_TYPE(o, t)
size_t mp_binary_get_size(char struct_type, char val_type, mp_uint_t *palign)
#define BYTEARRAY_TYPECODE
mp_int_t mp_obj_get_int(mp_const_obj_t arg)
mp_obj_t mp_obj_new_int_from_ll(long long val)
mp_obj_t mp_obj_new_int_from_ull(unsigned long long val)
long long mp_binary_get_int(mp_uint_t size, bool is_signed, bool big_endian, const byte *src)
#define MP_OBJ_NEW_SMALL_INT(small_int)
size_t strlen(const char *s)
unsigned long long uint64_t
void mp_binary_set_val_array(char typecode, void *p, mp_uint_t index, mp_obj_t val_in)
mp_obj_t mp_obj_new_int_from_uint(mp_uint_t value)
mp_obj_t mp_obj_new_str(const char *data, size_t len, bool make_qstr_if_not_already)
mp_obj_t mp_binary_get_val_array(char typecode, void *p, mp_uint_t index)
mp_obj_t mp_obj_new_int(mp_int_t value)
#define is_signed(typecode)
void mp_binary_set_val_array_from_int(char typecode, void *p, mp_uint_t index, mp_int_t val)
NORETURN void mp_raise_ValueError(const char *msg)
#define MP_ENDIANNESS_BIG
void mp_binary_set_int(mp_uint_t val_sz, bool big_endian, byte *dest, mp_uint_t val)
mp_obj_t mp_binary_get_val(char struct_type, char val_type, byte **ptr)
const mp_obj_type_t mp_type_int
void mp_obj_int_to_bytes_impl(mp_obj_t self_in, bool big_endian, size_t len, byte *buf)
void * memcpy(void *dst, const void *src, size_t n)