summaryrefslogtreecommitdiff
path: root/py/builtin.c
diff options
context:
space:
mode:
authorPaul Sokolovsky <pfalcon@users.sourceforge.net>2014-04-06 02:12:03 +0300
committerPaul Sokolovsky <pfalcon@users.sourceforge.net>2014-04-06 02:15:23 +0300
commit36dd19ae27ca72c064489c1a4bf7a942b5eecaea (patch)
treec102a7e222edfef14e9203e3bc473761e0cc4031 /py/builtin.c
parent4e1ed82583081a45501723bf9c920e8e776719f4 (diff)
py: Revert mp_load_attr() to its previous state (not supporting default val).
Based on the discussion in #433. mp_load_attr() is critical-path function, so any extra check will slowdown any script. As supporting default val required only for getattr() builtin, move correspending implementation there (still as a separate function due to concerns of maintainability of such almost-duplicated code instances).
Diffstat (limited to 'py/builtin.c')
-rw-r--r--py/builtin.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/py/builtin.c b/py/builtin.c
index 7a01731d0..de1a8fc6a 100644
--- a/py/builtin.c
+++ b/py/builtin.c
@@ -400,6 +400,22 @@ STATIC mp_obj_t mp_builtin_id(mp_obj_t o_in) {
MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_id_obj, mp_builtin_id);
+// See mp_load_attr() if making any changes
+STATIC inline mp_obj_t mp_load_attr_default(mp_obj_t base, qstr attr, mp_obj_t defval) {
+ mp_obj_t dest[2];
+ // use load_method, raising or not raising exception
+ ((defval == MP_OBJ_NULL) ? mp_load_method : mp_load_method_maybe)(base, attr, dest);
+ if (dest[0] == MP_OBJ_NULL) {
+ return defval;
+ } else if (dest[1] == MP_OBJ_NULL) {
+ // load_method returned just a normal attribute
+ return dest[0];
+ } else {
+ // load_method returned a method, so build a bound method object
+ return mp_obj_new_bound_meth(dest[0], dest[1]);
+ }
+}
+
STATIC mp_obj_t mp_builtin_getattr(uint n_args, const mp_obj_t *args) {
assert(MP_OBJ_IS_QSTR(args[1]));
mp_obj_t defval = MP_OBJ_NULL;