[issue4376] Nested ctypes 'BigEndianStructure' fails
Changes by Vlad Riscutia riscutiav...@gmail.com: Removed file: http://bugs.python.org/file22627/issue4376_fix.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue4376 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue4376] Nested ctypes 'BigEndianStructure' fails
Vlad Riscutia riscutiav...@gmail.com added the comment: New patch containing unittest that actually tests the feature. I would appreciate it if someone can try this on a bigendian machine. -- Added file: http://bugs.python.org/file22642/issue4376_fix.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue4376 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue4376] Nested ctypes 'BigEndianStructure' fails
Changes by Vlad Riscutia riscutiav...@gmail.com: Removed file: http://bugs.python.org/file22642/issue4376_fix.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue4376 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue4376] Nested ctypes 'BigEndianStructure' fails
Vlad Riscutia riscutiav...@gmail.com added the comment: Changed c_int in tests to c_int32 just to be on the safe side. -- Added file: http://bugs.python.org/file22643/issue4376_fix.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue4376 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue4376] Nested ctypes 'BigEndianStructure' fails
STINNER Victor victor.stin...@haypocalc.com added the comment: I don't like your test because it depends on system endian: +if sys.byteorder == little: +struct.menu.spam = 0x00FF +else: +struct.menu.spam = 0xFF00 I would prefer a test creating a structure from a byte string. Something like: --- import ctypes class Nested(ctypes.BigEndianStructure): _fields_ = ( ('x', ctypes.c_uint32), ('y', ctypes.c_uint32), ) class TestStruct(ctypes.BigEndianStructure): _fields_ = ( ('point', Nested), ) data = b'\0\0\0\1\0\0\0\2' assert len(data) == ctypes.sizeof(TestStruct) obj = ctypes.cast(data, ctypes.POINTER(TestStruct))[0] assert obj.point.x == 1 assert obj.point.y == 2 --- Use b'\1\0\0\0\2\0\0\0' for little endian. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue4376 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue4376] Nested ctypes 'BigEndianStructure' fails
Vlad Riscutia riscutiav...@gmail.com added the comment: But if you set raw memory to let's say b'\0\0\0\1', when you look at the c_int value afterwards, won't it be different on little endian and big endian machines? -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue4376 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue4376] Nested ctypes 'BigEndianStructure' fails
Changes by Jake jake.coff...@gmail.com: -- nosy: -Jake.Coffman ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue4376 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue4376] Nested ctypes 'BigEndianStructure' fails
STINNER Victor victor.stin...@haypocalc.com added the comment: But if you set raw memory to let's say b'\0\0\0\1', when you look at the c_int value afterwards, won't it be different on little endian and big endian machines? A big endian structure is supposed to read and write memory in the... big endian order, not in the host endian. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue4376 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue4376] Nested ctypes 'BigEndianStructure' fails
Changes by Vlad Riscutia riscutiav...@gmail.com: Removed file: http://bugs.python.org/file22643/issue4376_fix.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue4376 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue4376] Nested ctypes 'BigEndianStructure' fails
Vlad Riscutia riscutiav...@gmail.com added the comment: You're right. I was busy swapping bytes in my head and missed that :) -- Added file: http://bugs.python.org/file22644/issue4376_fix.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue4376 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue4376] Nested ctypes 'BigEndianStructure' fails
Roundup Robot devnull@devnull added the comment: New changeset 72e73fa03124 by Victor Stinner in branch '3.2': Close #4376: ctypes now supports nested structures in a endian different than http://hg.python.org/cpython/rev/72e73fa03124 New changeset 637210b9d054 by Victor Stinner in branch 'default': (merge 3.2) Close #4376: ctypes now supports nested structures in a endian http://hg.python.org/cpython/rev/637210b9d054 New changeset a9d0fab19d5e by Victor Stinner in branch '2.7': Close #4376: ctypes now supports nested structures in a endian different than http://hg.python.org/cpython/rev/a9d0fab19d5e -- nosy: +python-dev resolution: - fixed stage: test needed - committed/rejected status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue4376 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue4376] Nested ctypes 'BigEndianStructure' fails
STINNER Victor victor.stin...@haypocalc.com added the comment: I commited your fix, thanks Vlad! -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue4376 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue4376] Nested ctypes 'BigEndianStructure' fails
Amaury Forgeot d'Arc amaur...@gmail.com added the comment: Is there a unit test about the actual feature: that the bytes are actually swapped in the structure? For example, with a class T(BigEndianStructure): _fields_ = [(a, c_int), (b, c_int)] cast a pointer to T into a pointer to c_int, and read the values. -- nosy: +amaury.forgeotdarc ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue4376 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue4376] Nested ctypes 'BigEndianStructure' fails
Vlad Riscutia riscutiav...@gmail.com added the comment: Added unit test to reproduce the issue (covers both big endian and little endian structures so _other_endian function is hit on any machine). Test currently fails without fix and passes with proposed fix in place. -- keywords: +patch nosy: +vladris Added file: http://bugs.python.org/file22623/issue4376_test.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue4376 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue4376] Nested ctypes 'BigEndianStructure' fails
Vlad Riscutia riscutiav...@gmail.com added the comment: Also added diff for fix: - Implemented proposed issubclass(typ, Structure) solution - Refactored _other_endian function because we used to getattr, catch exception, then check if type is array/structure. I believe exception throwing should not be on normal code path so I replaced try-except with a check for hasattr - Removed a unittest which becomes deprecated with this fix (unittest asserts getting _other_endian for nested struct raises exception which is no longer the case) -- Added file: http://bugs.python.org/file22627/issue4376_fix.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue4376 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue4376] Nested ctypes 'BigEndianStructure' fails
Changes by Jake jake.coff...@gmail.com: -- nosy: +Jake.Coffman ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue4376 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue4376] Nested ctypes 'BigEndianStructure' fails
Terry J. Reedy tjre...@udel.edu added the comment: The test could be build from the attached example. -- nosy: +tjreedy stage: - unit test needed type: compile error - feature request versions: +Python 3.2 -Python 2.5, Python 2.6 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue4376 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue4376] Nested ctypes 'BigEndianStructure' fails
Alexander Belopolsky alexander.belopol...@gmail.com added the comment: theller - Should 'part' be inserted as is, [possibly] leading theller to a total structure of fields with mixed byte order? +1 for this option. -- nosy: +Alexander.Belopolsky ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue4376 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue4376] Nested ctypes 'BigEndianStructure' fails
STINNER Victor victor.stin...@haypocalc.com added the comment: ping! This issue is still open. -- nosy: +haypo ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue4376 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue4376] Nested ctypes 'BigEndianStructure' fails
Thomas Heller [EMAIL PROTECTED] added the comment: Currently, the _fields_ of ctypes Structures with non-native byte order can only contain simple types (like int, char, but not pointers), and arrays of those. Since this is all Python code (in Lib/ctypes/endian.py) it should be possible to extend the code to handle other types as well. If we do this, it must be decided if a Structure (call it 'part' for this discussion) of some byte order is contained in a _field_ of a non-native Structure type: - Should 'part' be inserted as is, leading to a total structure of fields with mixed byte order? - Should a new type be created from the 'part' _fields_, with also non-native byte-order? Other approaches would be possible as well... Here is a simple patch that implements the first approach; I have not tested if it works correctly: Index: _endian.py === --- _endian.py (revision 67045) +++ _endian.py (working copy) @@ -17,6 +17,8 @@ except AttributeError: if type(typ) == _array_type: return _other_endian(typ._type_) * typ._length_ +if issubclass(typ, Structure): +return typ raise TypeError(This type does not support other endian: %s % typ) class _swapped_meta(type(Structure)): ___ Python tracker [EMAIL PROTECTED] http://bugs.python.org/issue4376 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue4376] Nested ctypes 'BigEndianStructure' fails
Thomas Heller [EMAIL PROTECTED] added the comment: Correction: Since this is all Python code (in Lib/ctypes/_endian.py) it should be ___ Python tracker [EMAIL PROTECTED] http://bugs.python.org/issue4376 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue4376] Nested ctypes 'BigEndianStructure' fails
New submission from Aaron Brady [EMAIL PROTECTED]: Nested 'BigEndianStructure' fails in 2.5 and 2.6.: TypeError: This type does not support other endian Example and traceback in attached file. -- assignee: theller components: ctypes files: ng36.py messages: 76171 nosy: castironpi, theller severity: normal status: open title: Nested ctypes 'BigEndianStructure' fails type: compile error versions: Python 2.5, Python 2.6 Added file: http://bugs.python.org/file12091/ng36.py ___ Python tracker [EMAIL PROTECTED] http://bugs.python.org/issue4376 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com