@@ -383,15 +383,15 @@ as calling functions with a fixed number of parameters. On some platforms, and i
383
383
particular ARM64 for Apple Platforms, the calling convention for variadic functions
384
384
is different than that for regular functions.
385
385
386
- On those platforms it is required to specify the :attr: `~_FuncPtr .argtypes `
386
+ On those platforms it is required to specify the :attr: `~_CFuncPtr .argtypes `
387
387
attribute for the regular, non-variadic, function arguments:
388
388
389
389
.. code-block :: python3
390
390
391
391
libc.printf.argtypes = [ctypes.c_char_p]
392
392
393
393
Because specifying the attribute does not inhibit portability it is advised to always
394
- specify :attr: `~_FuncPtr .argtypes ` for all variadic functions.
394
+ specify :attr: `~_CFuncPtr .argtypes ` for all variadic functions.
395
395
396
396
397
397
.. _ctypes-calling-functions-with-own-custom-data-types :
@@ -426,9 +426,9 @@ Specifying the required argument types (function prototypes)
426
426
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
427
427
428
428
It is possible to specify the required argument types of functions exported from
429
- DLLs by setting the :attr: `~_FuncPtr .argtypes ` attribute.
429
+ DLLs by setting the :attr: `~_CFuncPtr .argtypes ` attribute.
430
430
431
- :attr: `~_FuncPtr .argtypes ` must be a sequence of C data types (the :func: `!printf ` function is
431
+ :attr: `~_CFuncPtr .argtypes ` must be a sequence of C data types (the :func: `!printf ` function is
432
432
probably not a good example here, because it takes a variable number and
433
433
different types of parameters depending on the format string, on the other hand
434
434
this is quite handy to experiment with this feature)::
@@ -453,7 +453,7 @@ prototype for a C function), and tries to convert the arguments to valid types::
453
453
454
454
If you have defined your own classes which you pass to function calls, you have
455
455
to implement a :meth: `~_CData.from_param ` class method for them to be able to use them
456
- in the :attr: `~_FuncPtr .argtypes ` sequence. The :meth: `~_CData.from_param ` class method receives
456
+ in the :attr: `~_CFuncPtr .argtypes ` sequence. The :meth: `~_CData.from_param ` class method receives
457
457
the Python object passed to the function call, it should do a typecheck or
458
458
whatever is needed to make sure this object is acceptable, and then return the
459
459
object itself, its :attr: `!_as_parameter_ ` attribute, or whatever you want to
@@ -476,7 +476,7 @@ Return types
476
476
477
477
478
478
By default functions are assumed to return the C :c:expr: `int ` type. Other
479
- return types can be specified by setting the :attr: `~_FuncPtr .restype ` attribute of the
479
+ return types can be specified by setting the :attr: `~_CFuncPtr .restype ` attribute of the
480
480
function object.
481
481
482
482
The C prototype of :c:func: `time ` is ``time_t time(time_t *) ``. Because :c:type: `time_t `
@@ -485,7 +485,7 @@ specify the :attr:`!restype` attribute::
485
485
486
486
>>> libc.time.restype = c_time_t
487
487
488
- The argument types can be specified using :attr: `~_FuncPtr .argtypes `::
488
+ The argument types can be specified using :attr: `~_CFuncPtr .argtypes `::
489
489
490
490
>>> libc.time.argtypes = (POINTER(c_time_t),)
491
491
@@ -508,7 +508,7 @@ a string pointer and a char, and returns a pointer to a string::
508
508
>>>
509
509
510
510
If you want to avoid the :func: `ord("x") <ord> ` calls above, you can set the
511
- :attr: `~_FuncPtr .argtypes ` attribute, and the second argument will be converted from a
511
+ :attr: `~_CFuncPtr .argtypes ` attribute, and the second argument will be converted from a
512
512
single character Python bytes object into a C char:
513
513
514
514
.. doctest ::
@@ -527,7 +527,7 @@ single character Python bytes object into a C char:
527
527
>>>
528
528
529
529
You can also use a callable Python object (a function or a class for example) as
530
- the :attr: `~_FuncPtr .restype ` attribute, if the foreign function returns an integer. The
530
+ the :attr: `~_CFuncPtr .restype ` attribute, if the foreign function returns an integer. The
531
531
callable will be called with the *integer * the C function returns, and the
532
532
result of this call will be used as the result of your function call. This is
533
533
useful to check for error return values and automatically raise an exception::
@@ -555,7 +555,7 @@ get the string representation of an error code, and *returns* an exception.
555
555
:func: `GetLastError ` to retrieve it.
556
556
557
557
Please note that a much more powerful error checking mechanism is available
558
- through the :attr: `~_FuncPtr .errcheck ` attribute;
558
+ through the :attr: `~_CFuncPtr .errcheck ` attribute;
559
559
see the reference manual for details.
560
560
561
561
@@ -859,7 +859,7 @@ Type conversions
859
859
^^^^^^^^^^^^^^^^
860
860
861
861
Usually, ctypes does strict type checking. This means, if you have
862
- ``POINTER(c_int) `` in the :attr: `~_FuncPtr .argtypes ` list of a function or as the type of
862
+ ``POINTER(c_int) `` in the :attr: `~_CFuncPtr .argtypes ` list of a function or as the type of
863
863
a member field in a structure definition, only instances of exactly the same
864
864
type are accepted. There are some exceptions to this rule, where ctypes accepts
865
865
other objects. For example, you can pass compatible array instances instead of
@@ -880,7 +880,7 @@ pointer types. So, for ``POINTER(c_int)``, ctypes accepts an array of c_int::
880
880
>>>
881
881
882
882
In addition, if a function argument is explicitly declared to be a pointer type
883
- (such as ``POINTER(c_int) ``) in :attr: `~_FuncPtr .argtypes `, an object of the pointed
883
+ (such as ``POINTER(c_int) ``) in :attr: `~_CFuncPtr .argtypes `, an object of the pointed
884
884
type (``c_int `` in this case) can be passed to the function. ctypes will apply
885
885
the required :func: `byref ` conversion in this case automatically.
886
886
@@ -1609,10 +1609,20 @@ As explained in the previous section, foreign functions can be accessed as
1609
1609
attributes of loaded shared libraries. The function objects created in this way
1610
1610
by default accept any number of arguments, accept any ctypes data instances as
1611
1611
arguments, and return the default result type specified by the library loader.
1612
- They are instances of a private class:
1613
1612
1613
+ They are instances of a private local class :class: `!_FuncPtr ` (not exposed
1614
+ in :mod: `!ctypes `) which inherits from the private :class: `_CFuncPtr ` class:
1614
1615
1615
- .. class :: _FuncPtr
1616
+ .. doctest ::
1617
+
1618
+ >>> import ctypes
1619
+ >>> lib = ctypes.CDLL(None )
1620
+ >>> issubclass (lib._FuncPtr, ctypes._CFuncPtr)
1621
+ True
1622
+ >>> lib._FuncPtr is ctypes._CFuncPtr
1623
+ False
1624
+
1625
+ .. class :: _CFuncPtr
1616
1626
1617
1627
Base class for C callable foreign functions.
1618
1628
@@ -1778,7 +1788,7 @@ different ways, depending on the type and number of the parameters in the call:
1778
1788
The optional *paramflags * parameter creates foreign function wrappers with much
1779
1789
more functionality than the features described above.
1780
1790
1781
- *paramflags * must be a tuple of the same length as :attr: `~_FuncPtr .argtypes `.
1791
+ *paramflags * must be a tuple of the same length as :attr: `~_CFuncPtr .argtypes `.
1782
1792
1783
1793
Each item in this tuple contains further information about a parameter, it must
1784
1794
be a tuple containing one, two, or three items.
@@ -1849,7 +1859,7 @@ value if there is a single one, or a tuple containing the output parameter
1849
1859
values when there are more than one, so the GetWindowRect function now returns a
1850
1860
RECT instance, when called.
1851
1861
1852
- Output parameters can be combined with the :attr: `~_FuncPtr .errcheck ` protocol to do
1862
+ Output parameters can be combined with the :attr: `~_CFuncPtr .errcheck ` protocol to do
1853
1863
further output processing and error checking. The win32 ``GetWindowRect `` api
1854
1864
function returns a ``BOOL `` to signal success or failure, so this function could
1855
1865
do the error checking, and raises an exception when the api call failed::
@@ -1862,7 +1872,7 @@ do the error checking, and raises an exception when the api call failed::
1862
1872
>>> GetWindowRect.errcheck = errcheck
1863
1873
>>>
1864
1874
1865
- If the :attr: `~_FuncPtr .errcheck ` function returns the argument tuple it receives
1875
+ If the :attr: `~_CFuncPtr .errcheck ` function returns the argument tuple it receives
1866
1876
unchanged, :mod: `ctypes ` continues the normal processing it does on the output
1867
1877
parameters. If you want to return a tuple of window coordinates instead of a
1868
1878
``RECT `` instance, you can retrieve the fields in the function and return them
@@ -2162,7 +2172,7 @@ Data types
2162
2172
2163
2173
This method adapts *obj * to a ctypes type. It is called with the actual
2164
2174
object used in a foreign function call when the type is present in the
2165
- foreign function's :attr: `~_FuncPtr .argtypes ` tuple;
2175
+ foreign function's :attr: `~_CFuncPtr .argtypes ` tuple;
2166
2176
it must return an object that can be used as a function call parameter.
2167
2177
2168
2178
All ctypes data types have a default implementation of this classmethod
@@ -2228,7 +2238,7 @@ Fundamental data types
2228
2238
Fundamental data types, when returned as foreign function call results, or, for
2229
2239
example, by retrieving structure field members or array items, are transparently
2230
2240
converted to native Python types. In other words, if a foreign function has a
2231
- :attr: `~_FuncPtr .restype ` of :class: `c_char_p `, you will always receive a Python bytes
2241
+ :attr: `~_CFuncPtr .restype ` of :class: `c_char_p `, you will always receive a Python bytes
2232
2242
object, *not * a :class: `c_char_p ` instance.
2233
2243
2234
2244
.. XXX above is false, it actually returns a Unicode string
0 commit comments