mirror of
https://github.com/python/cpython.git
synced 2025-09-27 02:39:58 +00:00
GH-92892: Add section about variadic functions to ctypes documentation (#99529)
On some platforms, and in particular macOS/arm64, the calling convention for variadic arguments is different from the regular calling convention. Add a section to the documentation to document this.
This commit is contained in:
parent
959ba45d75
commit
bc3a11d21d
2 changed files with 21 additions and 0 deletions
|
@ -373,6 +373,26 @@ that they can be converted to the required C data type::
|
||||||
31
|
31
|
||||||
>>>
|
>>>
|
||||||
|
|
||||||
|
.. _ctypes-calling-variadic-functions:
|
||||||
|
|
||||||
|
Calling varadic functions
|
||||||
|
^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
On a lot of platforms calling variadic functions through ctypes is exactly the same
|
||||||
|
as calling functions with a fixed number of parameters. On some platforms, and in
|
||||||
|
particular ARM64 for Apple Platforms, the calling convention for variadic functions
|
||||||
|
is different than that for regular functions.
|
||||||
|
|
||||||
|
On those platforms it is required to specify the *argtypes* attribute for the
|
||||||
|
regular, non-variadic, function arguments:
|
||||||
|
|
||||||
|
.. code-block:: python3
|
||||||
|
|
||||||
|
libc.printf.argtypes = [ctypes.c_char_p]
|
||||||
|
|
||||||
|
Because specifying the attribute does inhibit portability it is adviced to always
|
||||||
|
specify ``argtypes`` for all variadic functions.
|
||||||
|
|
||||||
|
|
||||||
.. _ctypes-calling-functions-with-own-custom-data-types:
|
.. _ctypes-calling-functions-with-own-custom-data-types:
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Document that calling variadic functions with ctypes requires special care on macOS/arm64 (and possibly other platforms).
|
Loading…
Add table
Add a link
Reference in a new issue