David Edelsohn <dje....@gmail.com> added the comment:
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. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue38628> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com