summaryrefslogtreecommitdiff
path: root/extmod/moductypes.c
diff options
context:
space:
mode:
Diffstat (limited to 'extmod/moductypes.c')
-rw-r--r--extmod/moductypes.c93
1 files changed, 53 insertions, 40 deletions
diff --git a/extmod/moductypes.c b/extmod/moductypes.c
index dc8ac4c72..8499d1c29 100644
--- a/extmod/moductypes.c
+++ b/extmod/moductypes.c
@@ -105,7 +105,7 @@ STATIC mp_obj_t uctypes_struct_make_new(const mp_obj_type_t *type, size_t n_args
mp_arg_check_num(n_args, kw_args, 2, 3, false);
mp_obj_uctypes_struct_t *o = m_new_obj(mp_obj_uctypes_struct_t);
o->base.type = type;
- o->addr = (void*)(uintptr_t)mp_obj_int_get_truncated(args[0]);
+ o->addr = (void *)(uintptr_t)mp_obj_int_get_truncated(args[0]);
o->desc = args[1];
o->flags = LAYOUT_NATIVE;
if (n_args == 3) {
@@ -125,8 +125,12 @@ STATIC void uctypes_struct_print(const mp_print_t *print, mp_obj_t self_in, mp_p
mp_int_t offset = MP_OBJ_SMALL_INT_VALUE(t->items[0]);
uint agg_type = GET_TYPE(offset, AGG_TYPE_BITS);
switch (agg_type) {
- case PTR: typen = "PTR"; break;
- case ARRAY: typen = "ARRAY"; break;
+ case PTR:
+ typen = "PTR";
+ break;
+ case ARRAY:
+ typen = "ARRAY";
+ break;
}
} else {
typen = "ERROR";
@@ -157,10 +161,10 @@ STATIC mp_uint_t uctypes_struct_agg_size(mp_obj_tuple_t *t, int layout_type, mp_
case STRUCT:
return uctypes_struct_size(t->items[1], layout_type, max_field_size);
case PTR:
- if (sizeof(void*) > *max_field_size) {
- *max_field_size = sizeof(void*);
+ if (sizeof(void *) > *max_field_size) {
+ *max_field_size = sizeof(void *);
}
- return sizeof(void*);
+ return sizeof(void *);
case ARRAY: {
mp_int_t arr_sz = MP_OBJ_SMALL_INT_VALUE(t->items[1]);
uint val_type = GET_TYPE(arr_sz, VAL_TYPE_BITS);
@@ -189,7 +193,7 @@ STATIC mp_uint_t uctypes_struct_agg_size(mp_obj_tuple_t *t, int layout_type, mp_
STATIC mp_uint_t uctypes_struct_size(mp_obj_t desc_in, int layout_type, mp_uint_t *max_field_size) {
if (!MP_OBJ_IS_TYPE(desc_in, &mp_type_dict)) {
if (MP_OBJ_IS_TYPE(desc_in, &mp_type_tuple)) {
- return uctypes_struct_agg_size((mp_obj_tuple_t*)MP_OBJ_TO_PTR(desc_in), layout_type, max_field_size);
+ return uctypes_struct_agg_size((mp_obj_tuple_t *)MP_OBJ_TO_PTR(desc_in), layout_type, max_field_size);
} else if (MP_OBJ_IS_SMALL_INT(desc_in)) {
// We allow sizeof on both type definitions and structures/structure fields,
// but scalar structure field is lowered into native Python int, so all
@@ -276,11 +280,11 @@ static inline void set_unaligned(uint val_type, byte *p, int big_endian, mp_obj_
static inline mp_uint_t get_aligned_basic(uint val_type, void *p) {
switch (val_type) {
case UINT8:
- return *(uint8_t*)p;
+ return *(uint8_t *)p;
case UINT16:
- return *(uint16_t*)p;
+ return *(uint16_t *)p;
case UINT32:
- return *(uint32_t*)p;
+ return *(uint32_t *)p;
}
assert(0);
return 0;
@@ -289,11 +293,14 @@ static inline mp_uint_t get_aligned_basic(uint val_type, void *p) {
static inline void set_aligned_basic(uint val_type, void *p, mp_uint_t v) {
switch (val_type) {
case UINT8:
- *(uint8_t*)p = (uint8_t)v; return;
+ *(uint8_t *)p = (uint8_t)v;
+ return;
case UINT16:
- *(uint16_t*)p = (uint16_t)v; return;
+ *(uint16_t *)p = (uint16_t)v;
+ return;
case UINT32:
- *(uint32_t*)p = (uint32_t)v; return;
+ *(uint32_t *)p = (uint32_t)v;
+ return;
}
assert(0);
}
@@ -301,26 +308,26 @@ static inline void set_aligned_basic(uint val_type, void *p, mp_uint_t v) {
STATIC mp_obj_t get_aligned(uint val_type, void *p, mp_int_t index) {
switch (val_type) {
case UINT8:
- return MP_OBJ_NEW_SMALL_INT(((uint8_t*)p)[index]);
+ return MP_OBJ_NEW_SMALL_INT(((uint8_t *)p)[index]);
case INT8:
- return MP_OBJ_NEW_SMALL_INT(((int8_t*)p)[index]);
+ return MP_OBJ_NEW_SMALL_INT(((int8_t *)p)[index]);
case UINT16:
- return MP_OBJ_NEW_SMALL_INT(((uint16_t*)p)[index]);
+ return MP_OBJ_NEW_SMALL_INT(((uint16_t *)p)[index]);
case INT16:
- return MP_OBJ_NEW_SMALL_INT(((int16_t*)p)[index]);
+ return MP_OBJ_NEW_SMALL_INT(((int16_t *)p)[index]);
case UINT32:
- return mp_obj_new_int_from_uint(((uint32_t*)p)[index]);
+ return mp_obj_new_int_from_uint(((uint32_t *)p)[index]);
case INT32:
- return mp_obj_new_int(((int32_t*)p)[index]);
+ return mp_obj_new_int(((int32_t *)p)[index]);
case UINT64:
- return mp_obj_new_int_from_ull(((uint64_t*)p)[index]);
+ return mp_obj_new_int_from_ull(((uint64_t *)p)[index]);
case INT64:
- return mp_obj_new_int_from_ll(((int64_t*)p)[index]);
+ return mp_obj_new_int_from_ll(((int64_t *)p)[index]);
#if MICROPY_PY_BUILTINS_FLOAT
case FLOAT32:
- return mp_obj_new_float((mp_float_t)((float*)p)[index]);
+ return mp_obj_new_float((mp_float_t)((float *)p)[index]);
case FLOAT64:
- return mp_obj_new_float(((double*)p)[index]);
+ return mp_obj_new_float(((double *)p)[index]);
#endif
default:
assert(0);
@@ -333,9 +340,9 @@ STATIC void set_aligned(uint val_type, void *p, mp_int_t index, mp_obj_t val) {
if (val_type == FLOAT32 || val_type == FLOAT64) {
mp_float_t v = mp_obj_get_float(val);
if (val_type == FLOAT32) {
- ((float*)p)[index] = v;
+ ((float *)p)[index] = v;
} else {
- ((double*)p)[index] = v;
+ ((double *)p)[index] = v;
}
return;
}
@@ -343,21 +350,27 @@ STATIC void set_aligned(uint val_type, void *p, mp_int_t index, mp_obj_t val) {
mp_int_t v = mp_obj_get_int_truncated(val);
switch (val_type) {
case UINT8:
- ((uint8_t*)p)[index] = (uint8_t)v; return;
+ ((uint8_t *)p)[index] = (uint8_t)v;
+ return;
case INT8:
- ((int8_t*)p)[index] = (int8_t)v; return;
+ ((int8_t *)p)[index] = (int8_t)v;
+ return;
case UINT16:
- ((uint16_t*)p)[index] = (uint16_t)v; return;
+ ((uint16_t *)p)[index] = (uint16_t)v;
+ return;
case INT16:
- ((int16_t*)p)[index] = (int16_t)v; return;
+ ((int16_t *)p)[index] = (int16_t)v;
+ return;
case UINT32:
- ((uint32_t*)p)[index] = (uint32_t)v; return;
+ ((uint32_t *)p)[index] = (uint32_t)v;
+ return;
case INT32:
- ((int32_t*)p)[index] = (int32_t)v; return;
+ ((int32_t *)p)[index] = (int32_t)v;
+ return;
case INT64:
case UINT64:
if (sizeof(mp_int_t) == 8) {
- ((uint64_t*)p)[index] = (uint64_t)v;
+ ((uint64_t *)p)[index] = (uint64_t)v;
} else {
// TODO: Doesn't offer atomic store semantics, but should at least try
set_unaligned(val_type, p, MP_ENDIANNESS_BIG, val);
@@ -373,7 +386,7 @@ STATIC mp_obj_t uctypes_struct_attr_op(mp_obj_t self_in, qstr attr, mp_obj_t set
// TODO: Support at least OrderedDict in addition
if (!MP_OBJ_IS_TYPE(self->desc, &mp_type_dict)) {
- mp_raise_TypeError(translate("struct: no fields"));
+ mp_raise_TypeError(translate("struct: no fields"));
}
mp_obj_t deref = mp_obj_dict_get(self->desc, MP_OBJ_NEW_QSTR(attr));
@@ -381,7 +394,7 @@ STATIC mp_obj_t uctypes_struct_attr_op(mp_obj_t self_in, qstr attr, mp_obj_t set
mp_int_t offset = MP_OBJ_SMALL_INT_VALUE(deref);
mp_uint_t val_type = GET_TYPE(offset, VAL_TYPE_BITS);
offset &= VALUE_MASK(VAL_TYPE_BITS);
-//printf("scalar type=%d offset=%x\n", val_type, offset);
+// printf("scalar type=%d offset=%x\n", val_type, offset);
if (val_type <= INT64 || val_type == FLOAT32 || val_type == FLOAT64) {
// printf("size=%d\n", GET_SCALAR_SIZE(val_type));
@@ -451,7 +464,7 @@ STATIC mp_obj_t uctypes_struct_attr_op(mp_obj_t self_in, qstr attr, mp_obj_t set
mp_int_t offset = MP_OBJ_SMALL_INT_VALUE(sub->items[0]);
mp_uint_t agg_type = GET_TYPE(offset, AGG_TYPE_BITS);
offset &= VALUE_MASK(AGG_TYPE_BITS);
-//printf("agg type=%d offset=%x\n", agg_type, offset);
+// printf("agg type=%d offset=%x\n", agg_type, offset);
switch (agg_type) {
case STRUCT: {
@@ -475,7 +488,7 @@ STATIC mp_obj_t uctypes_struct_attr_op(mp_obj_t self_in, qstr attr, mp_obj_t set
o->desc = MP_OBJ_FROM_PTR(sub);
o->addr = self->addr + offset;
o->flags = self->flags;
-//printf("PTR/ARR base addr=%p\n", o->addr);
+// printf("PTR/ARR base addr=%p\n", o->addr);
return MP_OBJ_FROM_PTR(o);
}
}
@@ -555,7 +568,7 @@ STATIC mp_obj_t uctypes_struct_subscr(mp_obj_t base_in, mp_obj_t index_in, mp_ob
}
} else if (agg_type == PTR) {
- byte *p = *(void**)self->addr;
+ byte *p = *(void **)self->addr;
if (MP_OBJ_IS_SMALL_INT(t->items[1])) {
uint val_type = GET_TYPE(MP_OBJ_SMALL_INT_VALUE(t->items[1]), VAL_TYPE_BITS);
return get_aligned(val_type, p, index);
@@ -603,7 +616,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(uctypes_struct_addressof_obj, uctypes_struct_addressof
/// captured by reference (and thus memory pointed by bytearray may change
/// or become invalid at later time). Use bytes_at() to capture by value.
STATIC mp_obj_t uctypes_struct_bytearray_at(mp_obj_t ptr, mp_obj_t size) {
- return mp_obj_new_bytearray_by_ref(mp_obj_int_get_truncated(size), (void*)(uintptr_t)mp_obj_int_get_truncated(ptr));
+ return mp_obj_new_bytearray_by_ref(mp_obj_int_get_truncated(size), (void *)(uintptr_t)mp_obj_int_get_truncated(ptr));
}
MP_DEFINE_CONST_FUN_OBJ_2(uctypes_struct_bytearray_at_obj, uctypes_struct_bytearray_at);
@@ -612,7 +625,7 @@ MP_DEFINE_CONST_FUN_OBJ_2(uctypes_struct_bytearray_at_obj, uctypes_struct_bytear
/// captured by value, i.e. copied. Use bytearray_at() to capture by reference
/// ("zero copy").
STATIC mp_obj_t uctypes_struct_bytes_at(mp_obj_t ptr, mp_obj_t size) {
- return mp_obj_new_bytes((void*)(uintptr_t)mp_obj_int_get_truncated(ptr), mp_obj_int_get_truncated(size));
+ return mp_obj_new_bytes((void *)(uintptr_t)mp_obj_int_get_truncated(ptr), mp_obj_int_get_truncated(size));
}
MP_DEFINE_CONST_FUN_OBJ_2(uctypes_struct_bytes_at_obj, uctypes_struct_bytes_at);
@@ -690,7 +703,7 @@ STATIC MP_DEFINE_CONST_DICT(mp_module_uctypes_globals, mp_module_uctypes_globals
const mp_obj_module_t mp_module_uctypes = {
.base = { &mp_type_module },
- .globals = (mp_obj_dict_t*)&mp_module_uctypes_globals,
+ .globals = (mp_obj_dict_t *)&mp_module_uctypes_globals,
};
#endif