Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
c64af8fa
Commit
c64af8fa
authored
Sep 25, 2019
by
Vinay Sajip
Committed by
GitHub
Sep 25, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changed conditions for ctypes array-in-struct handling. (GH-16381)
parent
17deb168
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
5 additions
and
8 deletions
+5
-8
Lib/ctypes/test/test_structures.py
Lib/ctypes/test/test_structures.py
+1
-1
Modules/_ctypes/stgdict.c
Modules/_ctypes/stgdict.c
+4
-7
No files found.
Lib/ctypes/test/test_structures.py
View file @
c64af8fa
...
...
@@ -480,7 +480,7 @@ class StructureTestCase(unittest.TestCase):
self
.
assertEqual
(
s
.
first
,
got
.
first
)
self
.
assertEqual
(
s
.
second
,
got
.
second
)
@
unittest
.
skipIf
(
MACHINE
in
(
'armv7l'
,
'ppc64'
),
@
unittest
.
skipIf
(
MACHINE
.
startswith
((
'arm'
,
'ppc'
)
),
'Test temporarily disabled on this architecture'
)
def
test_array_in_struct
(
self
):
# See bpo-22273
...
...
Modules/_ctypes/stgdict.c
View file @
c64af8fa
...
...
@@ -350,9 +350,7 @@ PyCStructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct
int
pack
;
Py_ssize_t
ffi_ofs
;
int
big_endian
;
#if defined(X86_64)
int
arrays_seen
=
0
;
#endif
/* HACK Alert: I cannot be bothered to fix ctypes.com, so there has to
be a way to use the old, broken semantics: _fields_ are not extended
...
...
@@ -504,10 +502,8 @@ PyCStructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct
Py_XDECREF
(
pair
);
return
-
1
;
}
#if defined(X86_64)
if
(
PyCArrayTypeObject_Check
(
desc
))
arrays_seen
=
1
;
#endif
dict
=
PyType_stgdict
(
desc
);
if
(
dict
==
NULL
)
{
Py_DECREF
(
pair
);
...
...
@@ -648,8 +644,6 @@ PyCStructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct
stgdict
->
align
=
total_align
;
stgdict
->
length
=
len
;
/* ADD ffi_ofs? */
#if defined(X86_64)
#define MAX_ELEMENTS 16
if
(
arrays_seen
&&
(
size
<=
MAX_ELEMENTS
))
{
...
...
@@ -669,6 +663,10 @@ PyCStructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct
* accurate set, to allow libffi to marshal them into registers
* correctly. It means one more loop over the fields, but if we got
* here, the structure is small, so there aren't too many of those.
*
* Although the passing in registers is specific to 64-bit Linux, the
* array-in-struct vs. pointer problem is general. But we restrict the
* type transformation to small structs nonetheless.
*/
ffi_type
*
actual_types
[
MAX_ELEMENTS
+
1
];
int
actual_type_index
=
0
;
...
...
@@ -746,7 +744,6 @@ PyCStructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct
memcpy
(
&
stgdict
->
ffi_type_pointer
.
elements
[
ffi_ofs
],
actual_types
,
actual_type_index
*
sizeof
(
ffi_type
*
));
}
#endif
/* We did check that this flag was NOT set above, it must not
have been set until now. */
...
...
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