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
81794fcd
Commit
81794fcd
authored
Sep 01, 2015
by
Damien George
Browse files
py/binary: Add support for array('q') and array('Q').
parent
22602cc3
Changes
2
Hide whitespace changes
Inline
Side-by-side
py/binary.c
View file @
81794fcd
...
@@ -130,12 +130,12 @@ mp_obj_t mp_binary_get_val_array(char typecode, void *p, mp_uint_t index) {
...
@@ -130,12 +130,12 @@ mp_obj_t mp_binary_get_val_array(char typecode, void *p, mp_uint_t index) {
return
mp_obj_new_int
(((
long
*
)
p
)[
index
]);
return
mp_obj_new_int
(((
long
*
)
p
)[
index
]);
case
'L'
:
case
'L'
:
return
mp_obj_new_int_from_uint
(((
unsigned
long
*
)
p
)[
index
]);
return
mp_obj_new_int_from_uint
(((
unsigned
long
*
)
p
)[
index
]);
#if MICROPY_LONGINT_IMPL != MICROPY_LONGINT_IMPL_NONE
#if MICROPY_LONGINT_IMPL != MICROPY_LONGINT_IMPL_NONE
case
'q'
:
case
'q'
:
case
'Q'
:
// TODO: Explode API more to cover signedness
return
mp_obj_new_int_from_ll
(((
long
long
*
)
p
)[
index
]);
return
mp_obj_new_int_from_ll
(((
long
long
*
)
p
)[
index
]);
#endif
case
'Q'
:
return
mp_obj_new_int_from_ull
(((
unsigned
long
long
*
)
p
)[
index
]);
#endif
#if MICROPY_PY_BUILTINS_FLOAT
#if MICROPY_PY_BUILTINS_FLOAT
case
'f'
:
case
'f'
:
return
mp_obj_new_float
(((
float
*
)
p
)[
index
]);
return
mp_obj_new_float
(((
float
*
)
p
)[
index
]);
...
@@ -316,6 +316,13 @@ void mp_binary_set_val_array(char typecode, void *p, mp_uint_t index, mp_obj_t v
...
@@ -316,6 +316,13 @@ void mp_binary_set_val_array(char typecode, void *p, mp_uint_t index, mp_obj_t v
((
mp_obj_t
*
)
p
)[
index
]
=
val_in
;
((
mp_obj_t
*
)
p
)[
index
]
=
val_in
;
break
;
break
;
default:
default:
#if MICROPY_LONGINT_IMPL != MICROPY_LONGINT_IMPL_NONE
if
((
typecode
|
0x20
)
==
'q'
&&
MP_OBJ_IS_TYPE
(
val_in
,
&
mp_type_int
))
{
mp_obj_int_to_bytes_impl
(
val_in
,
MP_ENDIANNESS_BIG
,
sizeof
(
long
long
),
(
byte
*
)
&
((
long
long
*
)
p
)[
index
]);
return
;
}
#endif
mp_binary_set_val_array_from_int
(
typecode
,
p
,
index
,
mp_obj_get_int
(
val_in
));
mp_binary_set_val_array_from_int
(
typecode
,
p
,
index
,
mp_obj_get_int
(
val_in
));
}
}
}
}
...
@@ -347,13 +354,13 @@ void mp_binary_set_val_array_from_int(char typecode, void *p, mp_uint_t index, m
...
@@ -347,13 +354,13 @@ void mp_binary_set_val_array_from_int(char typecode, void *p, mp_uint_t index, m
case
'L'
:
case
'L'
:
((
unsigned
long
*
)
p
)[
index
]
=
val
;
((
unsigned
long
*
)
p
)[
index
]
=
val
;
break
;
break
;
#if MICROPY_LONGINT_IMPL != MICROPY_LONGINT_IMPL_NONE
#if MICROPY_LONGINT_IMPL != MICROPY_LONGINT_IMPL_NONE
case
'q'
:
case
'q'
:
case
'Q'
:
assert
(
0
);
((
long
long
*
)
p
)[
index
]
=
val
;
((
long
long
*
)
p
)[
index
]
=
val
;
case
'Q'
:
((
unsigned
long
long
*
)
p
)[
index
]
=
val
;
break
;
break
;
#endif
#endif
#if MICROPY_PY_BUILTINS_FLOAT
#if MICROPY_PY_BUILTINS_FLOAT
case
'f'
:
case
'f'
:
((
float
*
)
p
)[
index
]
=
val
;
((
float
*
)
p
)[
index
]
=
val
;
...
...
tests/basics/array_q.py
0 → 100644
View file @
81794fcd
# test array('q') and array('Q')
from
array
import
array
print
(
array
(
'q'
))
print
(
array
(
'Q'
))
print
(
array
(
'q'
,
[
0
]))
print
(
array
(
'Q'
,
[
0
]))
print
(
array
(
'q'
,
[
-
2
**
63
,
-
1
,
0
,
1
,
2
,
2
**
63
-
1
]))
print
(
array
(
'Q'
,
[
0
,
1
,
2
,
2
**
64
-
1
]))
print
(
bytes
(
array
(
'q'
,
[
-
1
])))
print
(
bytes
(
array
(
'Q'
,
[
2
**
64
-
1
])))
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