Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
uPython-mirror
Commits
b9cf3d37
Commit
b9cf3d37
authored
Apr 08, 2014
by
Paul Sokolovsky
Browse files
bytearray: Support bytearray(int) constructor.
To create bytearray of given length.
parent
72cfc6ef
Changes
2
Hide whitespace changes
Inline
Side-by-side
py/objarray.c
View file @
b9cf3d37
...
...
@@ -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
);
...
...
tests/basics/bytearray1.py
View file @
b9cf3d37
print
(
bytearray
(
4
))
a
=
bytearray
([
1
,
2
,
200
])
print
(
a
[
0
],
a
[
2
])
print
(
a
[
-
1
])
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment