aboutsummaryrefslogtreecommitdiff
path: root/extmod/moductypes.c
diff options
context:
space:
mode:
authorDamien George2020-02-27 15:36:53 +1100
committerDamien George2020-02-28 10:33:03 +1100
commit69661f3343bedf86e514337cff63d96cc42f8859 (patch)
treeaf5dfb380ffdb75dda84828f63cf9d840d992f0f /extmod/moductypes.c
parent3f39d18c2b884d32f0443e2e8114ff9d7a14d718 (diff)
all: Reformat C and Python source code with tools/codeformat.py.
This is run with uncrustify 0.70.1, and black 19.10b0.
Diffstat (limited to 'extmod/moductypes.c')
-rw-r--r--extmod/moductypes.c112
1 files changed, 63 insertions, 49 deletions
diff --git a/extmod/moductypes.c b/extmod/moductypes.c
index 62bbcbac2..5446f7b8f 100644
--- a/extmod/moductypes.c
+++ b/extmod/moductypes.c
@@ -124,7 +124,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, n_kw, 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) {
@@ -138,18 +138,22 @@ STATIC void uctypes_struct_print(const mp_print_t *print, mp_obj_t self_in, mp_p
mp_obj_uctypes_struct_t *self = MP_OBJ_TO_PTR(self_in);
const char *typen = "unk";
if (mp_obj_is_type(self->desc, &mp_type_dict)
- #if MICROPY_PY_COLLECTIONS_ORDEREDDICT
+ #if MICROPY_PY_COLLECTIONS_ORDEREDDICT
|| mp_obj_is_type(self->desc, &mp_type_ordereddict)
- #endif
- ) {
+ #endif
+ ) {
typen = "STRUCT";
} else if (mp_obj_is_type(self->desc, &mp_type_tuple)) {
mp_obj_tuple_t *t = MP_OBJ_TO_PTR(self->desc);
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";
@@ -180,10 +184,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);
@@ -211,12 +215,12 @@ 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 MICROPY_PY_COLLECTIONS_ORDEREDDICT
+ #if MICROPY_PY_COLLECTIONS_ORDEREDDICT
&& !mp_obj_is_type(desc_in, &mp_type_ordereddict)
- #endif
- ) {
+ #endif
+ ) {
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
@@ -311,11 +315,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;
@@ -324,11 +328,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);
}
@@ -336,26 +343,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(((float*)p)[index]);
+ return mp_obj_new_float(((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);
@@ -368,9 +375,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;
}
@@ -378,21 +385,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);
@@ -407,11 +420,11 @@ STATIC mp_obj_t uctypes_struct_attr_op(mp_obj_t self_in, qstr attr, mp_obj_t set
mp_obj_uctypes_struct_t *self = MP_OBJ_TO_PTR(self_in);
if (!mp_obj_is_type(self->desc, &mp_type_dict)
- #if MICROPY_PY_COLLECTIONS_ORDEREDDICT
+ #if MICROPY_PY_COLLECTIONS_ORDEREDDICT
&& !mp_obj_is_type(self->desc, &mp_type_ordereddict)
- #endif
- ) {
- mp_raise_TypeError("struct: no fields");
+ #endif
+ ) {
+ mp_raise_TypeError("struct: no fields");
}
mp_obj_t deref = mp_obj_dict_get(self->desc, MP_OBJ_NEW_QSTR(attr));
@@ -593,7 +606,7 @@ STATIC mp_obj_t uctypes_struct_subscr(mp_obj_t self_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);
@@ -623,13 +636,14 @@ STATIC mp_obj_t uctypes_struct_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
mp_int_t offset = MP_OBJ_SMALL_INT_VALUE(t->items[0]);
uint agg_type = GET_TYPE(offset, AGG_TYPE_BITS);
if (agg_type == PTR) {
- byte *p = *(void**)self->addr;
+ byte *p = *(void **)self->addr;
return mp_obj_new_int((mp_int_t)(uintptr_t)p);
}
}
- /* fallthru */
+ /* fallthru */
- default: return MP_OBJ_NULL; // op not supported
+ default:
+ return MP_OBJ_NULL; // op not supported
}
}
@@ -660,7 +674,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);
@@ -669,7 +683,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);
@@ -772,7 +786,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