summaryrefslogtreecommitdiff
path: root/py/objarray.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2019-01-30 18:49:52 +1100
committerDamien George <damien.p.george@gmail.com>2019-02-12 14:54:51 +1100
commiteee1e8841a852f374b83e0a3e3b0ff7b66e54243 (patch)
treec928ad701fc0df71dc2863178ea8d2e8bea4946b /py/objarray.c
parent019433a17e82f22e8ee24ad1b53156403d4f4a67 (diff)
py: Downcase all MP_OBJ_IS_xxx macros to make a more consistent C API.
These macros could in principle be (inline) functions so it makes sense to have them lower case, to match the other C API functions. The remaining macros that are upper case are: - MP_OBJ_TO_PTR, MP_OBJ_FROM_PTR - MP_OBJ_NEW_SMALL_INT, MP_OBJ_SMALL_INT_VALUE - MP_OBJ_NEW_QSTR, MP_OBJ_QSTR_VALUE - MP_OBJ_FUN_MAKE_SIG - MP_DECLARE_CONST_xxx - MP_DEFINE_CONST_xxx These must remain macros because they are used when defining const data (at least, MP_OBJ_NEW_SMALL_INT is so it makes sense to have MP_OBJ_SMALL_INT_VALUE also a macro). For those macros that have been made lower case, compatibility macros are provided for the old names so that users do not need to change their code immediately.
Diffstat (limited to 'py/objarray.c')
-rw-r--r--py/objarray.c26
1 files changed, 13 insertions, 13 deletions
diff --git a/py/objarray.c b/py/objarray.c
index 6f857a9ed..4a8d0af3c 100644
--- a/py/objarray.c
+++ b/py/objarray.c
@@ -119,8 +119,8 @@ STATIC mp_obj_t array_construct(char typecode, mp_obj_t initializer) {
if (((MICROPY_PY_BUILTINS_BYTEARRAY
&& typecode == BYTEARRAY_TYPECODE)
|| (MICROPY_PY_ARRAY
- && (MP_OBJ_IS_TYPE(initializer, &mp_type_bytes)
- || (MICROPY_PY_BUILTINS_BYTEARRAY && MP_OBJ_IS_TYPE(initializer, &mp_type_bytearray)))))
+ && (mp_obj_is_type(initializer, &mp_type_bytes)
+ || (MICROPY_PY_BUILTINS_BYTEARRAY && mp_obj_is_type(initializer, &mp_type_bytearray)))))
&& mp_get_buffer(initializer, &bufinfo, MP_BUFFER_READ)) {
// construct array from raw bytes
// we round-down the len to make it a multiple of sz (CPython raises error)
@@ -184,7 +184,7 @@ STATIC mp_obj_t bytearray_make_new(const mp_obj_type_t *type_in, size_t n_args,
if (n_args == 0) {
// no args: construct an empty bytearray
return MP_OBJ_FROM_PTR(array_new(BYTEARRAY_TYPECODE, 0));
- } else if (MP_OBJ_IS_INT(args[0])) {
+ } else if (mp_obj_is_int(args[0])) {
// 1 arg, an integer: construct a blank bytearray of that length
mp_uint_t len = mp_obj_get_int(args[0]);
mp_obj_array_t *o = array_new(BYTEARRAY_TYPECODE, len);
@@ -279,7 +279,7 @@ STATIC mp_obj_t array_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs
mp_buffer_info_t lhs_bufinfo;
mp_buffer_info_t rhs_bufinfo;
if (mp_get_buffer(rhs_in, &rhs_bufinfo, MP_BUFFER_READ)) {
- if (!MP_OBJ_IS_TYPE(lhs_in, &mp_type_bytearray)) {
+ if (!mp_obj_is_type(lhs_in, &mp_type_bytearray)) {
return mp_const_false;
}
array_get_buffer(lhs_in, &lhs_bufinfo, MP_BUFFER_READ);
@@ -289,7 +289,7 @@ STATIC mp_obj_t array_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs
#endif
// Otherwise, can only look for a scalar numeric value in an array
- if (MP_OBJ_IS_INT(rhs_in) || mp_obj_is_float(rhs_in)) {
+ if (mp_obj_is_int(rhs_in) || mp_obj_is_float(rhs_in)) {
mp_raise_NotImplementedError(NULL);
}
@@ -314,8 +314,8 @@ STATIC mp_obj_t array_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs
#if MICROPY_PY_BUILTINS_BYTEARRAY || MICROPY_PY_ARRAY
STATIC mp_obj_t array_append(mp_obj_t self_in, mp_obj_t arg) {
// self is not a memoryview, so we don't need to use (& TYPECODE_MASK)
- assert((MICROPY_PY_BUILTINS_BYTEARRAY && MP_OBJ_IS_TYPE(self_in, &mp_type_bytearray))
- || (MICROPY_PY_ARRAY && MP_OBJ_IS_TYPE(self_in, &mp_type_array)));
+ assert((MICROPY_PY_BUILTINS_BYTEARRAY && mp_obj_is_type(self_in, &mp_type_bytearray))
+ || (MICROPY_PY_ARRAY && mp_obj_is_type(self_in, &mp_type_array)));
mp_obj_array_t *self = MP_OBJ_TO_PTR(self_in);
if (self->free == 0) {
@@ -335,8 +335,8 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(array_append_obj, array_append);
STATIC mp_obj_t array_extend(mp_obj_t self_in, mp_obj_t arg_in) {
// self is not a memoryview, so we don't need to use (& TYPECODE_MASK)
- assert((MICROPY_PY_BUILTINS_BYTEARRAY && MP_OBJ_IS_TYPE(self_in, &mp_type_bytearray))
- || (MICROPY_PY_ARRAY && MP_OBJ_IS_TYPE(self_in, &mp_type_array)));
+ assert((MICROPY_PY_BUILTINS_BYTEARRAY && mp_obj_is_type(self_in, &mp_type_bytearray))
+ || (MICROPY_PY_ARRAY && mp_obj_is_type(self_in, &mp_type_array)));
mp_obj_array_t *self = MP_OBJ_TO_PTR(self_in);
// allow to extend by anything that has the buffer protocol (extension to CPython)
@@ -377,7 +377,7 @@ STATIC mp_obj_t array_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value
mp_obj_array_t *o = MP_OBJ_TO_PTR(self_in);
if (0) {
#if MICROPY_PY_BUILTINS_SLICE
- } else if (MP_OBJ_IS_TYPE(index_in, &mp_type_slice)) {
+ } else if (mp_obj_is_type(index_in, &mp_type_slice)) {
mp_bound_slice_t slice;
if (!mp_seq_get_fast_slice_indexes(o->len, index_in, &slice)) {
mp_raise_NotImplementedError("only slices with step=1 (aka None) are supported");
@@ -388,7 +388,7 @@ STATIC mp_obj_t array_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value
size_t src_len;
void *src_items;
size_t item_sz = mp_binary_get_size('@', o->typecode & TYPECODE_MASK, NULL);
- if (MP_OBJ_IS_OBJ(value) && ((mp_obj_base_t*)MP_OBJ_TO_PTR(value))->type->subscr == array_subscr) {
+ if (mp_obj_is_obj(value) && ((mp_obj_base_t*)MP_OBJ_TO_PTR(value))->type->subscr == array_subscr) {
// value is array, bytearray or memoryview
mp_obj_array_t *src_slice = MP_OBJ_TO_PTR(value);
if (item_sz != mp_binary_get_size('@', src_slice->typecode & TYPECODE_MASK, NULL)) {
@@ -398,11 +398,11 @@ STATIC mp_obj_t array_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value
src_len = src_slice->len;
src_items = src_slice->items;
#if MICROPY_PY_BUILTINS_MEMORYVIEW
- if (MP_OBJ_IS_TYPE(value, &mp_type_memoryview)) {
+ if (mp_obj_is_type(value, &mp_type_memoryview)) {
src_items = (uint8_t*)src_items + (src_slice->memview_offset * item_sz);
}
#endif
- } else if (MP_OBJ_IS_TYPE(value, &mp_type_bytes)) {
+ } else if (mp_obj_is_type(value, &mp_type_bytes)) {
if (item_sz != 1) {
goto compat_error;
}