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 Ayappan
Recipients Ayappan
Date 2019-10-29.09:17:22
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1572340643.38.0.935669039099.issue38628@roundup.psfhosted.org>
In-reply-to
Content
There seems to be a behavioral issue with ctypes in AIX. 
The specific symptom is that passing structures containing arrays to a C function by value appears to be broken.
Consider the below program.,

#!/usr/bin/env python3

from ctypes import *

libc = CDLL('libc.a(shr_64.o)')


class MemchrArgsHack(Structure):
    _fields_ = [("s", c_char_p), ("c", c_ulong), ("n", c_ulong)]


memchr_args_hack = MemchrArgsHack()
memchr_args_hack.s = b"abcdef"
memchr_args_hack.c = ord('d')
memchr_args_hack.n = 7


class MemchrArgsHack2(Structure):
    _fields_ = [("s", c_char_p), ("c_n", c_ulong * 2)]


memchr_args_hack2 = MemchrArgsHack2()
memchr_args_hack2.s = b"abcdef"
memchr_args_hack2.c_n[0] = ord('d')
memchr_args_hack2.c_n[1] = 7

print(
    CFUNCTYPE(c_char_p, c_char_p, c_uint, c_ulong,
              c_void_p)(('memchr', libc))(b"abcdef", c_uint(ord('d')),
                                          c_ulong(7), None))
print(
    CFUNCTYPE(c_char_p, MemchrArgsHack,
              c_void_p)(('memchr', libc))(memchr_args_hack, None))
print(
    CFUNCTYPE(c_char_p, MemchrArgsHack2,
              c_void_p)(('memchr', libc))(memchr_args_hack2, None))

This one uses memchr from the C library and passing it structures that would map to the registers that correspond to the arguments of memchr. This works for the first structure type in the reproducer; however, using the second structure type (which should be treated the same way) does not work.

In the failing case, the last register that should be used for the structure is not populated from the structure. The reproducer passes an extra argument so that the register is instead populated from that argument for the failing case (instead of working because the register still contains the correct value from a previous call).

The output should be the same for all three calls, but we get:
b'def'
b'def'
None

The last line is None, because memchr got 0 (the None passed on the call) for its length argument.
History
Date User Action Args
2019-10-29 09:17:23Ayappansetrecipients: + Ayappan
2019-10-29 09:17:23Ayappansetmessageid: <1572340643.38.0.935669039099.issue38628@roundup.psfhosted.org>
2019-10-29 09:17:23Ayappanlinkissue38628 messages
2019-10-29 09:17:22Ayappancreate