summaryrefslogtreecommitdiff
path: root/py/objlist.c
diff options
context:
space:
mode:
authorPaul Sokolovsky <pfalcon@users.sourceforge.net>2015-02-15 22:24:03 +0300
committerPaul Sokolovsky <pfalcon@users.sourceforge.net>2015-02-15 22:41:14 +0300
commitfa3b8951452ca13a807c0b6a090e0385507113db (patch)
tree84f4d280e5e696a91528327aae226adeb3f28bbd /py/objlist.c
parent29c4f92e13f27a6fabf7556184325c2483ace358 (diff)
objexcept: Optimize traceback allocation for exception.
Traceback allocation for exception will now never lead to recursive MemoryError exception - if there's no memory for traceback, it simply won't be created.
Diffstat (limited to 'py/objlist.c')
-rw-r--r--py/objlist.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/py/objlist.c b/py/objlist.c
index 0ff3b1d53..476826301 100644
--- a/py/objlist.c
+++ b/py/objlist.c
@@ -477,6 +477,25 @@ mp_obj_t mp_obj_new_list(mp_uint_t n, mp_obj_t *items) {
return o;
}
+// Special method for usage with exceptions
+// Doesn't initialize items, assumes they will be initialized by client.
+mp_obj_t mp_obj_new_list_maybe(mp_uint_t n) {
+ mp_obj_list_t *o = m_new_obj_maybe(mp_obj_list_t);
+ if (!o) {
+ return o;
+ }
+ o->items = m_new_maybe(mp_obj_t, n);
+ if (!o->items) {
+ m_del_obj(mp_obj_list_t, o);
+ return MP_OBJ_NULL;
+ }
+
+ o->base.type = &mp_type_list;
+ o->len = o->alloc = n;
+
+ return o;
+}
+
void mp_obj_list_get(mp_obj_t self_in, mp_uint_t *len, mp_obj_t **items) {
mp_obj_list_t *self = self_in;
*len = self->len;