Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit bc3a11d

Browse filesBrowse files
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.
1 parent 959ba45 commit bc3a11d
Copy full SHA for bc3a11d

File tree

2 files changed

+21
-0
lines changed
Filter options

2 files changed

+21
-0
lines changed

‎Doc/library/ctypes.rst

Copy file name to clipboardExpand all lines: Doc/library/ctypes.rst
+20Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,26 @@ that they can be converted to the required C data type::
373373
31
374374
>>>
375375

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

377397
.. _ctypes-calling-functions-with-own-custom-data-types:
378398

+1Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.