From 3f5226246517be2f28d4f23d6e4c202047915f83 Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 3 Jun 2014 13:40:16 +0100 Subject: [PATCH] py: Allow tail call optimisation in mp_call_function_n_kw. This saves 4 words of stack space per Python call. --- py/objtype.c | 2 +- py/runtime.c | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/py/objtype.c b/py/objtype.c index ebbb6097dd..a51e12f1fd 100644 --- a/py/objtype.c +++ b/py/objtype.c @@ -516,7 +516,7 @@ STATIC mp_obj_t instance_call(mp_obj_t self_in, uint n_args, uint n_kw, const mp mp_obj_t member[2] = {MP_OBJ_NULL}; mp_obj_class_lookup(self, self->base.type, MP_QSTR___call__, offsetof(mp_obj_type_t, call), member); if (member[0] == MP_OBJ_NULL) { - return 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))); } if (member[0] == MP_OBJ_SENTINEL) { return mp_call_function_n_kw(self->subobj[0], n_args, n_kw, args); diff --git a/py/runtime.c b/py/runtime.c index 27a5ed5439..f13cc1d892 100644 --- a/py/runtime.c +++ b/py/runtime.c @@ -526,10 +526,7 @@ mp_obj_t mp_call_function_n_kw(mp_obj_t fun_in, uint n_args, uint n_kw, const mp // do the call if (type->call != NULL) { - mp_obj_t res = type->call(fun_in, n_args, n_kw, args); - if (res != NULL) { - return res; - } + return type->call(fun_in, n_args, n_kw, args); } nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "'%s' object is not callable", mp_obj_get_type_str(fun_in)));