Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
uPython-mirror
Commits
ccc52542
Commit
ccc52542
authored
Feb 16, 2017
by
Damien George
Browse files
py/objarray: Convert mp_uint_t to size_t where appropriate.
parent
c0d9500e
Changes
3
Hide whitespace changes
Inline
Side-by-side
py/obj.h
View file @
ccc52542
...
...
@@ -613,8 +613,8 @@ mp_obj_t mp_obj_new_int_from_ull(unsigned long long val); // this must return a
mp_obj_t
mp_obj_new_str
(
const
char
*
data
,
size_t
len
,
bool
make_qstr_if_not_already
);
mp_obj_t
mp_obj_new_str_from_vstr
(
const
mp_obj_type_t
*
type
,
vstr_t
*
vstr
);
mp_obj_t
mp_obj_new_bytes
(
const
byte
*
data
,
size_t
len
);
mp_obj_t
mp_obj_new_bytearray
(
mp_uint
_t
n
,
void
*
items
);
mp_obj_t
mp_obj_new_bytearray_by_ref
(
mp_uint
_t
n
,
void
*
items
);
mp_obj_t
mp_obj_new_bytearray
(
size
_t
n
,
void
*
items
);
mp_obj_t
mp_obj_new_bytearray_by_ref
(
size
_t
n
,
void
*
items
);
#if MICROPY_PY_BUILTINS_FLOAT
mp_obj_t
mp_obj_new_int_from_float
(
mp_float_t
val
);
mp_obj_t
mp_obj_new_complex
(
mp_float_t
real
,
mp_float_t
imag
);
...
...
@@ -639,7 +639,7 @@ mp_obj_t mp_obj_new_super(mp_obj_t type, mp_obj_t obj);
mp_obj_t
mp_obj_new_bound_meth
(
mp_obj_t
meth
,
mp_obj_t
self
);
mp_obj_t
mp_obj_new_getitem_iter
(
mp_obj_t
*
args
);
mp_obj_t
mp_obj_new_module
(
qstr
module_name
);
mp_obj_t
mp_obj_new_memoryview
(
byte
typecode
,
mp_uint
_t
nitems
,
void
*
items
);
mp_obj_t
mp_obj_new_memoryview
(
byte
typecode
,
size
_t
nitems
,
void
*
items
);
mp_obj_type_t
*
mp_obj_get_type
(
mp_const_obj_t
o_in
);
const
char
*
mp_obj_get_type_str
(
mp_const_obj_t
o_in
);
...
...
py/objarray.c
View file @
ccc52542
...
...
@@ -56,7 +56,7 @@
#if MICROPY_PY_BUILTINS_MEMORYVIEW
#define TYPECODE_MASK (0x7f)
#else
#define TYPECODE_MASK (~(
mp_uint
_t)0)
#define TYPECODE_MASK (~(
size
_t)0)
#endif
STATIC
mp_obj_t
array_iterator_new
(
mp_obj_t
array_in
);
...
...
@@ -78,7 +78,7 @@ STATIC void array_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t
mp_printf
(
print
,
"array('%c'"
,
o
->
typecode
);
if
(
o
->
len
>
0
)
{
mp_print_str
(
print
,
", ["
);
for
(
mp_uint
_t
i
=
0
;
i
<
o
->
len
;
i
++
)
{
for
(
size
_t
i
=
0
;
i
<
o
->
len
;
i
++
)
{
if
(
i
>
0
)
{
mp_print_str
(
print
,
", "
);
}
...
...
@@ -92,7 +92,7 @@ STATIC void array_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t
#endif
#if MICROPY_PY_BUILTINS_BYTEARRAY || MICROPY_PY_ARRAY
STATIC
mp_obj_array_t
*
array_new
(
char
typecode
,
mp_uint
_t
n
)
{
STATIC
mp_obj_array_t
*
array_new
(
char
typecode
,
size
_t
n
)
{
int
typecode_size
=
mp_binary_get_size
(
'@'
,
typecode
,
NULL
);
mp_obj_array_t
*
o
=
m_new_obj
(
mp_obj_array_t
);
#if MICROPY_PY_BUILTINS_BYTEARRAY && MICROPY_PY_ARRAY
...
...
@@ -124,13 +124,13 @@ STATIC mp_obj_t array_construct(char typecode, mp_obj_t initializer) {
// construct array from raw bytes
// we round-down the len to make it a multiple of sz (CPython raises error)
size_t
sz
=
mp_binary_get_size
(
'@'
,
typecode
,
NULL
);
mp_uint
_t
len
=
bufinfo
.
len
/
sz
;
size
_t
len
=
bufinfo
.
len
/
sz
;
mp_obj_array_t
*
o
=
array_new
(
typecode
,
len
);
memcpy
(
o
->
items
,
bufinfo
.
buf
,
len
*
sz
);
return
MP_OBJ_FROM_PTR
(
o
);
}
mp_uint
_t
len
;
size
_t
len
;
// Try to create array of exact len if initializer len is known
mp_obj_t
len_in
=
mp_obj_len_maybe
(
initializer
);
if
(
len_in
==
MP_OBJ_NULL
)
{
...
...
@@ -143,7 +143,7 @@ STATIC mp_obj_t array_construct(char typecode, mp_obj_t initializer) {
mp_obj_t
iterable
=
mp_getiter
(
initializer
);
mp_obj_t
item
;
mp_uint
_t
i
=
0
;
size
_t
i
=
0
;
while
((
item
=
mp_iternext
(
iterable
))
!=
MP_OBJ_STOP_ITERATION
)
{
if
(
len
==
0
)
{
array_append
(
MP_OBJ_FROM_PTR
(
array
),
item
);
...
...
@@ -198,7 +198,7 @@ STATIC mp_obj_t bytearray_make_new(const mp_obj_type_t *type_in, size_t n_args,
#if MICROPY_PY_BUILTINS_MEMORYVIEW
mp_obj_t
mp_obj_new_memoryview
(
byte
typecode
,
mp_uint
_t
nitems
,
void
*
items
)
{
mp_obj_t
mp_obj_new_memoryview
(
byte
typecode
,
size
_t
nitems
,
void
*
items
)
{
mp_obj_array_t
*
self
=
m_new_obj
(
mp_obj_array_t
);
self
->
base
.
type
=
&
mp_type_memoryview
;
self
->
typecode
=
typecode
;
...
...
@@ -254,7 +254,7 @@ STATIC mp_obj_t array_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in)
size_t
sz
=
mp_binary_get_size
(
'@'
,
lhs_bufinfo
.
typecode
,
NULL
);
// convert byte count to element count (in case rhs is not multiple of sz)
mp_uint
_t
rhs_len
=
rhs_bufinfo
.
len
/
sz
;
size
_t
rhs_len
=
rhs_bufinfo
.
len
/
sz
;
// note: lhs->len is element count of lhs, lhs_bufinfo.len is byte count
mp_obj_array_t
*
res
=
array_new
(
lhs_bufinfo
.
typecode
,
lhs
->
len
+
rhs_len
);
...
...
@@ -345,7 +345,7 @@ STATIC mp_obj_t array_extend(mp_obj_t self_in, mp_obj_t arg_in) {
size_t
sz
=
mp_binary_get_size
(
'@'
,
self
->
typecode
,
NULL
);
// convert byte count to element count
mp_uint
_t
len
=
arg_bufinfo
.
len
/
sz
;
size
_t
len
=
arg_bufinfo
.
len
/
sz
;
// make sure we have enough room to extend
// TODO: alloc policy; at the moment we go conservative
...
...
@@ -384,7 +384,7 @@ STATIC mp_obj_t array_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value
if
(
value
!=
MP_OBJ_SENTINEL
)
{
#if MICROPY_PY_ARRAY_SLICE_ASSIGN
// Assign
mp_uint
_t
src_len
;
size
_t
src_len
;
void
*
src_items
;
size_t
item_sz
=
mp_binary_get_size
(
'@'
,
o
->
typecode
&
TYPECODE_MASK
,
NULL
);
if
(
MP_OBJ_IS_OBJ
(
value
)
&&
((
mp_obj_base_t
*
)
MP_OBJ_TO_PTR
(
value
))
->
type
->
subscr
==
array_subscr
)
{
...
...
@@ -501,7 +501,7 @@ STATIC mp_int_t array_get_buffer(mp_obj_t o_in, mp_buffer_info_t *bufinfo, mp_ui
// read-only memoryview
return
1
;
}
bufinfo
->
buf
=
(
uint8_t
*
)
bufinfo
->
buf
+
(
mp_uint
_t
)
o
->
free
*
sz
;
bufinfo
->
buf
=
(
uint8_t
*
)
bufinfo
->
buf
+
(
size
_t
)
o
->
free
*
sz
;
}
#else
(
void
)
flags
;
...
...
@@ -562,20 +562,20 @@ const mp_obj_type_t mp_type_memoryview = {
#endif
/* unused
mp_uint
_t mp_obj_array_len(mp_obj_t self_in) {
size
_t mp_obj_array_len(mp_obj_t self_in) {
return ((mp_obj_array_t *)self_in)->len;
}
*/
#if MICROPY_PY_BUILTINS_BYTEARRAY
mp_obj_t
mp_obj_new_bytearray
(
mp_uint
_t
n
,
void
*
items
)
{
mp_obj_t
mp_obj_new_bytearray
(
size
_t
n
,
void
*
items
)
{
mp_obj_array_t
*
o
=
array_new
(
BYTEARRAY_TYPECODE
,
n
);
memcpy
(
o
->
items
,
items
,
n
);
return
MP_OBJ_FROM_PTR
(
o
);
}
// Create bytearray which references specified memory area
mp_obj_t
mp_obj_new_bytearray_by_ref
(
mp_uint
_t
n
,
void
*
items
)
{
mp_obj_t
mp_obj_new_bytearray_by_ref
(
size
_t
n
,
void
*
items
)
{
mp_obj_array_t
*
o
=
m_new_obj
(
mp_obj_array_t
);
o
->
base
.
type
=
&
mp_type_bytearray
;
o
->
typecode
=
BYTEARRAY_TYPECODE
;
...
...
@@ -592,8 +592,8 @@ mp_obj_t mp_obj_new_bytearray_by_ref(mp_uint_t n, void *items) {
typedef
struct
_mp_obj_array_it_t
{
mp_obj_base_t
base
;
mp_obj_array_t
*
array
;
mp_uint
_t
offset
;
mp_uint
_t
cur
;
size
_t
offset
;
size
_t
cur
;
}
mp_obj_array_it_t
;
STATIC
mp_obj_t
array_it_iternext
(
mp_obj_t
self_in
)
{
...
...
py/objarray.h
View file @
ccc52542
...
...
@@ -32,11 +32,11 @@
typedef
struct
_mp_obj_array_t
{
mp_obj_base_t
base
;
mp_uint
_t
typecode
:
8
;
size
_t
typecode
:
8
;
// free is number of unused elements after len used elements
// alloc size = len + free
mp_uint
_t
free
:
(
8
*
sizeof
(
mp_uint
_t
)
-
8
);
mp_uint
_t
len
;
// in elements
size
_t
free
:
(
8
*
sizeof
(
size
_t
)
-
8
);
size
_t
len
;
// in elements
void
*
items
;
}
mp_obj_array_t
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a 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