aboutsummaryrefslogtreecommitdiff
path: root/py/objtype.c
diff options
context:
space:
mode:
authorDamien George2020-02-21 13:15:21 +1100
committerDamien George2020-02-21 13:20:12 +1100
commit9344e876bb40d2cb759fc8318626952473a4be58 (patch)
tree98ef851a0ff797970d90499992068f3a8f3f7751 /py/objtype.c
parentd3b2c6e44c25ef6714d767e4da4e808a7ba80f23 (diff)
py/objtype: Allow mp_instance_cast_to_native_base to take native obj.
And rename it to mp_obj_cast_to_native_base() to indicate this. This allows users of this function to easily support native and native-subclass objects in the same way (by just passing the object through this function).
Diffstat (limited to 'py/objtype.c')
-rw-r--r--py/objtype.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/py/objtype.c b/py/objtype.c
index b2c2f58d9..206e80ffc 100644
--- a/py/objtype.c
+++ b/py/objtype.c
@@ -1389,13 +1389,17 @@ STATIC mp_obj_t mp_builtin_isinstance(mp_obj_t object, mp_obj_t classinfo) {
MP_DEFINE_CONST_FUN_OBJ_2(mp_builtin_isinstance_obj, mp_builtin_isinstance);
-mp_obj_t mp_instance_cast_to_native_base(mp_const_obj_t self_in, mp_const_obj_t native_type) {
+mp_obj_t mp_obj_cast_to_native_base(mp_obj_t self_in, mp_const_obj_t native_type) {
const mp_obj_type_t *self_type = mp_obj_get_type(self_in);
- if (!mp_obj_is_subclass_fast(MP_OBJ_FROM_PTR(self_type), native_type)) {
+
+ if (MP_OBJ_FROM_PTR(self_type) == native_type) {
+ return self_in;
+ } else if (!mp_obj_is_subclass_fast(MP_OBJ_FROM_PTR(self_type), native_type)) {
return MP_OBJ_NULL;
+ } else {
+ mp_obj_instance_t *self = (mp_obj_instance_t*)MP_OBJ_TO_PTR(self_in);
+ return self->subobj[0];
}
- mp_obj_instance_t *self = (mp_obj_instance_t*)MP_OBJ_TO_PTR(self_in);
- return self->subobj[0];
}
/******************************************************************************/