[New-bugs-announce] [issue42880] ctypes: variadic function call still doesn't work on Apple Silicon

Ziqiao Kong report at bugs.python.org
Sun Jan 10 02:41:58 EST 2021


New submission from Ziqiao Kong <ziqiaokong at gmail.com>:

Hello! Thanks for your contribution on porting python to native Apple Silicon. I have noticed that there is an issue https://bugs.python.org/issue41100 and corresponding Github PR https://github.com/python/cpython/pull/22855 stating that variadic functions ABI has been corrected. However, during our test, it still doesn't work on Apple Silicon with brew-installed python 3.9.1 and python 3..10.0a4 built from sources. The details are as follows:

A x86_64 Mojave Macmini with python 3.8:
```
/tmp $ python3 --version
Python 3.8.6
/tmp $ uname -a
Darwin *** 18.7.0 Darwin Kernel Version 18.7.0: Mon Apr 27 20:09:39 PDT 2020; root:xnu-4903.278.35~1/RELEASE_X86_64 x86_64
/tmp $ cat main.c
#include <stdarg.h>
#include <stdio.h>
#include <stdint.h>
void test(uint64_t end, ...){
  int a;
  va_list valist;
  va_start(valist, end);
  a = va_arg(valist, int);
  va_end(valist);
  printf("%d\n", a);
  return;
}
/tmp $ cc -shared -g main.c -o ./main.dylib
/tmp $ cat test_main.py
from ctypes import *

d = CDLL("./main.dylib")
d.test.restype = None
d.test(c_uint64(12), c_int(34))
/tmp $ python3 test_main.py
34
/tmp $
```

An M1 Macbook Pro with brew-installed python 3.9.1
```
kabeor at kamino /tmp % python3 --version
Python 3.9.1
kabeor at kamino /tmp % cat main.c
#include <stdarg.h>
#include <stdio.h>
#include <stdint.h>
void test(uint64_t end, ...){
  int a;
  va_list valist;
  va_start(valist, end);
  a = va_arg(valist, int);
  va_end(valist);
  printf("%d\n", a);
  return;
}
kabeor at kamino /tmp % cc -shared -g main.c -o ./main.dylib
kabeor at kamino /tmp % cat test_main.py
from ctypes import *

d = CDLL("./main.dylib")
d.test.restype = None
d.test(c_uint64(12), c_int(34))
kabeor at kamino /tmp % python3 test_main.py
48144104
kabeor at kamino /tmp %
```

An M1 Macbook Pro with python 3.10.0a4 built from Github release tarball
```
kabeor at kamino cpython-3.10.0a4 % ./python.exe --version
Python 3.10.0a4
kabeor at kamino cpython-3.10.0a4 % cp /tmp/main.c ./
kabeor at kamino cpython-3.10.0a4 % cp /tmp/test_main.py ./
kabeor at kamino cpython-3.10.0a4 % ./python.exe --version
Python 3.10.0a4
kabeor at kamino cpython-3.10.0a4 % cat ./main.c
#include <stdarg.h>
#include <stdio.h>
#include <stdint.h>
void test(uint64_t end, ...){
  int a;
  va_list valist;
  va_start(valist, end);
  a = va_arg(valist, int);
  va_end(valist);
  printf("%d\n", a);
  return;
}
kabeor at kamino cpython-3.10.0a4 % cc -shared -g main.c -o ./main.dylib
kabeor at kamino cpython-3.10.0a4 % cat test_main.py
from ctypes import *

d = CDLL("./main.dylib")
d.test.restype = None
d.test(c_uint64(12), c_int(34))
kabeor at kamino cpython-3.10.0a4 % ./python.exe test_main.py
3
kabeor at kamino cpython-3.10.0a4 %
```

Thanks in advance!

----------
components: ctypes
messages: 384756
nosy: lawrence-danna-apple, lazymio
priority: normal
severity: normal
status: open
title: ctypes: variadic function call still doesn't work on Apple Silicon
versions: Python 3.10, Python 3.9

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue42880>
_______________________________________


More information about the New-bugs-announce mailing list