diff options
author | Ronald Oussoren <ronaldoussoren@mac.com> | 2022-11-22 10:33:37 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-22 10:33:37 (GMT) |
commit | bc3a11d21ddef28047b18c0f6a5068fa9fb16da2 (patch) | |
tree | f3a7334c86978fc40d837959a74297fee8a719af /Doc | |
parent | 959ba45d75953caa911e16b4c2a277978fc4b9b0 (diff) | |
download | cpython-bc3a11d21ddef28047b18c0f6a5068fa9fb16da2.zip cpython-bc3a11d21ddef28047b18c0f6a5068fa9fb16da2.tar.gz cpython-bc3a11d21ddef28047b18c0f6a5068fa9fb16da2.tar.bz2 |
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.
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/library/ctypes.rst | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/Doc/library/ctypes.rst b/Doc/library/ctypes.rst index e85a6cb..71e5545 100644 --- a/Doc/library/ctypes.rst +++ b/Doc/library/ctypes.rst @@ -373,6 +373,26 @@ that they can be converted to the required C data type:: 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: |