8000 py: Downcase all MP_OBJ_IS_xxx macros to make a more consistent C API. · micropython/micropython@eee1e88 · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit eee1e88

Browse files
committed
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.
1 parent 019433a commit eee1e88

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+277
-268
lines changed

py/binary.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ void mp_binary_set_val(char struct_type, char val_type, mp_obj_t val_in, byte **
293293
#endif
294294
default:
295295
#if MICROPY_LONGINT_IMPL != MICROPY_LONGINT_IMPL_NONE
296-
if (MP_OBJ_IS_TYPE(val_in, &mp_type_int)) {
296+
if (mp_obj_is_type( A3E2 val_in, &mp_type_int)) {
297297
mp_obj_int_to_bytes_impl(val_in, struct_type == '>', size, p);
298298
return;
299299
} else
@@ -330,7 +330,7 @@ void mp_binary_set_val_array(char typecode, void *p, mp_uint_t index, mp_obj_t v
330330
break;
331331
default:
332332
#if MICROPY_LONGINT_IMPL != MICROPY_LONGINT_IMPL_NONE
333-
if (MP_OBJ_IS_TYPE(val_in, &mp_type_int)) {
333+
if (mp_obj_is_type(val_in, &mp_type_int)) {
334334
size_t size = mp_binary_get_size('@', typecode, NULL);
335335
mp_obj_int_to_bytes_impl(val_in, MP_ENDIANNESS_BIG,
336336
size, (uint8_t*)p + index * size);

py/builtinevex.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ STATIC mp_obj_t code_execute(mp_obj_code_t *self, mp_obj_dict_t *globals, mp_obj
5252

5353
// a bit of a hack: fun_bc will re-set globals, so need to make sure it's
5454
// the correct one
55-
if (MP_OBJ_IS_TYPE(self->module_fun, &mp_type_fun_bc)) {
55+
if (mp_obj_is_type(self->module_fun, &mp_type_fun_bc)) {
5656
mp_obj_fun_bc_t *fun_bc = MP_OBJ_TO_PTR(self->module_fun);
5757
fun_bc->globals = globals;
5858
}
@@ -114,7 +114,7 @@ STATIC mp_obj_t eval_exec_helper(size_t n_args, const mp_obj_t *args, mp_parse_i
114114
mp_obj_dict_t *locals = mp_locals_get();
115115
for (size_t i = 1; i < 3 && i < n_args; ++i) {
116116
if (args[i] != mp_const_none) {
117-
if (!MP_OBJ_IS_TYPE(args[i], &mp_type_dict)) {
117+
if (!mp_obj_is_type(args[i], &mp_type_dict)) {
118118
mp_raise_TypeError(NULL);
119119
}
120120
locals = MP_OBJ_TO_PTR(args[i]);
@@ -125,7 +125,7 @@ STATIC mp_obj_t eval_exec_helper(size_t n_args, const mp_obj_t *args, mp_parse_i
125125
}
126126

127127
#if MICROPY_PY_BUILTINS_COMPILE
128-
if (MP_OBJ_IS_TYPE(args[0], &mp_type_code)) {
128+
if (mp_obj_is_type(args[0], &mp_type_code)) {
129129
return code_execute(MP_OBJ_TO_PTR(args[0]), globals, locals);
130130
}
131131
#endif

py/compile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2939,7 +2939,7 @@ STATIC void check_for_doc_string(compiler_t *comp, mp_parse_node_t pn) {
29392939
if ((MP_PARSE_NODE_IS_LEAF(pns->nodes[0])
29402940
&& MP_PARSE_NODE_LEAF_KIND(pns->nodes[0]) == MP_PARSE_NODE_STRING)
29412941
|| (MP_PARSE_NODE_IS_STRUCT_KIND(pns->nodes[0], PN_const_object)
2942-
&& MP_OBJ_IS_STR(get_const_object((mp_parse_node_struct_t*)pns->nodes[0])))) {
2942+
&& mp_obj_is_str(get_const_object((mp_parse_node_struct_t*)pns->nodes[0])))) {
29432943
// compile the doc string
29442944
compile_node(comp, pns->nodes[0]);
29452945
// store the doc string

py/emitglue.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,10 @@ mp_obj_t mp_make_function_from_raw_code(const mp_raw_code_t *rc, mp_obj_t def_ar
124124
assert(rc != NULL);
125125

126126
// def_args must be MP_OBJ_NULL or a tuple
127-
assert(def_args == MP_OBJ_NULL || MP_OBJ_IS_TYPE(def_args, &mp_type_tuple));
127+
assert(def_args == MP_OBJ_NULL || mp_obj_is_type(def_args, &mp_type_tuple));
128128
129129
// def_kw_args must be MP_OBJ_NULL or a dict
130-
assert(def_kw_args == MP_OBJ_NULL || MP_OBJ_IS_TYPE(def_kw_args, &mp_type_dict));
130+
assert(def_kw_args == MP_OBJ_NULL || mp_obj_is_type(def_kw_args, &mp_type_dict));
131131

132132
// make the function, depending on the raw code kind
133133
mp_obj_t fun;

py/map.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,9 @@ mp_map_elem_t *mp_map_lookup(mp_map_t *map, mp_obj_t index, mp_map_lookup_kind_t
150150
// Work out if we can compare just pointers
151151
bool compare_only_ptrs = map->all_keys_are_qstrs;
152152
if (compare_only_ptrs) {
153-
if (MP_OBJ_IS_QSTR(index)) {
153+
if (mp_obj_is_qstr(index)) {
154154
// Index is a qstr, so can just do ptr comparison.
155-
} else if (MP_OBJ_IS_TYPE(index, &mp_type_str)) {
155+
} else if (mp_obj_is_type(index, &mp_type_str)) {
156156
// Index is a non-interned string.
157157
// We can either intern the string, or force a full equality comparison.
158158
// We chose the latter, since interning costs time and potentially RAM,
@@ -197,7 +197,7 @@ mp_map_elem_t *mp_map_lookup(mp_map_t *map, mp_obj_t index, mp_map_lookup_kind_t
197197
}
198198
mp_map_elem_t *elem = map->table + map->used++;
199199
elem->key = index;
200-
if (!MP_OBJ_IS_QSTR(index)) {
200+
if (!mp_obj_is_qstr(index)) {
201201
map->all_keys_are_qstrs = 0;
202202
}
203203
return elem;
@@ -218,7 +218,7 @@ mp_map_elem_t *mp_map_lookup(mp_map_t *map, mp_obj_t index, mp_map_lookup_kind_t
218218

219219
// get hash of index, with fast path for common case of qstr
220220
mp_uint_t hash;
221-
if (MP_OBJ_IS_QSTR(index)) {
221+
if (mp_obj_is_qstr(index)) {
222222
hash = qstr_hash(MP_OBJ_QSTR_VALUE(index));
223223
} else {
224224
hash = MP_OBJ_SMALL_INT_VALUE(mp_unary_op(MP_UNARY_OP_HASH, index));
@@ -238,7 +238,7 @@ mp_map_elem_t *mp_map_lookup(mp_map_t *map, mp_obj_t index, mp_map_lookup_kind_t
238238
}
239239
avail_slot->key = index;
240240
avail_slot->value = MP_OBJ_NULL;
241-
if (!MP_OBJ_IS_QSTR(index)) {
241+
if (!mp_obj_is_qstr(index)) {
242242
map->all_keys_are_qstrs = 0;
243243
}
244244
return avail_slot;
@@ -278,7 +278,7 @@ mp_map_elem_t *mp_map_lookup(mp_map_t *map, mp_obj_t index, mp_map_lookup_kind_t
278278
map->used++;
279279
avail_slot->key = index;
280280
avail_slot->value = MP_OBJ_NULL;
281-
if (!MP_OBJ_IS_QSTR(index)) {
281+
if (!mp_obj_is_qstr(index)) {
282282
map->all_keys_are_qstrs = 0;
283283
}
284284
return avail_slot;

py/modbuiltins.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ STATIC mp_obj_t mp_builtin_ord(mp_obj_t o_in) {
357357
size_t len;
358358
const byte *str = (const byte*)mp_obj_str_get_data(o_in, &len);
359359
#if MICROPY_PY_BUILTINS_STR_UNICODE
360-
if (MP_OBJ_IS_STR(o_in)) {
360+
if (mp_obj_is_str(o_in)) {
361361
len = utf8_charlen(str, len);
362362
if (len == 1) {
363363
return mp_obj_new_int(utf8_get_char(str));
@@ -471,7 +471,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_repr_obj, mp_builtin_repr);
471471

472472
STATIC mp_obj_t mp_builtin_round(size_t n_args, const mp_obj_t *args) {
473473
mp_obj_t o_in = args[0];
474-
if (MP_OBJ_IS_INT(o_in)) {
474+
if (mp_obj_is_int(o_in)) {
475475
if (n_args <= 1) {
476476
return o_in;
477477
}

py/mpprint.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ int mp_print_mp_int(const mp_print_t *print, mp_obj_t x, int base, int base_char
207207
// If needed this function could be generalised to handle other values.
208208
assert(base == 2 || base == 8 || base == 10 || base == 16);
209209

210-
if (!MP_OBJ_IS_INT(x)) {
210+
if (!mp_obj_is_int(x)) {
211211
// This will convert booleans to int, or raise an error for
212212
// non-integer types.
213213
x = MP_OBJ_NEW_SMALL_INT(mp_obj_get_int(x));

py/obj.c

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@
3838
#include "py/stream.h" // for mp_obj_print
3939

4040
mp_obj_type_t *mp_obj_get_type(mp_const_obj_t o_in) {
41-
if (MP_OBJ_IS_SMALL_INT(o_in)) {
41+
if (mp_obj_is_small_int(o_in)) {
4242
return (mp_obj_type_t*)&mp_type_int;
43-
} else if (MP_OBJ_IS_QSTR(o_in)) {
43+
} else if (mp_obj_is_qstr(o_in)) {
4444
return (mp_obj_type_t*)&mp_type_str;
4545
#if MICROPY_PY_BUILTINS_FLOAT
4646
} else if (mp_obj_is_float(o_in)) {
@@ -112,7 +112,7 @@ bool mp_obj_is_true(mp_obj_t arg) {
112112
return 1;
113113
} else if (arg == mp_const_none) {
114114
return 0;
115-
} else if (MP_OBJ_IS_SMALL_INT(arg)) {
115+
} else if (mp_obj_is_small_int(arg)) {
116116
if (MP_OBJ_SMALL_INT_VALUE(arg) == 0) {
117117
return 0;
118118
} else {
@@ -167,7 +167,7 @@ bool mp_obj_equal(mp_obj_t o1, mp_obj_t o2) {
167167
&& !mp_obj_is_float(o1)
168168
#endif
169169
#if MICROPY_PY_BUILTINS_COMPLEX
170-
&& !MP_OBJ_IS_TYPE(o1, &mp_type_complex)
170+
&& !mp_obj_is_type(o1, &mp_type_complex)
171171
#endif
172172
) {
173173
return true;
@@ -177,8 +177,8 @@ bool mp_obj_equal(mp_obj_t o1, mp_obj_t o2) {
177177
}
178178

179179
// fast path for small ints
180-
if (MP_OBJ_IS_SMALL_INT(o1)) {
181-
if (MP_OBJ_IS_SMALL_INT(o2)) {
180+
if (mp_obj_is_small_int(o1)) {
181+
if (mp_obj_is_small_int(o2)) {
182182
// both SMALL_INT, and not equal if we get here
183183
return false;
184184
} else {
@@ -189,19 +189,19 @@ bool mp_obj_equal(mp_obj_t o1, mp_obj_t o2) {
189189
}
190190

191191
// fast path for strings
192-
if (MP_OBJ_IS_STR(o1)) {
193-
if (MP_OBJ_IS_STR(o2)) {
192+
if (mp_obj_is_str(o1)) {
193+
if (mp_obj_is_str(o2)) {
194194
// both strings, use special function
195195
return mp_obj_str_equal(o1, o2);
196196
} else {
197197
// a string is never equal to anything else
198198
goto str_cmp_err;
199199
}
200-
} else if (MP_OBJ_IS_STR(o2)) {
200+
} else if (mp_obj_is_str(o2)) {
201201
// o1 is not a string (else caught above), so the objects are not equal
202202
str_cmp_err:
203203
#if MICROPY_PY_STR_BYTES_CMP_WARN
204-
if (MP_OBJ_IS_TYPE(o1, &mp_type_bytes) || MP_OBJ_IS_TYPE(o2, &mp_type_bytes)) {
204+
if (mp_obj_is_type(o1, &mp_type_bytes) || mp_obj_is_type(o2, &mp_type_bytes)) {
205205
mp_warning(MP_WARN_CAT(BytesWarning), "Comparison between bytes and str");
206206
}
207207
#endif
@@ -230,9 +230,9 @@ mp_int_t mp_obj_get_int(mp_const_obj_t arg) {
230230
return 0;
231231
} else if (arg == mp_const_true) {
232232
return 1;
233-
} else if (MP_OBJ_IS_SMALL_INT(arg)) {
233+
} else if (mp_obj_is_small_int(arg)) {
234234
return MP_OBJ_SMALL_INT_VALUE(arg);
235-
} else if (MP_OBJ_IS_TYPE(arg, &mp_type_int)) {
235+
} else if (mp_obj_is_type(arg, &mp_type_int)) {
236236
return mp_obj_int_get_checked(arg);
237237
} else {
238238
mp_obj_t res = mp_unary_op(MP_UNARY_OP_INT, (mp_obj_t)arg);
@@ -241,7 +241,7 @@ mp_int_t mp_obj_get_int(mp_const_obj_t arg) {
241241
}
242242

243243
mp_int_t mp_obj_get_int_truncated(mp_const_obj_t arg) {
244-
if (MP_OBJ_IS_INT(arg)) {
244+
if (mp_obj_is_int(arg)) {
245245
return mp_obj_int_get_truncated(arg);
246246
} else {
247247
return mp_obj_get_int(arg);
@@ -256,9 +256,9 @@ bool mp_obj_get_int_maybe(mp_const_obj_t arg, mp_int_t *value) {
256256
*value = 0;
257257
} else if (arg == mp_const_true) {
258258
*value = 1;
259-
} else if (MP_OBJ_IS_SMALL_INT(arg)) {
259+
} else if (mp_obj_is_small_int(arg)) {
260260
*value = MP_OBJ_SMALL_INT_VALUE(arg);
261-
} else if (MP_OBJ_IS_TYPE(arg, &mp_type_int)) {
261+
} else if (mp_obj_is_type(arg, &mp_type_int)) {
262262
*value = mp_obj_int_get_checked(arg);
263263
} else {
264264
return false;
@@ -274,10 +274,10 @@ bool mp_obj_get_float_maybe(mp_obj_t arg, mp_float_t *value) {
274274
val = 0;
275275
} else if (arg == mp_const_true) {
276276
val = 1;
277-
} else if (MP_OBJ_IS_SMALL_INT(arg)) {
277+
} else if (mp_obj_is_small_int(arg)) {
278278
val = MP_OBJ_SMALL_INT_VALUE(arg);
279279
#if MICROPY_LONGINT_IMPL != MICROPY_LONGINT_IMPL_NONE
280-
} else if (MP_OBJ_IS_TYPE(arg, &mp_type_int)) {
280+
} else if (mp_obj_is_type(arg, &mp_type_int)) {
281281
val = mp_obj_int_as_float_impl(arg);
282282
#endif
283283
} else if (mp_obj_is_float(arg)) {
@@ -313,18 +313,18 @@ void mp_obj_get_complex(mp_obj_t arg, mp_float_t *real, mp_float_t *imag) {
313313
} else if (arg == mp_const_true) {
314314
*real = 1;
315315
*imag = 0;
316-
} else if (MP_OBJ_IS_SMALL_INT(arg)) {
316+
} else if (mp_obj_is_small_int(arg)) {
317317
*real = MP_OBJ_SMALL_INT_VALUE(arg);
318318
*imag = 0;
319319
#if MICROPY_LONGINT_IMPL != MICROPY_LONGINT_IMPL_NONE
320-
} else if (MP_OBJ_IS_TYPE(arg, &mp_type_int)) {
320+
} else if (mp_obj_is_type(arg, &mp_type_int)) {
321321
*real = mp_obj_int_as_float_impl(arg);
322322
*imag = 0;
323323
#endif
324324
} else if (mp_obj_is_float(arg)) {
325325
*real = mp_obj_float_get(arg);
326326
*imag = 0;
327-
} else if (MP_OBJ_IS_TYPE(arg, &mp_type_complex)) {
327+
} else if (mp_obj_is_type(arg, &mp_type_complex)) {
328328
mp_obj_complex_get(arg, real, imag);
329329
} else {
330330
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
@@ -340,9 +340,9 @@ void mp_obj_get_complex(mp_obj_t arg, mp_float_t *real, mp_float_t *imag) {
340340

341341
// note: returned value in *items may point to the interior of a GC block
342342
void mp_obj_get_array(mp_obj_t o, size_t *len, mp_obj_t **items) {
343-
if (MP_OBJ_IS_TYPE(o, &mp_type_tuple)) {
343+
if (mp_obj_is_type(o, &mp_type_tuple)) {
344344
mp_obj_tuple_get(o, len, items);
345-
} else if (MP_OBJ_IS_TYPE(o, &mp_type_list)) {
345+
} else if (mp_obj_is_type(o, &mp_type_list)) {
346346
mp_obj_list_get(o, len, items);
347347
} else {
348348
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
@@ -371,7 +371,7 @@ void mp_obj_get_array_fixed_n(mp_obj_t o, size_t len, mp_obj_t **items) {
371371
// is_slice determines whether the index is a slice index
372372
size_t mp_get_index(const mp_obj_type_t *type, size_t len, mp_obj_t index, bool is_slice) {
373373
mp_int_t i;
374-
if (MP_OBJ_IS_SMALL_INT(index)) {
374+
if (mp_obj_is_small_int(index)) {
375375
i = MP_OBJ_SMALL_INT_VALUE(index);
376376
} else if (!mp_obj_get_int_maybe(index, &i)) {
377377
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
@@ -409,7 +409,7 @@ size_t mp_get_index(const mp_obj_type_t *type, size_t len, mp_obj_t index, bool
409409

410410
mp_obj_t mp_obj_id(mp_obj_t o_in) {
411411
mp_int_t id = (mp_int_t)o_in;
412-
if (!MP_OBJ_IS_OBJ(o_in)) {
412+
if (!mp_obj_is_obj(o_in)) {
413413
return mp_obj_new_int(id);
414414
} else if (id >= 0) {
415415
// Many OSes and CPUs have affinity for putting "user" memories
@@ -445,9 +445,9 @@ mp_obj_t mp_obj_len_maybe(mp_obj_t o_in) {
445445
if (
446446
#if !MICROPY_PY_BUILTINS_STR_UNICODE
447447
// It's simple - unicode is slow, non-unicode is fast
448-
MP_OBJ_IS_STR(o_in) ||
448+
mp_obj_is_str(o_in) ||
449449
#endif
450-
MP_OBJ_IS_TYPE(o_in, &mp_type_bytes)) {
450+
mp_obj_is_type(o_in, &mp_type_bytes)) {
451451
GET_STR_LEN(o_in, l);
452452
return MP_OBJ_NEW_SMALL_INT(l);
453453
} else {

0 commit comments

Comments
 (0)
0