diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2022-11-22 10:57:09 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-22 10:57:09 -0800 |
commit | a64e71eeceb67a993b9b4bd34ab6083f184bd552 (patch) | |
tree | 078cdaf334bceb0ebc65a138d2836e389b6f57ec | |
parent | [3.11] gh-99146 struct module documentation should have more predictable exam... (diff) | |
download | cpython-a64e71eeceb67a993b9b4bd34ab6083f184bd552.tar.gz cpython-a64e71eeceb67a993b9b4bd34ab6083f184bd552.tar.bz2 cpython-a64e71eeceb67a993b9b4bd34ab6083f184bd552.zip |
GH-92892: Add section about variadic functions to ctypes documentation (GH-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.
(cherry picked from commit bc3a11d21ddef28047b18c0f6a5068fa9fb16da2)
Co-authored-by: Ronald Oussoren <ronaldoussoren@mac.com>
-rw-r--r-- | Doc/library/ctypes.rst | 20 | ||||
-rw-r--r-- | Misc/NEWS.d/next/Documentation/2022-11-16-12-52-23.gh-issue-92892.TS-P0j.rst | 1 |
2 files changed, 21 insertions, 0 deletions
diff --git a/Doc/library/ctypes.rst b/Doc/library/ctypes.rst index a8d19a9d1a2..d97d01d265a 100644 --- a/Doc/library/ctypes.rst +++ b/Doc/library/ctypes.rst @@ -370,6 +370,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: diff --git a/Misc/NEWS.d/next/Documentation/2022-11-16-12-52-23.gh-issue-92892.TS-P0j.rst b/Misc/NEWS.d/next/Documentation/2022-11-16-12-52-23.gh-issue-92892.TS-P0j.rst new file mode 100644 index 00000000000..54e421d19d9 --- /dev/null +++ b/Misc/NEWS.d/next/Documentation/2022-11-16-12-52-23.gh-issue-92892.TS-P0j.rst @@ -0,0 +1 @@ +Document that calling variadic functions with ctypes requires special care on macOS/arm64 (and possibly other platforms). |