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
f5dd6f7f
Commit
f5dd6f7f
authored
May 10, 2015
by
Kaspar Schleiser
Committed by
Damien George
May 17, 2015
Browse files
py/binary: Make return type of mp_binary_get_size size_t instead of int.
Fixes sign-compare warning.
parent
b5cef5c7
Changes
4
Hide whitespace changes
Inline
Side-by-side
py/binary.c
View file @
f5dd6f7f
...
...
@@ -40,8 +40,8 @@
#define alignof(type) offsetof(struct { char c; type t; }, t)
#endif
in
t
mp_binary_get_size
(
char
struct_type
,
char
val_type
,
mp_uint_t
*
palign
)
{
in
t
size
=
0
;
size_
t
mp_binary_get_size
(
char
struct_type
,
char
val_type
,
mp_uint_t
*
palign
)
{
size_
t
size
=
0
;
int
align
=
1
;
switch
(
struct_type
)
{
case
'<'
:
case
'>'
:
...
...
@@ -179,7 +179,7 @@ mp_obj_t mp_binary_get_val(char struct_type, char val_type, byte **ptr) {
byte
*
p
=
*
ptr
;
mp_uint_t
align
;
in
t
size
=
mp_binary_get_size
(
struct_type
,
val_type
,
&
align
);
size_
t
size
=
mp_binary_get_size
(
struct_type
,
val_type
,
&
align
);
if
(
struct_type
==
'@'
)
{
// Make pointer aligned
p
=
(
byte
*
)(((
mp_uint_t
)
p
+
align
-
1
)
&
~
((
mp_uint_t
)
align
-
1
));
...
...
@@ -244,7 +244,7 @@ void mp_binary_set_val(char struct_type, char val_type, mp_obj_t val_in, byte **
byte
*
p
=
*
ptr
;
mp_uint_t
align
;
in
t
size
=
mp_binary_get_size
(
struct_type
,
val_type
,
&
align
);
size_
t
size
=
mp_binary_get_size
(
struct_type
,
val_type
,
&
align
);
if
(
struct_type
==
'@'
)
{
// Make pointer aligned
p
=
(
byte
*
)(((
mp_uint_t
)
p
+
align
-
1
)
&
~
((
mp_uint_t
)
align
-
1
));
...
...
py/binary.h
View file @
f5dd6f7f
...
...
@@ -32,7 +32,7 @@
// (underlyingly they're same).
#define BYTEARRAY_TYPECODE 0
in
t
mp_binary_get_size
(
char
struct_type
,
char
val_type
,
mp_uint_t
*
palign
);
size_
t
mp_binary_get_size
(
char
struct_type
,
char
val_type
,
mp_uint_t
*
palign
);
mp_obj_t
mp_binary_get_val_array
(
char
typecode
,
void
*
p
,
mp_uint_t
index
);
void
mp_binary_set_val_array
(
char
typecode
,
void
*
p
,
mp_uint_t
index
,
mp_obj_t
val_in
);
void
mp_binary_set_val_array_from_int
(
char
typecode
,
void
*
p
,
mp_uint_t
index
,
mp_int_t
val
);
...
...
py/objarray.c
View file @
f5dd6f7f
...
...
@@ -102,7 +102,7 @@ STATIC void array_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t
#if MICROPY_PY_BUILTINS_BYTEARRAY || MICROPY_PY_ARRAY
STATIC
mp_obj_array_t
*
array_new
(
char
typecode
,
mp_uint_t
n
)
{
int
typecode_size
=
mp_binary_get_size
(
'@'
,
typecode
,
NULL
);
if
(
typecode_size
<
=
0
)
{
if
(
typecode_size
=
=
0
)
{
nlr_raise
(
mp_obj_new_exception_msg
(
&
mp_type_ValueError
,
"bad typecode"
));
}
mp_obj_array_t
*
o
=
m_new_obj
(
mp_obj_array_t
);
...
...
@@ -134,7 +134,7 @@ STATIC mp_obj_t array_construct(char typecode, mp_obj_t initializer) {
&&
mp_get_buffer
(
initializer
,
&
bufinfo
,
MP_BUFFER_READ
))
{
// construct array from raw bytes
// we round-down the len to make it a multiple of sz (CPython raises error)
in
t
sz
=
mp_binary_get_size
(
'@'
,
typecode
,
NULL
);
size_
t
sz
=
mp_binary_get_size
(
'@'
,
typecode
,
NULL
);
mp_uint_t
len
=
bufinfo
.
len
/
sz
;
mp_obj_array_t
*
o
=
array_new
(
typecode
,
len
);
memcpy
(
o
->
items
,
bufinfo
.
buf
,
len
*
sz
);
...
...
@@ -262,7 +262,7 @@ STATIC mp_obj_t array_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in)
array_get_buffer
(
lhs_in
,
&
lhs_bufinfo
,
MP_BUFFER_READ
);
mp_get_buffer_raise
(
rhs_in
,
&
rhs_bufinfo
,
MP_BUFFER_READ
);
in
t
sz
=
mp_binary_get_size
(
'@'
,
lhs_bufinfo
.
typecode
,
NULL
);
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
;
...
...
@@ -305,7 +305,7 @@ STATIC mp_obj_t array_append(mp_obj_t self_in, mp_obj_t arg) {
mp_obj_array_t
*
self
=
self_in
;
if
(
self
->
free
==
0
)
{
in
t
item_sz
=
mp_binary_get_size
(
'@'
,
self
->
typecode
,
NULL
);
size_
t
item_sz
=
mp_binary_get_size
(
'@'
,
self
->
typecode
,
NULL
);
// TODO: alloc policy
self
->
free
=
8
;
self
->
items
=
m_renew
(
byte
,
self
->
items
,
item_sz
*
self
->
len
,
item_sz
*
(
self
->
len
+
self
->
free
));
...
...
@@ -326,7 +326,7 @@ STATIC mp_obj_t array_extend(mp_obj_t self_in, mp_obj_t arg_in) {
mp_buffer_info_t
arg_bufinfo
;
mp_get_buffer_raise
(
arg_in
,
&
arg_bufinfo
,
MP_BUFFER_READ
);
in
t
sz
=
mp_binary_get_size
(
'@'
,
self
->
typecode
,
NULL
);
size_
t
sz
=
mp_binary_get_size
(
'@'
,
self
->
typecode
,
NULL
);
// convert byte count to element count
mp_uint_t
len
=
arg_bufinfo
.
len
/
sz
;
...
...
@@ -371,7 +371,7 @@ STATIC mp_obj_t array_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value
// Assign
mp_uint_t
src_len
;
void
*
src_items
;
in
t
item_sz
=
mp_binary_get_size
(
'@'
,
o
->
typecode
,
NULL
);
size_
t
item_sz
=
mp_binary_get_size
(
'@'
,
o
->
typecode
,
NULL
);
if
(
MP_OBJ_IS_TYPE
(
value
,
&
mp_type_array
)
||
MP_OBJ_IS_TYPE
(
value
,
&
mp_type_bytearray
))
{
mp_obj_array_t
*
src_slice
=
value
;
if
(
item_sz
!=
mp_binary_get_size
(
'@'
,
src_slice
->
typecode
,
NULL
))
{
...
...
@@ -418,7 +418,7 @@ STATIC mp_obj_t array_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value
}
mp_obj_array_t
*
res
;
in
t
sz
=
mp_binary_get_size
(
'@'
,
o
->
typecode
&
TYPECODE_MASK
,
NULL
);
size_
t
sz
=
mp_binary_get_size
(
'@'
,
o
->
typecode
&
TYPECODE_MASK
,
NULL
);
assert
(
sz
>
0
);
if
(
0
)
{
// dummy
...
...
@@ -460,7 +460,7 @@ STATIC mp_obj_t array_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value
STATIC
mp_int_t
array_get_buffer
(
mp_obj_t
o_in
,
mp_buffer_info_t
*
bufinfo
,
mp_uint_t
flags
)
{
mp_obj_array_t
*
o
=
o_in
;
in
t
sz
=
mp_binary_get_size
(
'@'
,
o
->
typecode
&
TYPECODE_MASK
,
NULL
);
size_
t
sz
=
mp_binary_get_size
(
'@'
,
o
->
typecode
&
TYPECODE_MASK
,
NULL
);
bufinfo
->
buf
=
o
->
items
;
bufinfo
->
len
=
o
->
len
*
sz
;
bufinfo
->
typecode
=
o
->
typecode
&
TYPECODE_MASK
;
...
...
stmhal/adc.c
View file @
f5dd6f7f
...
...
@@ -219,7 +219,7 @@ STATIC mp_obj_t adc_read_timed(mp_obj_t self_in, mp_obj_t buf_in, mp_obj_t freq_
mp_buffer_info_t
bufinfo
;
mp_get_buffer_raise
(
buf_in
,
&
bufinfo
,
MP_BUFFER_WRITE
);
in
t
typesize
=
mp_binary_get_size
(
'@'
,
bufinfo
.
typecode
,
NULL
);
size_
t
typesize
=
mp_binary_get_size
(
'@'
,
bufinfo
.
typecode
,
NULL
);
// Init TIM6 at the required frequency (in Hz)
timer_tim6_init
(
mp_obj_get_int
(
freq_in
));
...
...
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