STINNER Victor <vstin...@python.org> added the comment:

I was surprised by the following test in StructUnionType_paramfunc():

if ((size_t)self->b_size > sizeof(void*)) {
   ... copy the structure ...
} else {
   ... pass by reference (?) ...
}

So I wrote a simple C library with the structure: typedef struct Point { int x; 
int y; } and functions modifying this structure, structured passed by copy or 
structure passed by reference.

I'm surprised: ctypes works as expected :-)

Try attached point.c and point.py:

$ gcc -c point.c -fpic && gcc -shared -o libpoint.so point.o && python3 point.py
p = <Point x=1 y=2>
p = <Point x=1 y=2>
p = <Point x=0 y=0>
ok
sizeof(Point) = 16 bytes

Modify CoordType in point.c and point.py to test different sizes, on x86-64, I 
get:

* c_byte: 2 bytes
* c_short: 4 bytes
* c_int: 8 bytes
* c_long: 16 bytes

----------
keywords: +3.8regression
versions: +Python 3.9
Added file: https://bugs.python.org/file48574/point.c

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue37140>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to