Skip to content

Commit bb4c6f3

Browse files
committed
py: Make MP_OBJ_NEW_SMALL_INT cast arg to mp_int_t itself.
Addresses issue adafruit#724.
1 parent fa1ecda commit bb4c6f3

17 files changed

Lines changed: 44 additions & 44 deletions

File tree

extmod/moductypes.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -296,13 +296,13 @@ static inline void set_aligned_basic(uint val_type, void *p, mp_uint_t v) {
296296
STATIC mp_obj_t get_aligned(uint val_type, void *p, mp_int_t index) {
297297
switch (val_type) {
298298
case UINT8:
299-
return MP_OBJ_NEW_SMALL_INT((mp_int_t)((uint8_t*)p)[index]);
299+
return MP_OBJ_NEW_SMALL_INT(((uint8_t*)p)[index]);
300300
case INT8:
301-
return MP_OBJ_NEW_SMALL_INT((mp_int_t)((int8_t*)p)[index]);
301+
return MP_OBJ_NEW_SMALL_INT(((int8_t*)p)[index]);
302302
case UINT16:
303-
return MP_OBJ_NEW_SMALL_INT((mp_int_t)((uint16_t*)p)[index]);
303+
return MP_OBJ_NEW_SMALL_INT(((uint16_t*)p)[index]);
304304
case INT16:
305-
return MP_OBJ_NEW_SMALL_INT((mp_int_t)((int16_t*)p)[index]);
305+
return MP_OBJ_NEW_SMALL_INT(((int16_t*)p)[index]);
306306
case UINT32:
307307
return mp_obj_new_int_from_uint(((uint32_t*)p)[index]);
308308
case INT32:

py/modgc.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ extern uint gc_collected;
4242
STATIC mp_obj_t py_gc_collect(void) {
4343
gc_collect();
4444
#if MICROPY_PY_GC_COLLECT_RETVAL
45-
return MP_OBJ_NEW_SMALL_INT((mp_uint_t)gc_collected);
45+
return MP_OBJ_NEW_SMALL_INT(gc_collected);
4646
#else
4747
return mp_const_none;
4848
#endif
@@ -64,14 +64,14 @@ MP_DEFINE_CONST_FUN_OBJ_0(gc_enable_obj, gc_enable);
6464
STATIC mp_obj_t gc_mem_free(void) {
6565
gc_info_t info;
6666
gc_info(&info);
67-
return MP_OBJ_NEW_SMALL_INT((mp_uint_t)info.free);
67+
return MP_OBJ_NEW_SMALL_INT(info.free);
6868
}
6969
MP_DEFINE_CONST_FUN_OBJ_0(gc_mem_free_obj, gc_mem_free);
7070

7171
STATIC mp_obj_t gc_mem_alloc(void) {
7272
gc_info_t info;
7373
gc_info(&info);
74-
return MP_OBJ_NEW_SMALL_INT((mp_uint_t)info.used);
74+
return MP_OBJ_NEW_SMALL_INT(info.used);
7575
}
7676
MP_DEFINE_CONST_FUN_OBJ_0(gc_mem_alloc_obj, gc_mem_alloc);
7777

py/modmicropython.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@
3535

3636
#if MICROPY_MEM_STATS
3737
STATIC mp_obj_t mp_micropython_mem_total() {
38-
return MP_OBJ_NEW_SMALL_INT((mp_int_t)m_get_total_bytes_allocated());
38+
return MP_OBJ_NEW_SMALL_INT(m_get_total_bytes_allocated());
3939
}
4040

4141
STATIC mp_obj_t mp_micropython_mem_current() {
42-
return MP_OBJ_NEW_SMALL_INT((mp_int_t)m_get_current_bytes_allocated());
42+
return MP_OBJ_NEW_SMALL_INT(m_get_current_bytes_allocated());
4343
}
4444

4545
STATIC mp_obj_t mp_micropython_mem_peak() {
46-
return MP_OBJ_NEW_SMALL_INT((mp_int_t)m_get_peak_bytes_allocated());
46+
return MP_OBJ_NEW_SMALL_INT(m_get_peak_bytes_allocated());
4747
}
4848

4949
STATIC MP_DEFINE_CONST_FUN_OBJ_0(mp_micropython_mem_total_obj, mp_micropython_mem_total);

py/obj.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ mp_obj_t mp_obj_len_maybe(mp_obj_t o_in) {
368368
MP_OBJ_IS_STR(o_in) ||
369369
#endif
370370
MP_OBJ_IS_TYPE(o_in, &mp_type_bytes)) {
371-
return MP_OBJ_NEW_SMALL_INT((mp_int_t)mp_obj_str_get_len(o_in));
371+
return MP_OBJ_NEW_SMALL_INT(mp_obj_str_get_len(o_in));
372372
} else {
373373
mp_obj_type_t *type = mp_obj_get_type(o_in);
374374
if (type->unary_op != NULL) {

py/obj.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ typedef struct _mp_obj_base_t mp_obj_base_t;
7676
#define MP_OBJ_IS_STR(o) (MP_OBJ_IS_QSTR(o) || MP_OBJ_IS_TYPE(o, &mp_type_str))
7777

7878
#define MP_OBJ_SMALL_INT_VALUE(o) (((mp_int_t)(o)) >> 1)
79-
#define MP_OBJ_NEW_SMALL_INT(small_int) ((mp_obj_t)(((small_int) << 1) | 1))
79+
#define MP_OBJ_NEW_SMALL_INT(small_int) ((mp_obj_t)((((mp_int_t)(small_int)) << 1) | 1))
8080

8181
#define MP_OBJ_QSTR_VALUE(o) (((mp_int_t)(o)) >> 2)
82-
#define MP_OBJ_NEW_QSTR(qstr) ((mp_obj_t)((((mp_uint_t)qstr) << 2) | 2))
82+
#define MP_OBJ_NEW_QSTR(qstr) ((mp_obj_t)((((mp_uint_t)(qstr)) << 2) | 2))
8383

8484
// These macros are used to declare and define constant function objects
8585
// You can put "static" in front of the definitions to make them local

py/objbool.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ STATIC mp_obj_t bool_unary_op(int op, mp_obj_t o_in) {
7474

7575
STATIC mp_obj_t bool_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
7676
if (MP_BINARY_OP_OR <= op && op <= MP_BINARY_OP_NOT_EQUAL) {
77-
return mp_binary_op(op, MP_OBJ_NEW_SMALL_INT((mp_int_t)mp_obj_is_true(lhs_in)), rhs_in);
77+
return mp_binary_op(op, MP_OBJ_NEW_SMALL_INT(mp_obj_is_true(lhs_in)), rhs_in);
7878
}
7979
return MP_OBJ_NULL; // op not supported
8080
}

py/objdict.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ STATIC mp_obj_t dict_unary_op(int op, mp_obj_t self_in) {
7575
mp_obj_dict_t *self = self_in;
7676
switch (op) {
7777
case MP_UNARY_OP_BOOL: return MP_BOOL(self->map.used != 0);
78-
case MP_UNARY_OP_LEN: return MP_OBJ_NEW_SMALL_INT((mp_int_t)self->map.used);
78+
case MP_UNARY_OP_LEN: return MP_OBJ_NEW_SMALL_INT(self->map.used);
7979
default: return MP_OBJ_NULL; // op not supported
8080
}
8181
}

py/objint.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ STATIC mp_obj_t mp_obj_int_make_new(mp_obj_t type_in, uint n_args, uint n_kw, co
6464
return mp_parse_num_integer(s, l, 0);
6565
#if MICROPY_PY_BUILTINS_FLOAT
6666
} else if (MP_OBJ_IS_TYPE(args[0], &mp_type_float)) {
67-
return MP_OBJ_NEW_SMALL_INT((mp_int_t)(MICROPY_FLOAT_C_FUN(trunc)(mp_obj_float_get(args[0]))));
67+
return MP_OBJ_NEW_SMALL_INT((MICROPY_FLOAT_C_FUN(trunc)(mp_obj_float_get(args[0]))));
6868
#endif
6969
} else {
7070
// try to convert to small int (eg from bool)

py/objset.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ STATIC mp_obj_t set_unary_op(int op, mp_obj_t self_in) {
476476
mp_obj_set_t *self = self_in;
477477
switch (op) {
478478
case MP_UNARY_OP_BOOL: return MP_BOOL(self->set.used != 0);
479-
case MP_UNARY_OP_LEN: return MP_OBJ_NEW_SMALL_INT((mp_int_t)self->set.used);
479+
case MP_UNARY_OP_LEN: return MP_OBJ_NEW_SMALL_INT(self->set.used);
480480
default: return MP_OBJ_NULL; // op not supported
481481
}
482482
}

py/objstr.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ STATIC mp_obj_t str_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
370370
#endif
371371
const byte *p = str_index_to_ptr(type, self_data, self_len, index, false);
372372
if (type == &mp_type_bytes) {
373-
return MP_OBJ_NEW_SMALL_INT((mp_int_t)*p);
373+
return MP_OBJ_NEW_SMALL_INT(*p);
374374
} else {
375375
return mp_obj_new_str((char*)p, 1, true);
376376
}
@@ -1917,7 +1917,7 @@ STATIC mp_obj_t bytes_it_iternext(mp_obj_t self_in) {
19171917
mp_obj_str_it_t *self = self_in;
19181918
GET_STR_DATA_LEN(self->str, str, len);
19191919
if (self->cur < len) {
1920-
mp_obj_t o_out = MP_OBJ_NEW_SMALL_INT((mp_int_t)str[self->cur]);
1920+
mp_obj_t o_out = MP_OBJ_NEW_SMALL_INT(str[self->cur]);
19211921
self->cur += 1;
19221922
return o_out;
19231923
} else {

0 commit comments

Comments
 (0)