summaryrefslogtreecommitdiffstatshomepage
path: root/py/objobject.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2015-05-03 23:23:18 +0100
committerDamien George <damien.p.george@gmail.com>2015-05-04 11:08:40 +0100
commit47b9809d231c4359c56316130a76f13de2b907f7 (patch)
treeca8b6341b8e28f6c2692e92005bb8f072b14b5a3 /py/objobject.c
parent0116218fa89cc88d5d5ed7291c4f8d3412f78543 (diff)
downloadmicropython-47b9809d231c4359c56316130a76f13de2b907f7.tar.gz
micropython-47b9809d231c4359c56316130a76f13de2b907f7.zip
py: Check that arg to object.__new__ is a user-defined type.
Addresses issue #1203.
Diffstat (limited to 'py/objobject.c')
-rw-r--r--py/objobject.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/py/objobject.c b/py/objobject.c
index c5675c0719..7288ac946e 100644
--- a/py/objobject.c
+++ b/py/objobject.c
@@ -26,10 +26,9 @@
#include <stdlib.h>
+#include "py/objtype.h"
#include "py/runtime.h"
-mp_obj_t instance_make_new(mp_obj_t self_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args);
-
typedef struct _mp_obj_object_t {
mp_obj_base_t base;
} mp_obj_object_t;
@@ -50,8 +49,12 @@ STATIC mp_obj_t object___init__(mp_obj_t self) {
STATIC MP_DEFINE_CONST_FUN_OBJ_1(object___init___obj, object___init__);
STATIC mp_obj_t object___new__(mp_obj_t cls) {
+ if (!MP_OBJ_IS_TYPE(cls, &mp_type_type) || !mp_obj_is_instance_type((mp_obj_type_t*)cls)) {
+ nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError,
+ "__new__ arg must be a user-type"));
+ }
mp_obj_t o = MP_OBJ_SENTINEL;
- mp_obj_t res = instance_make_new(cls, 1, 0, &o);
+ mp_obj_t res = mp_obj_instance_make_new(cls, 1, 0, &o);
return res;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(object___new___fun_obj, object___new__);