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 ciresnave
Recipients ciresnave, eryksun
Date 2021-09-25.18:53:23
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1632596003.19.0.551798516891.issue45285@roundup.psfhosted.org>
In-reply-to
Content
Wow.  Thank you Eryk Sun.  While that seems like a convoluted way to make a type act like the type it is...it works.  Verified it with the following code:

from ctypes import POINTER, c_char, sizeof, Structure


class char_from_c(c_char):
    pass


print("Size of c_char vs size of char_from_c:")
print(sizeof(c_char))
print(sizeof(char_from_c))


class my_structure(Structure):
    _fields_ = [
        ("first_char", char_from_c),
        ("second_char", char_from_c),
        ("third_char", char_from_c),
    ]


my_structure_object: my_structure = my_structure(97, 98, 99)

pointer_to_char_from_c_in_my_structure = POINTER(c_char)(my_structure_object.first_char)

print("\nContents of pointer_to_char_from_c_in_my_structure:")
print(pointer_to_char_from_c_in_my_structure.contents)
print("\npointer_to_char_from_c_in_my_Structure[0]:")
print(pointer_to_char_from_c_in_my_structure[0])

print("\nValues from my_structure_object:")
character_counter = 0
while character_counter < sizeof(my_structure_object):
    print(pointer_to_char_from_c_in_my_structure[character_counter])
    character_counter += 1



...which gave me the following results:

Size of c_char vs size of char_from_c:
1
1

Contents of pointer_to_char_from_c_in_my_structure:
c_char(b'a')

pointer_to_char_from_c_in_my_Structure[0]:
b'a'

Values from my_structure_object:
b'a'
b'b'
b'c'


Again...Thank you.  Closing this "bug" as it is weird...but not a bug.
History
Date User Action Args
2021-09-25 18:53:23ciresnavesetrecipients: + ciresnave, eryksun
2021-09-25 18:53:23ciresnavesetmessageid: <1632596003.19.0.551798516891.issue45285@roundup.psfhosted.org>
2021-09-25 18:53:23ciresnavelinkissue45285 messages
2021-09-25 18:53:23ciresnavecreate