mirror of
https://github.com/python/cpython.git
synced 2025-08-03 00:23:06 +00:00
support pep 3118 format strings for ctypes objects with nontrivial shapes (closes #10744)
Patch by Matti Picus.
This commit is contained in:
parent
5d52022406
commit
5eb6b39210
5 changed files with 74 additions and 15 deletions
|
@ -96,6 +96,9 @@ class EmptyStruct(Structure):
|
|||
class aUnion(Union):
|
||||
_fields_ = [("a", c_int)]
|
||||
|
||||
class StructWithArrays(Structure):
|
||||
_fields_ = [("x", c_long * 3 * 2), ("y", Point * 4)]
|
||||
|
||||
class Incomplete(Structure):
|
||||
pass
|
||||
|
||||
|
@ -145,10 +148,10 @@ native_types = [
|
|||
|
||||
## arrays and pointers
|
||||
|
||||
(c_double * 4, "(4)<d", (4,), c_double),
|
||||
(c_float * 4 * 3 * 2, "(2,3,4)<f", (2,3,4), c_float),
|
||||
(POINTER(c_short) * 2, "(2)&<h", (2,), POINTER(c_short)),
|
||||
(POINTER(c_short) * 2 * 3, "(3,2)&<h", (3,2,), POINTER(c_short)),
|
||||
(c_double * 4, "<d", (4,), c_double),
|
||||
(c_float * 4 * 3 * 2, "<f", (2,3,4), c_float),
|
||||
(POINTER(c_short) * 2, "&<h", (2,), POINTER(c_short)),
|
||||
(POINTER(c_short) * 2 * 3, "&<h", (3,2,), POINTER(c_short)),
|
||||
(POINTER(c_short * 2), "&(2)<h", (), POINTER(c_short)),
|
||||
|
||||
## structures and unions
|
||||
|
@ -160,6 +163,9 @@ native_types = [
|
|||
(EmptyStruct, "T{}", (), EmptyStruct),
|
||||
# the pep does't support unions
|
||||
(aUnion, "B", (), aUnion),
|
||||
# structure with sub-arrays
|
||||
(StructWithArrays, "T{(2,3)<l:x:(4)T{<l:x:<l:y:}:y:}", (), StructWithArrays),
|
||||
(StructWithArrays * 3, "T{(2,3)<l:x:(4)T{<l:x:<l:y:}:y:}", (3,), StructWithArrays),
|
||||
|
||||
## pointer to incomplete structure
|
||||
(Incomplete, "B", (), Incomplete),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue