This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author David.Edelsohn
Recipients Ayappan, BTaskaya, David.Edelsohn, Michael.Felt, T.Rex, ronaldoussoren
Date 2020-08-02.15:30:05
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1596382205.95.0.00131352260102.issue38628@roundup.psfhosted.org>
In-reply-to
Content
I thought that the ctypes documentation mentioned that Arrays passed by Value are converted to Structures.  I cannot find it in the ctypes documentation at the moment.  But Modules/_ctypes/stgdict.c has a large comment about passing Arrays by Value as Structs.

* See bpo-22273. Arrays are normally treated as pointers, which is
* fine when an array name is being passed as parameter, but not when
* passing structures by value that contain arrays. On 64-bit Linux,
* small structures passed by value are passed in registers, and in
* order to do this, libffi needs to know the true type of the array
* members of structs. Treating them as pointers breaks things.

The comment proceeds to discuss 64-bit Linux, which means x86_64 Linux. Python ctypes coerces the array into a structure, which works on x86_64 Linux.  Something about the libffi descriptor created by Python ctypes does not work correctly for AIX, and it may be a fundamental difference in the alignment and padding rules for passing Arrays versus Structures.  Python ctypes assumes that Arrays and Structures are interchangeable with respect to argument passing.

And, again, the initial example was completely wrong and illegal and not expected to work because it created a data object that doesn't match the function signature, which happened to behave correctly on x86.  The initial example in the bug report repeatedly confuses people because they continually try to debug an incorrect use of ctypes.
History
Date User Action Args
2020-08-02 15:30:06David.Edelsohnsetrecipients: + David.Edelsohn, ronaldoussoren, Michael.Felt, Ayappan, BTaskaya, T.Rex
2020-08-02 15:30:05David.Edelsohnsetmessageid: <1596382205.95.0.00131352260102.issue38628@roundup.psfhosted.org>
2020-08-02 15:30:05David.Edelsohnlinkissue38628 messages
2020-08-02 15:30:05David.Edelsohncreate