Author vstinner
Recipients Paul Monson, lukasz.langa, petr.viktorin, serge-sans-paille, steve.dower, vstinner
Date 2019-08-30.09:48:54
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1567158535.19.0.564899936942.issue37140@roundup.psfhosted.org>
In-reply-to
Content
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
History
Date User Action Args
2019-08-30 09:48:55vstinnersetrecipients: + vstinner, petr.viktorin, lukasz.langa, steve.dower, serge-sans-paille, Paul Monson
2019-08-30 09:48:55vstinnersetmessageid: <1567158535.19.0.564899936942.issue37140@roundup.psfhosted.org>
2019-08-30 09:48:55vstinnerlinkissue37140 messages
2019-08-30 09:48:54vstinnercreate