diff options
| author | Damien George | 2014-11-03 16:09:39 +0000 |
|---|---|---|
| committer | Damien George | 2014-11-03 16:09:39 +0000 |
| commit | 0344fa1ddfbe8674061fed8e904468b9bd2aa550 (patch) | |
| tree | 54f4e31a21eb4722bbc07fb7d939a6364e5d2276 /py/objtype.c | |
| parent | 2cd79fa92484330e415cf0b400544ad90205a611 (diff) | |
py: Fix builtin callable so it checks user-defined instances correctly.
Addresses issue #953.
Diffstat (limited to 'py/objtype.c')
| -rw-r--r-- | py/objtype.c | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/py/objtype.c b/py/objtype.c index cb6b95733..b0c6a629d 100644 --- a/py/objtype.c +++ b/py/objtype.c @@ -583,7 +583,7 @@ STATIC mp_obj_t instance_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value } } -STATIC mp_obj_t instance_call(mp_obj_t self_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { +bool mp_obj_instance_is_callable(mp_obj_t self_in) { mp_obj_instance_t *self = self_in; mp_obj_t member[2] = {MP_OBJ_NULL}; struct class_lookup_data lookup = { @@ -593,6 +593,19 @@ STATIC mp_obj_t instance_call(mp_obj_t self_in, mp_uint_t n_args, mp_uint_t n_kw .dest = member, }; mp_obj_class_lookup(&lookup, self->base.type); + return member[0] != MP_OBJ_NULL; +} + +mp_obj_t mp_obj_instance_call(mp_obj_t self_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) { + mp_obj_instance_t *self = self_in; + mp_obj_t member[2] = {MP_OBJ_NULL, MP_OBJ_NULL}; + struct class_lookup_data lookup = { + .obj = self, + .attr = MP_QSTR___call__, + .meth_offset = offsetof(mp_obj_type_t, call), + .dest = member, + }; + mp_obj_class_lookup(&lookup, self->base.type); if (member[0] == MP_OBJ_NULL) { nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "'%s' object is not callable", mp_obj_get_type_str(self_in))); } @@ -777,7 +790,7 @@ mp_obj_t mp_obj_new_type(qstr name, mp_obj_t bases_tuple, mp_obj_t locals_dict) o->load_attr = instance_load_attr; o->store_attr = instance_store_attr; o->subscr = instance_subscr; - o->call = instance_call; + o->call = mp_obj_instance_call; o->getiter = instance_getiter; o->bases_tuple = bases_tuple; o->locals_dict = locals_dict; |
