Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
U
uPython-mirror
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
TASTE
uPython-mirror
Commits
66d0c105
Commit
66d0c105
authored
Jan 03, 2016
by
Dave Hylands
Committed by
Paul Sokolovsky
Jan 10, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
extmod: Fix uctypes size calculation for bitfields
parent
8175877a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
12 additions
and
1 deletion
+12
-1
extmod/moductypes.c
extmod/moductypes.c
+3
-0
tests/extmod/uctypes_sizeof.py
tests/extmod/uctypes_sizeof.py
+8
-1
tests/extmod/uctypes_sizeof.py.exp
tests/extmod/uctypes_sizeof.py.exp
+1
-0
No files found.
extmod/moductypes.c
View file @
66d0c105
...
...
@@ -230,6 +230,9 @@ STATIC mp_uint_t uctypes_struct_size(mp_obj_t desc_in, int layout_type, mp_uint_
mp_uint_t
offset
=
MP_OBJ_SMALL_INT_VALUE
(
v
);
mp_uint_t
val_type
=
GET_TYPE
(
offset
,
VAL_TYPE_BITS
);
offset
&=
VALUE_MASK
(
VAL_TYPE_BITS
);
if
(
val_type
>=
BFUINT8
&&
val_type
<=
BFINT32
)
{
offset
&=
(
1
<<
OFFSET_BITS
)
-
1
;
}
mp_uint_t
s
=
uctypes_struct_scalar_size
(
val_type
);
if
(
s
>
*
max_field_size
)
{
*
max_field_size
=
s
;
...
...
tests/extmod/uctypes_sizeof.py
View file @
66d0c105
...
...
@@ -6,7 +6,11 @@ desc = {
# arr2 is array at offset 0, size 2, of structures defined recursively
"arr2"
:
(
uctypes
.
ARRAY
|
0
,
2
,
{
"b"
:
uctypes
.
UINT8
|
0
}),
"arr3"
:
(
uctypes
.
ARRAY
|
2
,
uctypes
.
UINT16
|
2
),
"arr4"
:
(
uctypes
.
ARRAY
|
0
,
2
,
{
"b"
:
uctypes
.
UINT8
|
0
,
"w"
:
uctypes
.
UINT16
|
1
})
"arr4"
:
(
uctypes
.
ARRAY
|
0
,
2
,
{
"b"
:
uctypes
.
UINT8
|
0
,
"w"
:
uctypes
.
UINT16
|
1
}),
"sub"
:
(
0
,
{
'b1'
:
uctypes
.
BFUINT8
|
0
|
4
<<
uctypes
.
BF_POS
|
4
<<
uctypes
.
BF_LEN
,
'b2'
:
uctypes
.
BFUINT8
|
0
|
0
<<
uctypes
.
BF_POS
|
4
<<
uctypes
.
BF_LEN
,
}),
}
data
=
bytearray
(
b"01234567"
)
...
...
@@ -29,3 +33,6 @@ except TypeError:
print
(
uctypes
.
sizeof
(
S
.
arr4
))
assert
uctypes
.
sizeof
(
S
.
arr4
)
==
6
print
(
uctypes
.
sizeof
(
S
.
sub
))
assert
uctypes
.
sizeof
(
S
.
sub
)
==
1
tests/extmod/uctypes_sizeof.py.exp
View file @
66d0c105
...
...
@@ -3,3 +3,4 @@
4
TypeError
6
1
Write
Preview
Markdown
is supported
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