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

problem calling variadic functions imported from dynamic libraries under macOS on Apple Silicon #114810

Copy link
Copy link
Open
@applebud

Description

@applebud
Issue body actions

Bug report

Bug description:

I see a problem calling variadic functions imported from dynamic libraries under macOS on Apple Silicon.
I’m using a bit of code sample from https://docs.python.org/3/library/ctypes.html#specifying-the-required-argument-types-function-prototypes
First with Intel macOS Python (running via Rosetta):

% python3
Python 3.11.6 (main, Nov  3 2023, 03:33:27) [Clang 14.0.0 (clang-1400.0.29.202)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import platform
>>> platform.version()
'Darwin Kernel Version 23.3.0: Wed Dec 20 21:31:00 PST 2023; root:xnu-10002.81.5~7/RELEASE_ARM64_T6020'
>>> platform.processor()
'i386'
>>> from ctypes import *
>>> libc = cdll.LoadLibrary("libc.dylib")
>>> printf = libc.printf
>>> printf.argtypes = [c_char_p, c_char_p, c_int, c_double]
>>> printf(b"String '%s', Int %d, Double %f\n", b"Hi", 10, 2.2)
String 'Hi', Int 10, Double 2.200000
37
>>> 

And now with native Apple Silicon Python:

% python3
Python 3.11.7 (main, Dec  4 2023, 18:10:11) [Clang 15.0.0 (clang-1500.1.0.2.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import platform
>>> platform.version()
'Darwin Kernel Version 23.3.0: Wed Dec 20 21:31:00 PST 2023; root:xnu-10002.81.5~7/RELEASE_ARM64_T6020'
>>> platform.processor()
'arm'
>>> from ctypes import *
>>> libc = cdll.LoadLibrary("libc.dylib")
>>> printf = libc.printf
>>> printf.argtypes = [c_char_p, c_char_p, c_int, c_double]
>>> printf(b"String '%s', Int %d, Double %f\n", b"Hi", 10, 2.2)
String '(null)', Int 0, Double 0.000000
40
>>> 

As you can see the results are incorrect.

CPython versions tested on:

3.11

Operating systems tested on:

macOS

Metadata

Metadata

Assignees

No one assigned

    Labels

    OS-mactype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.