aboutsummaryrefslogtreecommitdiff
path: root/py/objtype.h
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2017-12-12 15:22:03 +1100
committerDamien George <damien.p.george@gmail.com>2017-12-12 16:53:44 +1100
commitc78ef92d787d7bab8acbec69e978037ec2b20d21 (patch)
treed539242f509ac167ee78f790b8e5424b06f801d8 /py/objtype.h
parent3c28df16586157b6b80e7437559c36f05a309e24 (diff)
py/objtype: Refactor object's handling of __new__ to not create 2 objs.
Before this patch, if a user defined the __new__() function for a class then two instances of that class would be created: once before __new__ is called and once during the __new__ call (assuming the user creates some instance, eg using super().__new__, which is most of the time). The first one was then discarded. This refactor makes it so that a new instance is only created if the user __new__ function doesn't exist.
Diffstat (limited to 'py/objtype.h')
-rw-r--r--py/objtype.h5
1 files changed, 5 insertions, 0 deletions
diff --git a/py/objtype.h b/py/objtype.h
index 52419f3cd..1f4313084 100644
--- a/py/objtype.h
+++ b/py/objtype.h
@@ -37,6 +37,11 @@ typedef struct _mp_obj_instance_t {
// TODO maybe cache __getattr__ and __setattr__ for efficient lookup of them
} mp_obj_instance_t;
+#if MICROPY_CPYTHON_COMPAT
+// this is needed for object.__new__
+mp_obj_instance_t *mp_obj_new_instance(const mp_obj_type_t *cls, const mp_obj_type_t **native_base);
+#endif
+
// this needs to be exposed for MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE to work
void mp_obj_instance_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest);