New submission from higstar <adr...@higstar.com>: When defining a structure with members of ctype type c_ulonglong, some members appear read only?
I created this test.py and appended the results below: ----- import ctypes import time class all_ulong(ctypes.BigEndianStructure): _fields_ = [ ("Data0", ctypes.c_ulong, 4), ("Data1", ctypes.c_ulong, 4), ] class all_ulonglong(ctypes.BigEndianStructure): _fields_ = [ ("Data0", ctypes.c_ulonglong, 4), ("Data1", ctypes.c_ulonglong, 4), ] def inc_both_members(test): test.Data0 += 1 test.Data1 += 1 def print_both_members(test): print("Data0 is %d, Data1 is %d for %s"%(test.Data0, test.Data1, test.__class__.__name__)) tests = [all_ulong(), all_ulonglong()] for test in tests: print_both_members(test) Failed = False while not Failed: for test in tests: inc_both_members(test) print_both_members(test) if not tests[0].Data0 == tests[1].Data0: Failed = True if not tests[0].Data1 == tests[1].Data1: Failed = True ----- >c:\python25\python.exe test.py Data0 is 0, Data1 is 0 for all_ulong Data0 is 0, Data1 is 0 for all_ulonglong Data0 is 1, Data1 is 1 for all_ulong Data0 is 1, Data1 is 1 for all_ulonglong Data0 is 2, Data1 is 2 for all_ulong Data0 is 2, Data1 is 1 for all_ulonglong >c:\python26\python.exe test.py Data0 is 0, Data1 is 0 for all_ulong Data0 is 0, Data1 is 0 for all_ulonglong Data0 is 1, Data1 is 1 for all_ulong Data0 is 1, Data1 is 1 for all_ulonglong Data0 is 2, Data1 is 2 for all_ulong Data0 is 2, Data1 is 1 for all_ulonglong >c:\python30\python.exe test.py Data0 is 0, Data1 is 0 for all_ulong Data0 is 0, Data1 is 0 for all_ulonglong Data0 is 1, Data1 is 1 for all_ulong Data0 is 1, Data1 is 1 for all_ulonglong Data0 is 2, Data1 is 2 for all_ulong Data0 is 2, Data1 is 1 for all_ulonglong As you can see the second member Data1, is not incrementing correctly. I found this issue because I started using c_ulonglong types for all members so that when casting a byte stream to one of these ctype structures, there are no incorrect values when casting to a member crossing byte/word/long boundaries. ---------- assignee: theller components: ctypes messages: 88110 nosy: higstar, theller severity: normal status: open title: c_ulonglong structure members appear read-only type: compile error versions: Python 2.5, Python 2.6, Python 3.0 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue6068> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com