@@ -397,15 +397,15 @@ as calling functions with a fixed number of parameters. On some platforms, and i
397
397
particular ARM64 for Apple Platforms, the calling convention for variadic functions
398
398
is different than that for regular functions.
399
399
400
- On those platforms it is required to specify the :attr: `~_FuncPtr .argtypes `
400
+ On those platforms it is required to specify the :attr: `~_CFuncPtr .argtypes `
401
401
attribute for the regular, non-variadic, function arguments:
402
402
403
403
.. code-block :: python3
404
404
405
405
libc.printf.argtypes = [ctypes.c_char_p]
406
406
407
407
Because specifying the attribute does not inhibit portability it is advised to always
408
- specify :attr: `~_FuncPtr .argtypes ` for all variadic functions.
408
+ specify :attr: `~_CFuncPtr .argtypes ` for all variadic functions.
409
409
410
410
411
411
.. _ctypes-calling-functions-with-own-custom-data-types :
@@ -440,9 +440,9 @@ Specifying the required argument types (function prototypes)
440
440
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
441
441
442
442
It is possible to specify the required argument types of functions exported from
443
- DLLs by setting the :attr: `~_FuncPtr .argtypes ` attribute.
443
+ DLLs by setting the :attr: `~_CFuncPtr .argtypes ` attribute.
444
444
445
- :attr: `~_FuncPtr .argtypes ` must be a sequence of C data types (the :func: `!printf ` function is
445
+ :attr: `~_CFuncPtr .argtypes ` must be a sequence of C data types (the :func: `!printf ` function is
446
446
probably not a good example here, because it takes a variable number and
447
447
different types of parameters depending on the format string, on the other hand
448
448
this is quite handy to experiment with this feature)::
@@ -467,7 +467,7 @@ prototype for a C function), and tries to convert the arguments to valid types::
467
467
468
468
If you have defined your own classes which you pass to function calls, you have
469
469
to implement a :meth: `~_CData.from_param ` class method for them to be able to use them
470
- in the :attr: `~_FuncPtr .argtypes ` sequence. The :meth: `~_CData.from_param ` class method receives
470
+ in the :attr: `~_CFuncPtr .argtypes ` sequence. The :meth: `~_CData.from_param ` class method receives
471
471
the Python object passed to the function call, it should do a typecheck or
472
472
whatever is needed to make sure this object is acceptable, and then return the
473
473
object itself, its :attr: `!_as_parameter_ ` attribute, or whatever you want to
@@ -490,7 +490,7 @@ Return types
490
490
491
491
492
492
By default functions are assumed to return the C :c:expr: `int ` type. Other
493
- return types can be specified by setting the :attr: `~_FuncPtr .restype ` attribute of the
493
+ return types can be specified by setting the :attr: `~_CFuncPtr .restype ` attribute of the
494
494
function object.
495
495
496
496
The C prototype of :c:func: `time ` is ``time_t time(time_t *) ``. Because :c:type: `time_t `
@@ -499,7 +499,7 @@ specify the :attr:`!restype` attribute::
499
499
500
500
>>> libc.time.restype = c_time_t
501
501
502
- The argument types can be specified using :attr: `~_FuncPtr .argtypes `::
502
+ The argument types can be specified using :attr: `~_CFuncPtr .argtypes `::
503
503
504
504
>>> libc.time.argtypes = (POINTER(c_time_t),)
505
505
@@ -522,7 +522,7 @@ a string pointer and a char, and returns a pointer to a string::
522
522
>>>
523
523
524
524
If you want to avoid the :func: `ord("x") <ord> ` calls above, you can set the
525
- :attr: `~_FuncPtr .argtypes ` attribute, and the second argument will be converted from a
525
+ :attr: `~_CFuncPtr .argtypes ` attribute, and the second argument will be converted from a
526
526
single character Python bytes object into a C char:
527
527
528
528
.. doctest ::
@@ -541,7 +541,7 @@ single character Python bytes object into a C char:
541
541
>>>
542
542
543
543
You can also use a callable Python object (a function or a class for example) as
544
- the :attr: `~_FuncPtr .restype ` attribute, if the foreign function returns an integer. The
544
+ the :attr: `~_CFuncPtr .restype ` attribute, if the foreign function returns an integer. The
545
545
callable will be called with the *integer * the C function returns, and the
546
546
result of this call will be used as the result of your function call. This is
547
547
useful to check for error return values and automatically raise an exception::
@@ -569,7 +569,7 @@ get the string representation of an error code, and *returns* an exception.
569
569
:func: `GetLastError ` to retrieve it.
570
570
571
571
Please note that a much more powerful error checking mechanism is available
572
- through the :attr: `~_FuncPtr .errcheck ` attribute;
572
+ through the :attr: `~_CFuncPtr .errcheck ` attribute;
573
573
see the reference manual for details.
574
574
575
575
@@ -877,7 +877,7 @@ Type conversions
877
877
^^^^^^^^^^^^^^^^
878
878
879
879
Usually, ctypes does strict type checking. This means, if you have
880
- ``POINTER(c_int) `` in the :attr: `~_FuncPtr .argtypes ` list of a function or as the type of
880
+ ``POINTER(c_int) `` in the :attr: `~_CFuncPtr .argtypes ` list of a function or as the type of
881
881
a member field in a structure definition, only instances of exactly the same
882
882
type are accepted. There are some exceptions to this rule, where ctypes accepts
883
883
other objects. For example, you can pass compatible array instances instead of
@@ -898,7 +898,7 @@ pointer types. So, for ``POINTER(c_int)``, ctypes accepts an array of c_int::
898
898
>>>
899
899
900
900
In addition, if a function argument is explicitly declared to be a pointer type
901
- (such as ``POINTER(c_int) ``) in :attr: `~_FuncPtr .argtypes `, an object of the pointed
901
+ (such as ``POINTER(c_int) ``) in :attr: `~_CFuncPtr .argtypes `, an object of the pointed
902
902
type (``c_int `` in this case) can be passed to the function. ctypes will apply
903
903
the required :func: `byref ` conversion in this case automatically.
904
904
@@ -1627,10 +1627,20 @@ As explained in the previous section, foreign functions can be accessed as
1627
1627
attributes of loaded shared libraries. The function objects created in this way
1628
1628
by default accept any number of arguments, accept any ctypes data instances as
1629
1629
arguments, and return the default result type specified by the library loader.
1630
- They are instances of a private class:
1631
1630
1631
+ They are instances of a private local class :class: `!_FuncPtr ` (not exposed
1632
+ in :mod: `!ctypes `) which inherits from the private :class: `_CFuncPtr ` class:
1632
1633
1633
- .. class :: _FuncPtr
1634
+ .. doctest ::
1635
+
1636
+ >>> import ctypes
1637
+ >>> lib = ctypes.CDLL(None )
1638
+ >>> issubclass (lib._FuncPtr, ctypes._CFuncPtr)
1639
+ True
1640
+ >>> lib._FuncPtr is ctypes._CFuncPtr
1641
+ False
1642
+
1643
+ .. class :: _CFuncPtr
1634
1644
1635
1645
Base class for C callable foreign functions.
1636
1646
@@ -1796,7 +1806,7 @@ different ways, depending on the type and number of the parameters in the call:
1796
1806
The optional *paramflags * parameter creates foreign function wrappers with much
1797
1807
more functionality than the features described above.
1798
1808
1799
- *paramflags * must be a tuple of the same length as :attr: `~_FuncPtr .argtypes `.
1809
+ *paramflags * must be a tuple of the same length as :attr: `~_CFuncPtr .argtypes `.
1800
1810
1801
1811
Each item in this tuple contains further information about a parameter, it must
1802
1812
be a tuple containing one, two, or three items.
@@ -1867,7 +1877,7 @@ value if there is a single one, or a tuple containing the output parameter
1867
1877
values when there are more than one, so the GetWindowRect function now returns a
1868
1878
RECT instance, when called.
1869
1879
1870
- Output parameters can be combined with the :attr: `~_FuncPtr .errcheck ` protocol to do
1880
+ Output parameters can be combined with the :attr: `~_CFuncPtr .errcheck ` protocol to do
1871
1881
further output processing and error checking. The win32 ``GetWindowRect `` api
1872
1882
function returns a ``BOOL `` to signal success or failure, so this function could
1873
1883
do the error checking, and raises an exception when the api call failed::
@@ -1880,7 +1890,7 @@ do the error checking, and raises an exception when the api call failed::
1880
1890
>>> GetWindowRect.errcheck = errcheck
1881
1891
>>>
1882
1892
1883
- If the :attr: `~_FuncPtr .errcheck ` function returns the argument tuple it receives
1893
+ If the :attr: `~_CFuncPtr .errcheck ` function returns the argument tuple it receives
1884
1894
unchanged, :mod: `ctypes ` continues the normal processing it does on the output
1885
1895
parameters. If you want to return a tuple of window coordinates instead of a
1886
1896
``RECT `` instance, you can retrieve the fields in the function and return them
@@ -2180,7 +2190,7 @@ Data types
2180
2190
2181
2191
This method adapts *obj * to a ctypes type. It is called with the actual
2182
2192
object used in a foreign function call when the type is present in the
2183
- foreign function's :attr: `~_FuncPtr .argtypes ` tuple;
2193
+ foreign function's :attr: `~_CFuncPtr .argtypes ` tuple;
2184
2194
it must return an object that can be used as a function call parameter.
2185
2195
2186
2196
All ctypes data types have a default implementation of this classmethod
@@ -2246,7 +2256,7 @@ Fundamental data types
2246
2256
Fundamental data types, when returned as foreign function call results, or, for
2247
2257
example, by retrieving structure field members or array items, are transparently
2248
2258
converted to native Python types. In other words, if a foreign function has a
2249
- :attr: `~_FuncPtr .restype ` of :class: `c_char_p `, you will always receive a Python bytes
2259
+ :attr: `~_CFuncPtr .restype ` of :class: `c_char_p `, you will always receive a Python bytes
2250
2260
object, *not * a :class: `c_char_p ` instance.
2251
2261
2252
2262
.. XXX above is false, it actually returns a Unicode string
0 commit comments