Skip to content

Commit 6ac5dce

Browse files
committed
py: Rename MP_OBJ_NOT_SUPPORTED to MP_OBJ_NULL.
See issue adafruit#608 for justification.
1 parent 6d19774 commit 6ac5dce

File tree

19 files changed

+61
-70
lines changed

19 files changed

+61
-70
lines changed

py/obj.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ int mp_obj_is_true(mp_obj_t arg) {
122122
mp_obj_type_t *type = mp_obj_get_type(arg);
123123
if (type->unary_op != NULL) {
124124
mp_obj_t result = type->unary_op(MP_UNARY_OP_BOOL, arg);
125-
if (result != MP_OBJ_NOT_SUPPORTED) {
125+
if (result != MP_OBJ_NULL) {
126126
return result == mp_const_true;
127127
}
128128
}
@@ -212,7 +212,7 @@ bool mp_obj_equal(mp_obj_t o1, mp_obj_t o2) {
212212
mp_obj_type_t *type = mp_obj_get_type(o1);
213213
if (type->binary_op != NULL) {
214214
mp_obj_t r = type->binary_op(MP_BINARY_OP_EQUAL, o1, o2);
215-
if (r != MP_OBJ_NOT_SUPPORTED) {
215+
if (r != MP_OBJ_NULL) {
216216
return r == mp_const_true ? true : false;
217217
}
218218
}
@@ -357,12 +357,7 @@ mp_obj_t mp_obj_len_maybe(mp_obj_t o_in) {
357357
} else {
358358
mp_obj_type_t *type = mp_obj_get_type(o_in);
359359
if (type->unary_op != NULL) {
360-
mp_obj_t val = type->unary_op(MP_UNARY_OP_LEN, o_in);
361-
// TODO: Here's the case of having MP_OBJ_NOT_SUPPORTED is confusing
362-
if (val == MP_OBJ_NOT_SUPPORTED) {
363-
return MP_OBJ_NULL;
364-
}
365-
return val;
360+
return type->unary_op(MP_UNARY_OP_LEN, o_in);
366361
} else {
367362
return MP_OBJ_NULL;
368363
}
@@ -373,7 +368,7 @@ mp_obj_t mp_obj_subscr(mp_obj_t base, mp_obj_t index, mp_obj_t value) {
373368
mp_obj_type_t *type = mp_obj_get_type(base);
374369
if (type->subscr != NULL) {
375370
mp_obj_t ret = type->subscr(base, index, value);
376-
if (ret != MP_OBJ_NOT_SUPPORTED) {
371+
if (ret != MP_OBJ_NULL) {
377372
return ret;
378373
}
379374
// TODO: call base classes here?

py/obj.h

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ typedef struct _mp_obj_base_t mp_obj_base_t;
5252
// These fake objects are used to indicate certain things in arguments or return
5353
// values, and should only be used when explicitly allowed.
5454
//
55-
// - MP_OBJ_NULL : used to indicate the absence of an object.
56-
// - MP_OBJ_NOT_SUPPORTED : a return value that indicates an unsupported operation.
55+
// - MP_OBJ_NULL : used to indicate the absence of an object, or unsupported operation.
5756
// - MP_OBJ_STOP_ITERATION : used instead of throwing a StopIteration, for efficiency.
5857
// - MP_OBJ_SENTINEL : used for various internal purposes where one needs
5958
// an object which is unique from all other objects, including MP_OBJ_NULL.
@@ -63,14 +62,12 @@ typedef struct _mp_obj_base_t mp_obj_base_t;
6362

6463
#if NDEBUG
6564
#define MP_OBJ_NULL ((mp_obj_t)0)
66-
#define MP_OBJ_NOT_SUPPORTED ((mp_obj_t)0)
6765
#define MP_OBJ_STOP_ITERATION ((mp_obj_t)0)
6866
#define MP_OBJ_SENTINEL ((mp_obj_t)4)
6967
#else
7068
#define MP_OBJ_NULL ((mp_obj_t)0)
71-
#define MP_OBJ_NOT_SUPPORTED ((mp_obj_t)4)
72-
#define MP_OBJ_STOP_ITERATION ((mp_obj_t)8)
73-
#define MP_OBJ_SENTINEL ((mp_obj_t)12)
69+
#define MP_OBJ_STOP_ITERATION ((mp_obj_t)4)
70+
#define MP_OBJ_SENTINEL ((mp_obj_t)8)
7471
#endif
7572

7673
// These macros check for small int, qstr or object, and access small int and qstr values
@@ -256,15 +253,15 @@ struct _mp_obj_type_t {
256253
mp_make_new_fun_t make_new; // to make an instance of the type
257254

258255
mp_call_fun_t call;
259-
mp_unary_op_fun_t unary_op; // can return MP_OBJ_NOT_SUPPORTED if op not supported
260-
mp_binary_op_fun_t binary_op; // can return MP_OBJ_NOT_SUPPORTED if op not supported
256+
mp_unary_op_fun_t unary_op; // can return MP_OBJ_NULL if op not supported
257+
mp_binary_op_fun_t binary_op; // can return MP_OBJ_NULL if op not supported
261258

262259
mp_load_attr_fun_t load_attr;
263260
mp_store_attr_fun_t store_attr; // if value is MP_OBJ_NULL, then delete that attribute
264261

265262
mp_subscr_fun_t subscr; // implements load, store, delete subscripting
266263
// value=MP_OBJ_NULL means delete, value=MP_OBJ_SENTINEL means load, else store
267-
// can return MP_OBJ_NOT_SUPPORTED
264+
// can return MP_OBJ_NULL if op not supported
268265

269266
mp_fun_1_t getiter;
270267
mp_fun_1_t iternext; // may return MP_OBJ_STOP_ITERATION as an optimisation instead of raising StopIteration() (with no args)
@@ -483,11 +480,11 @@ typedef struct _mp_obj_float_t {
483480
mp_float_t value;
484481
} mp_obj_float_t;
485482
mp_float_t mp_obj_float_get(mp_obj_t self_in);
486-
mp_obj_t mp_obj_float_binary_op(int op, mp_float_t lhs_val, mp_obj_t rhs); // can return MP_OBJ_NOT_SUPPORTED
483+
mp_obj_t mp_obj_float_binary_op(int op, mp_float_t lhs_val, mp_obj_t rhs); // can return MP_OBJ_NULL if op not supported
487484

488485
// complex
489486
void mp_obj_complex_get(mp_obj_t self_in, mp_float_t *real, mp_float_t *imag);
490-
mp_obj_t mp_obj_complex_binary_op(int op, mp_float_t lhs_real, mp_float_t lhs_imag, mp_obj_t rhs_in); // can return MP_OBJ_NOT_SUPPORTED
487+
mp_obj_t mp_obj_complex_binary_op(int op, mp_float_t lhs_real, mp_float_t lhs_imag, mp_obj_t rhs_in); // can return MP_OBJ_NULL if op not supported
491488
#endif
492489

493490
// tuple

py/objarray.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ STATIC mp_obj_t array_unary_op(int op, mp_obj_t o_in) {
140140
switch (op) {
141141
case MP_UNARY_OP_BOOL: return MP_BOOL(o->len != 0);
142142
case MP_UNARY_OP_LEN: return MP_OBJ_NEW_SMALL_INT(o->len);
143-
default: return MP_OBJ_NOT_SUPPORTED;
143+
default: return MP_OBJ_NULL; // op not supported
144144
}
145145
}
146146

@@ -166,15 +166,15 @@ STATIC mp_obj_t array_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value
166166
// TODO implement
167167
// TODO: confirmed that both bytearray and array.array support
168168
// slice deletion
169-
return MP_OBJ_NOT_SUPPORTED;
169+
return MP_OBJ_NULL; // op not supported
170170
} else {
171171
mp_obj_array_t *o = self_in;
172172
if (MP_OBJ_IS_TYPE(index_in, &mp_type_slice)) {
173173
if (value != MP_OBJ_SENTINEL) {
174174
// Only getting a slice is suported so far, not assignment
175175
// TODO: confirmed that both bytearray and array.array support
176176
// slice assignment (incl. of different size)
177-
return MP_OBJ_NOT_SUPPORTED;
177+
return MP_OBJ_NULL; // op not supported
178178
}
179179
machine_uint_t start, stop;
180180
if (!mp_seq_get_fast_slice_indexes(o->len, index_in, &start, &stop)) {

py/objbool.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ 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) {
7777
return mp_binary_op(op, MP_OBJ_NEW_SMALL_INT((machine_int_t)mp_obj_is_true(lhs_in)), rhs_in);
7878
}
79-
return MP_OBJ_NOT_SUPPORTED;
79+
return MP_OBJ_NULL; // op not supported
8080
}
8181

8282
const mp_obj_type_t mp_type_bool = {

py/objcomplex.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ STATIC mp_obj_t complex_unary_op(int op, mp_obj_t o_in) {
123123
case MP_UNARY_OP_BOOL: return MP_BOOL(o->real != 0 || o->imag != 0);
124124
case MP_UNARY_OP_POSITIVE: return o_in;
125125
case MP_UNARY_OP_NEGATIVE: return mp_obj_new_complex(-o->real, -o->imag);
126-
default: return MP_OBJ_NOT_SUPPORTED;
126+
default: return MP_OBJ_NULL; // op not supported
127127
}
128128
}
129129

@@ -233,7 +233,7 @@ mp_obj_t mp_obj_complex_binary_op(int op, mp_float_t lhs_real, mp_float_t lhs_im
233233
case MP_BINARY_OP_EQUAL: return MP_BOOL(lhs_real == rhs_real && lhs_imag == rhs_imag);
234234

235235
default:
236-
return MP_OBJ_NOT_SUPPORTED;
236+
return MP_OBJ_NULL; // op not supported
237237
}
238238
return mp_obj_new_complex(lhs_real, lhs_imag);
239239
}

py/objdict.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ STATIC mp_obj_t dict_unary_op(int op, mp_obj_t self_in) {
103103
switch (op) {
104104
case MP_UNARY_OP_BOOL: return MP_BOOL(self->map.used != 0);
105105
case MP_UNARY_OP_LEN: return MP_OBJ_NEW_SMALL_INT((machine_int_t)self->map.used);
106-
default: return MP_OBJ_NOT_SUPPORTED;
106+
default: return MP_OBJ_NULL; // op not supported
107107
}
108108
}
109109

@@ -140,7 +140,7 @@ STATIC mp_obj_t dict_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
140140
}
141141
default:
142142
// op not supported
143-
return MP_OBJ_NOT_SUPPORTED;
143+
return MP_OBJ_NULL;
144144
}
145145
}
146146

@@ -463,13 +463,13 @@ STATIC void dict_view_print(void (*print)(void *env, const char *fmt, ...), void
463463
}
464464

465465
STATIC mp_obj_t dict_view_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
466-
/* only supported for the 'keys' kind until sets and dicts are refactored */
466+
// only supported for the 'keys' kind until sets and dicts are refactored
467467
mp_obj_dict_view_t *o = lhs_in;
468468
if (o->kind != MP_DICT_VIEW_KEYS) {
469-
return MP_OBJ_NOT_SUPPORTED;
469+
return MP_OBJ_NULL; // op not supported
470470
}
471471
if (op != MP_BINARY_OP_IN) {
472-
return MP_OBJ_NOT_SUPPORTED;
472+
return MP_OBJ_NULL; // op not supported
473473
}
474474
return dict_binary_op(op, o->dict, rhs_in);
475475
}

py/objfloat.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ STATIC mp_obj_t float_unary_op(int op, mp_obj_t o_in) {
9696
case MP_UNARY_OP_BOOL: return MP_BOOL(o->value != 0);
9797
case MP_UNARY_OP_POSITIVE: return o_in;
9898
case MP_UNARY_OP_NEGATIVE: return mp_obj_new_float(-o->value);
99-
default: return MP_OBJ_NOT_SUPPORTED;
99+
default: return MP_OBJ_NULL; // op not supported
100100
}
101101
}
102102

@@ -165,7 +165,7 @@ mp_obj_t mp_obj_float_binary_op(int op, mp_float_t lhs_val, mp_obj_t rhs_in) {
165165
case MP_BINARY_OP_MORE_EQUAL: return MP_BOOL(lhs_val >= rhs_val);
166166

167167
default:
168-
return MP_OBJ_NOT_SUPPORTED;
168+
return MP_OBJ_NULL; // op not supported
169169
}
170170
return mp_obj_new_float(lhs_val);
171171
}

py/objfun.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ STATIC mp_obj_t fun_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
5959
// we don't even need to check for 2nd arg type.
6060
return MP_BOOL(lhs_in == rhs_in);
6161
}
62-
return MP_OBJ_NOT_SUPPORTED;
62+
return MP_OBJ_NULL; // op not supported
6363
}
6464

6565
STATIC mp_obj_t fun_native_call(mp_obj_t self_in, uint n_args, uint n_kw, const mp_obj_t *args) {

py/objint.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ bool mp_obj_int_is_positive(mp_obj_t self_in) {
216216

217217
// This is called for operations on SMALL_INT that are not handled by mp_unary_op
218218
mp_obj_t mp_obj_int_unary_op(int op, mp_obj_t o_in) {
219-
return MP_OBJ_NOT_SUPPORTED;
219+
return MP_OBJ_NULL; // op not supported
220220
}
221221

222222
// This is called for operations on SMALL_INT that are not handled by mp_binary_op
@@ -285,7 +285,7 @@ mp_obj_t mp_obj_int_binary_op_extra_cases(int op, mp_obj_t lhs_in, mp_obj_t rhs_
285285
return mp_binary_op(op, rhs_in, lhs_in);
286286
}
287287
}
288-
return MP_OBJ_NOT_SUPPORTED;
288+
return MP_OBJ_NULL; // op not supported
289289
}
290290

291291
// this is a classmethod

py/objint_longlong.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ mp_obj_t mp_obj_int_unary_op(int op, mp_obj_t o_in) {
6464
case MP_UNARY_OP_POSITIVE: return o_in;
6565
case MP_UNARY_OP_NEGATIVE: return mp_obj_new_int_from_ll(-o->val);
6666
case MP_UNARY_OP_INVERT: return mp_obj_new_int_from_ll(~o->val);
67-
default: return MP_OBJ_NOT_SUPPORTED;
67+
default: return MP_OBJ_NULL; // op not supported
6868
}
6969
}
7070

@@ -77,7 +77,7 @@ mp_obj_t mp_obj_int_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
7777
} else if (MP_OBJ_IS_TYPE(lhs_in, &mp_type_int)) {
7878
lhs_val = ((mp_obj_int_t*)lhs_in)->val;
7979
} else {
80-
return MP_OBJ_NOT_SUPPORTED;
80+
return MP_OBJ_NULL; // op not supported
8181
}
8282

8383
if (MP_OBJ_IS_SMALL_INT(rhs_in)) {
@@ -135,7 +135,7 @@ mp_obj_t mp_obj_int_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
135135
return MP_BOOL(lhs_val == rhs_val);
136136

137137
default:
138-
return MP_OBJ_NOT_SUPPORTED;
138+
return MP_OBJ_NULL; // op not supported
139139
}
140140
}
141141

0 commit comments

Comments
 (0)