diff options
author | Damien George <damien.p.george@gmail.com> | 2014-04-08 18:29:50 +0100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-04-08 18:29:50 +0100 |
commit | 134c10e776a5d75cfdd6bf98697cb50d7da7adf6 (patch) | |
tree | 31eef85b9103ecc747353fe3703f751b000bafa8 /py | |
parent | 47e1b85d9c2e87aad8396da8b2c492157deaaf3a (diff) | |
parent | f898a95cbaa9046da4e50b500d13b1765d67a94d (diff) | |
download | micropython-134c10e776a5d75cfdd6bf98697cb50d7da7adf6.tar.gz micropython-134c10e776a5d75cfdd6bf98697cb50d7da7adf6.zip |
Merge branch 'master' of github.com:micropython/micropython
Diffstat (limited to 'py')
-rw-r--r-- | py/objarray.c | 7 | ||||
-rw-r--r-- | py/objstr.c | 1 |
2 files changed, 8 insertions, 0 deletions
diff --git a/py/objarray.c b/py/objarray.c index 0383cb17b3..4f9fa49bcb 100644 --- a/py/objarray.c +++ b/py/objarray.c @@ -91,6 +91,13 @@ STATIC mp_obj_t array_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const m // This is top-level factory function, not virtual method // TODO: "bytearray" really should be type, not function STATIC mp_obj_t mp_builtin_bytearray(mp_obj_t arg) { + if (MP_OBJ_IS_SMALL_INT(arg)) { + uint len = MP_OBJ_SMALL_INT_VALUE(arg); + mp_obj_array_t *o = array_new(BYTEARRAY_TYPECODE, len); + memset(o->items, 0, len); + return o; + } + return array_construct(BYTEARRAY_TYPECODE, arg); } MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_bytearray_obj, mp_builtin_bytearray); diff --git a/py/objstr.c b/py/objstr.c index d2d672b983..5e9f0c76b6 100644 --- a/py/objstr.c +++ b/py/objstr.c @@ -1352,6 +1352,7 @@ const mp_obj_type_t mp_type_bytes = { .make_new = bytes_make_new, .binary_op = str_binary_op, .getiter = mp_obj_new_bytes_iterator, + .buffer_p = { .get_buffer = str_get_buffer }, .locals_dict = (mp_obj_t)&str_locals_dict, }; |