summaryrefslogtreecommitdiffstatshomepage
path: root/py/objcomplex.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2015-11-27 17:01:44 +0000
committerDamien George <damien.p.george@gmail.com>2015-11-29 14:25:35 +0000
commit999cedb90ff0827cdb9dfe0e4faa6ebc1739d271 (patch)
tree897eb07b82f1893cfd413b9ef7f625cd996f859d /py/objcomplex.c
parentcbf7674025814797f5c537d6d1c195efe58ccaaf (diff)
downloadmicropython-999cedb90ff0827cdb9dfe0e4faa6ebc1739d271.tar.gz
micropython-999cedb90ff0827cdb9dfe0e4faa6ebc1739d271.zip
py: Wrap all obj-ptr conversions in MP_OBJ_TO_PTR/MP_OBJ_FROM_PTR.
This allows the mp_obj_t type to be configured to something other than a pointer-sized primitive type. This patch also includes additional changes to allow the code to compile when sizeof(mp_uint_t) != sizeof(void*), such as using size_t instead of mp_uint_t, and various casts.
Diffstat (limited to 'py/objcomplex.c')
-rw-r--r--py/objcomplex.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/py/objcomplex.c b/py/objcomplex.c
index 231ccf7689..e9a15d2547 100644
--- a/py/objcomplex.c
+++ b/py/objcomplex.c
@@ -47,7 +47,7 @@ typedef struct _mp_obj_complex_t {
STATIC void complex_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind) {
(void)kind;
- mp_obj_complex_t *o = o_in;
+ mp_obj_complex_t *o = MP_OBJ_TO_PTR(o_in);
#if MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_FLOAT
char buf[16];
const int precision = 7;
@@ -114,7 +114,7 @@ STATIC mp_obj_t complex_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n
}
STATIC mp_obj_t complex_unary_op(mp_uint_t op, mp_obj_t o_in) {
- mp_obj_complex_t *o = o_in;
+ mp_obj_complex_t *o = MP_OBJ_TO_PTR(o_in);
switch (op) {
case MP_UNARY_OP_BOOL: return mp_obj_new_bool(o->real != 0 || o->imag != 0);
case MP_UNARY_OP_POSITIVE: return o_in;
@@ -124,7 +124,7 @@ STATIC mp_obj_t complex_unary_op(mp_uint_t op, mp_obj_t o_in) {
}
STATIC mp_obj_t complex_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
- mp_obj_complex_t *lhs = lhs_in;
+ mp_obj_complex_t *lhs = MP_OBJ_TO_PTR(lhs_in);
return mp_obj_complex_binary_op(op, lhs->real, lhs->imag, rhs_in);
}
@@ -133,7 +133,7 @@ STATIC void complex_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
// not load attribute
return;
}
- mp_obj_complex_t *self = self_in;
+ mp_obj_complex_t *self = MP_OBJ_TO_PTR(self_in);
if (attr == MP_QSTR_real) {
dest[0] = mp_obj_new_float(self->real);
} else if (attr == MP_QSTR_imag) {
@@ -156,12 +156,12 @@ mp_obj_t mp_obj_new_complex(mp_float_t real, mp_float_t imag) {
o->base.type = &mp_type_complex;
o->real = real;
o->imag = imag;
- return o;
+ return MP_OBJ_FROM_PTR(o);
}
void mp_obj_complex_get(mp_obj_t self_in, mp_float_t *real, mp_float_t *imag) {
assert(MP_OBJ_IS_TYPE(self_in, &mp_type_complex));
- mp_obj_complex_t *self = self_in;
+ mp_obj_complex_t *self = MP_OBJ_TO_PTR(self_in);
*real = self->real;
*imag = self->imag;
}