Skip to content

Commit a64e71e

Browse files
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 bc3a11d) Co-authored-by: Ronald Oussoren <[email protected]>
1 parent 420b7e8 commit a64e71e

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

Doc/library/ctypes.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,26 @@ that they can be converted to the required C data type::
370370
31
371371
>>>
372372

373+
.. _ctypes-calling-variadic-functions:
374+
375+
Calling varadic functions
376+
^^^^^^^^^^^^^^^^^^^^^^^^^
377+
378+
On a lot of platforms calling variadic functions through ctypes is exactly the same
379+
as calling functions with a fixed number of parameters. On some platforms, and in
380+
particular ARM64 for Apple Platforms, the calling convention for variadic functions
381+
is different than that for regular functions.
382+
383+
On those platforms it is required to specify the *argtypes* attribute for the
384+
regular, non-variadic, function arguments:
385+
386+
.. code-block:: python3
387+
388+
libc.printf.argtypes = [ctypes.c_char_p]
389+
390+
Because specifying the attribute does inhibit portability it is adviced to always
391+
specify ``argtypes`` for all variadic functions.
392+
373393

374394
.. _ctypes-calling-functions-with-own-custom-data-types:
375395

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Document that calling variadic functions with ctypes requires special care on macOS/arm64 (and possibly other platforms).

0 commit comments

Comments
 (0)