summaryrefslogtreecommitdiff
path: root/py/objarray.c
diff options
context:
space:
mode:
authorPaul Sokolovsky <pfalcon@users.sourceforge.net>2014-01-28 02:31:52 +0200
committerPaul Sokolovsky <pfalcon@users.sourceforge.net>2014-01-28 03:18:30 +0200
commit11973b48b58862d346f416f400887061eb032898 (patch)
tree73a3d73560c5dcd76a502668391f36a70b3e2062 /py/objarray.c
parent42647e64db811ec0967eae6576fc6b0028aabfdb (diff)
array.array: Allow to create empty arrays.
Diffstat (limited to 'py/objarray.c')
-rw-r--r--py/objarray.c23
1 files changed, 10 insertions, 13 deletions
diff --git a/py/objarray.c b/py/objarray.c
index 4f3656115..88f788811 100644
--- a/py/objarray.c
+++ b/py/objarray.c
@@ -164,20 +164,17 @@ static mp_obj_t array_construct(char typecode, mp_obj_t initializer) {
}
static mp_obj_t array_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_obj_t *args) {
- switch (n_args) {
- case 2:
- {
- // TODO check args
- uint l;
- const byte *s = mp_obj_str_get_data(args[0], &l);
- mp_obj_t initializer = args[1];
- return array_construct(*s, initializer);
- }
-
- default:
- nlr_jump(mp_obj_new_exception_msg_varg(MP_QSTR_TypeError, "unexpected # of arguments, %d given", n_args));
+ if (n_args < 1 || n_args > 2) {
+ nlr_jump(mp_obj_new_exception_msg_varg(MP_QSTR_TypeError, "unexpected # of arguments, %d given", n_args));
+ }
+ // TODO check args
+ uint l;
+ const byte *typecode = mp_obj_str_get_data(args[0], &l);
+ if (n_args == 1) {
+ return array_new(*typecode, 0);
}
- return NULL;
+
+ return array_construct(*typecode, args[1]);
}
// This is top-level factory function, not virtual method