ctypes-commit Mailing List for ctypes (Page 34)
Brought to you by:
theller
You can subscribe to this list here.
2004 |
Jan
|
Feb
|
Mar
|
Apr
(8) |
May
(90) |
Jun
(143) |
Jul
(106) |
Aug
(94) |
Sep
(84) |
Oct
(163) |
Nov
(60) |
Dec
(58) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2005 |
Jan
(128) |
Feb
(79) |
Mar
(227) |
Apr
(192) |
May
(179) |
Jun
(41) |
Jul
(53) |
Aug
(103) |
Sep
(28) |
Oct
(38) |
Nov
(81) |
Dec
(17) |
2006 |
Jan
(184) |
Feb
(111) |
Mar
(188) |
Apr
(67) |
May
(58) |
Jun
(123) |
Jul
(73) |
Aug
|
Sep
|
Oct
(1) |
Nov
|
Dec
|
From: Thomas H. <th...@us...> - 2005-11-30 09:36:15
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1160 Modified Files: Tag: branch_1_0 _ctypes.c Log Message: Bump version number to 0.9.9.1, and fix the path to the ctypes.test package in the setup script. Index: _ctypes.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes.c,v retrieving revision 1.226.2.37 retrieving revision 1.226.2.38 diff -C2 -d -r1.226.2.37 -r1.226.2.38 *** _ctypes.c 29 Nov 2005 20:15:17 -0000 1.226.2.37 --- _ctypes.c 30 Nov 2005 09:36:07 -0000 1.226.2.38 *************** *** 4416,4420 **** PyModule_AddObject(m, "FUNCFLAG_CDECL", PyInt_FromLong(FUNCFLAG_CDECL)); PyModule_AddObject(m, "FUNCFLAG_PYTHONAPI", PyInt_FromLong(FUNCFLAG_PYTHONAPI)); ! PyModule_AddStringConstant(m, "__version__", "0.9.9.0"); #ifdef RTLD_LOCAL --- 4416,4420 ---- PyModule_AddObject(m, "FUNCFLAG_CDECL", PyInt_FromLong(FUNCFLAG_CDECL)); PyModule_AddObject(m, "FUNCFLAG_PYTHONAPI", PyInt_FromLong(FUNCFLAG_PYTHONAPI)); ! PyModule_AddStringConstant(m, "__version__", "0.9.9.1"); #ifdef RTLD_LOCAL |
From: Thomas H. <th...@us...> - 2005-11-30 09:36:11
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1124 Modified Files: Tag: branch_1_0 setup.py Log Message: Bump version number to 0.9.9.1, and fix the path to the ctypes.test package in the setup script. Index: setup.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/setup.py,v retrieving revision 1.122.2.8 retrieving revision 1.122.2.9 diff -C2 -d -r1.122.2.8 -r1.122.2.9 *** setup.py 8 Nov 2005 20:34:13 -0000 1.122.2.8 --- setup.py 30 Nov 2005 09:36:01 -0000 1.122.2.9 *************** *** 12,16 **** LIBFFI_SOURCES='source/gcc/libffi' ! __version__ = "0.9.9.0" ################################################################ --- 12,16 ---- LIBFFI_SOURCES='source/gcc/libffi' ! __version__ = "0.9.9.1" ################################################################ *************** *** 281,286 **** package_dir["ctypes.com.tools"] = "win32/com/tools" ! packages.append("ctypes.test") ! package_dir["ctypes.test"] = "win32/com/test" ################################################################ --- 281,286 ---- package_dir["ctypes.com.tools"] = "win32/com/tools" ! packages.append("ctypes.com.test") ! package_dir["ctypes.com.test"] = "win32/com/test" ################################################################ |
From: Thomas H. <th...@us...> - 2005-11-30 09:35:13
|
Update of /cvsroot/ctypes/ctypes/ctypes/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv830 Modified Files: Tag: branch_1_0 test_byteswap.py Log Message: Add some testing ideas. Index: test_byteswap.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/test/Attic/test_byteswap.py,v retrieving revision 1.1.2.5 retrieving revision 1.1.2.6 diff -C2 -d -r1.1.2.5 -r1.1.2.6 *** test_byteswap.py 29 Nov 2005 20:36:57 -0000 1.1.2.5 --- test_byteswap.py 30 Nov 2005 09:35:03 -0000 1.1.2.6 *************** *** 129,132 **** --- 129,202 ---- self.failUnless(c_char.__ctype_be__ is c_char) + ''' + ################################################################ + + def test(): + from ctypes import BigEndianStructure + class PT(BigEndianStructure): + ## class PT(Structure): + _fields_ = [("x", c_int), + ("y", c_int), + ("b", c_char), + ## ("c", c_wchar), + ("c", c_byte), + ("d", c_ubyte), + ## ("e", POINTER(c_int)), + ## ("f", POINTER(POINTER(c_int))), + + ## ("float", c_float), + ## ("double", c_double), + + ("b1", c_byte, 3), + ("b2", c_byte, 3), + ("b3", c_byte, 2), + ("a", c_int * 3 * 3 * 3)] + + for desc in PT._fields_: + print getattr(PT, desc[0]) + + if __name__ == "__main__": + test() + + from ctypes import BigEndianStructure + + class SCSI_6(BigEndianStructure): + _pack_ = 1 + _fields_ = [("opcode", c_ubyte, 8), + + ("lun", c_ulong, 3), + ("blockaddr", c_ulong, 21), + ("transferlen", c_ulong, 8), + + ("controlbyte", c_ubyte, 8)] + print sizeof(SCSI_6) + + def bin(s): + from binascii import hexlify + return hexlify(str(buffer(s))) + + print bin(SCSI_6(-1)) + print bin(SCSI_6(0, -1)) + print bin(SCSI_6(0, 0, -1)) + print bin(SCSI_6(0, 0, 0, -1)) + print bin(SCSI_6(0, 0, 0, 0, -1)) + + class SCSI_12(BigEndianStructure): + _pack_ = 1 + _fields_ = [("opcode", c_ubyte, 8), + + ("lun", c_ubyte, 3), + ("_res1", c_ubyte, 4), + ("reladdr", c_ubyte, 1), + + ("blockaddr", c_ulong), + + ("_res2", c_ubyte), + ("_res3", c_ubyte), + ("_res4", c_ubyte), + + ("transferlen", c_ushort), + ("controlbyte", c_ubyte)] + ''' if __name__ == "__main__": |
From: Thomas H. <th...@us...> - 2005-11-30 09:35:05
|
Update of /cvsroot/ctypes/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv707 Added Files: Tag: branch_1_0 _endian.py Log Message: Implement BigEndianStructure and LittleEndianStructure. --- NEW FILE: _endian.py --- from ctypes import * _array_type = type(c_int * 3) def _other_endian(typ): """Return the type with the 'other' byte order. Simple types like c_int and so on already have __ctype_be__ and __ctype_le__ attributes which contain the types, for more complicated types only arrays are supported. """ try: return getattr(typ, _OTHER_ENDIAN) except AttributeError: if type(typ) == _array_type: return _other_endian(typ._type_) * typ._length_ raise TypeError("This type does not support other endian: %s" % typ) class _swapped_meta(type(Structure)): def __setattr__(self, attrname, value): if attrname == "_fields_": fields = [] for desc in value: name = desc[0] typ = desc[1] rest = desc[2:] fields.append((name, _other_endian(typ)) + rest) value = fields super(_swapped_meta, self).__setattr__(attrname, value) ################################################################ # Note: The Structure metaclass checks for the *presence* (not the # value!) of a _swapped_bytes_ attribute to determine the bit order in # structures containing bit fields. if sys.byteorder == "little": _OTHER_ENDIAN = "__ctype_be__" LittleEndianStructure = Structure class BigEndianStructure(Structure): """Structure with big endian byte order""" __metaclass__ = _swapped_meta _swappedbytes_ = None elif sys.byteorder == "big": _OTHER_ENDIAN = "__ctype_le__" BigEndianStructure = Structure class LittleEndianStructure(Structure): """Structure with little endian byte order""" __metaclass__ = _swapped_meta _swappedbytes_ = None else: raise RuntimeError("Invalid byteorder") |
From: Thomas H. <th...@us...> - 2005-11-30 09:34:28
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv590 Modified Files: Tag: branch_1_0 stgdict.c Log Message: Implement BigEndianStructure and LittleEndianStructure. Index: stgdict.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/stgdict.c,v retrieving revision 1.32.2.3 retrieving revision 1.32.2.4 diff -C2 -d -r1.32.2.3 -r1.32.2.4 *** stgdict.c 11 Nov 2005 08:10:26 -0000 1.32.2.3 --- stgdict.c 30 Nov 2005 09:34:21 -0000 1.32.2.4 *************** *** 195,201 **** #ifdef IS_BIG_ENDIAN ! big_endian = 1; #else ! big_endian = 0; #endif --- 195,201 ---- #ifdef IS_BIG_ENDIAN ! big_endian = PyObject_HasAttrString(type, "_swappedbytes_") ? 0 : 1; #else ! big_endian = PyObject_HasAttrString(type, "_swappedbytes_") ? 1 : 0; #endif |
From: Thomas H. <th...@us...> - 2005-11-30 09:34:24
|
Update of /cvsroot/ctypes/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv568 Modified Files: Tag: branch_1_0 __init__.py Log Message: Implement BigEndianStructure and LittleEndianStructure. Index: __init__.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/__init__.py,v retrieving revision 1.61.2.14 retrieving revision 1.61.2.15 diff -C2 -d -r1.61.2.14 -r1.61.2.15 *** __init__.py 29 Nov 2005 20:14:57 -0000 1.61.2.14 --- __init__.py 30 Nov 2005 09:34:16 -0000 1.61.2.15 *************** *** 9,13 **** del _magicfile ! __version__ = "0.9.9.0" from _ctypes import Union, Structure, Array --- 9,13 ---- del _magicfile ! __version__ = "0.9.9.1" from _ctypes import Union, Structure, Array *************** *** 461,462 **** --- 461,464 ---- pass return result + + from ctypes._endian import BigEndianStructure, LittleEndianStructure |
From: Thomas H. <th...@us...> - 2005-11-30 07:47:10
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32750 Modified Files: Tag: branch_1_0 cfield.c Log Message: Correct l_get_sw. Index: cfield.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/cfield.c,v retrieving revision 1.74.2.12 retrieving revision 1.74.2.13 diff -C2 -d -r1.74.2.12 -r1.74.2.13 *** cfield.c 30 Nov 2005 07:43:16 -0000 1.74.2.12 --- cfield.c 30 Nov 2005 07:47:02 -0000 1.74.2.13 *************** *** 736,740 **** { long val = *(long *)ptr; ! val = SWAP_INT(val); GET_BITFIELD(val, size); return PyInt_FromLong(val); --- 736,740 ---- { long val = *(long *)ptr; ! val = SWAP_LONG(val); GET_BITFIELD(val, size); return PyInt_FromLong(val); |
From: Thomas H. <th...@us...> - 2005-11-30 07:43:25
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31653 Modified Files: Tag: branch_1_0 cfield.c Log Message: Correct definition of SWAP_LONG. Index: cfield.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/cfield.c,v retrieving revision 1.74.2.11 retrieving revision 1.74.2.12 diff -C2 -d -r1.74.2.11 -r1.74.2.12 *** cfield.c 29 Nov 2005 20:34:08 -0000 1.74.2.11 --- cfield.c 30 Nov 2005 07:43:16 -0000 1.74.2.12 *************** *** 446,450 **** # define SWAP_LONG SWAP_4 #elif SIZEOF_LONG == 8 ! # define SWAP_LONG SWAP_4 #endif /***************************************************************** --- 446,450 ---- # define SWAP_LONG SWAP_4 #elif SIZEOF_LONG == 8 ! # define SWAP_LONG SWAP_8 #endif /***************************************************************** |
From: Thomas H. <th...@us...> - 2005-11-29 20:37:24
|
Update of /cvsroot/ctypes/ctypes/ctypes/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16549 Modified Files: Tag: branch_1_0 test_byteswap.py Log Message: More struct.pack comparisons. Index: test_byteswap.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/test/Attic/test_byteswap.py,v retrieving revision 1.1.2.4 retrieving revision 1.1.2.5 diff -C2 -d -r1.1.2.4 -r1.1.2.5 *** test_byteswap.py 29 Nov 2005 20:32:33 -0000 1.1.2.4 --- test_byteswap.py 29 Nov 2005 20:36:57 -0000 1.1.2.5 *************** *** 100,115 **** --- 100,119 ---- s = c_longlong.__ctype_be__(0x1234567890ABCDEF) + self.failUnlessEqual(bin(struct.pack(">q", 0x1234567890ABCDEF)), "1234567890ABCDEF") self.failUnlessEqual(bin(s), "1234567890ABCDEF") self.failUnlessEqual(s.value, 0x1234567890ABCDEF) s = c_longlong.__ctype_le__(0x1234567890ABCDEF) + self.failUnlessEqual(bin(struct.pack("<q", 0x1234567890ABCDEF)), "EFCDAB9078563412") self.failUnlessEqual(bin(s), "EFCDAB9078563412") self.failUnlessEqual(s.value, 0x1234567890ABCDEF) s = c_ulonglong.__ctype_be__(0x1234567890ABCDEF) + self.failUnlessEqual(bin(struct.pack(">Q", 0x1234567890ABCDEF)), "1234567890ABCDEF") self.failUnlessEqual(bin(s), "1234567890ABCDEF") self.failUnlessEqual(s.value, 0x1234567890ABCDEF) s = c_ulonglong.__ctype_le__(0x1234567890ABCDEF) + self.failUnlessEqual(bin(struct.pack("<Q", 0x1234567890ABCDEF)), "EFCDAB9078563412") self.failUnlessEqual(bin(s), "EFCDAB9078563412") self.failUnlessEqual(s.value, 0x1234567890ABCDEF) |
From: Thomas H. <th...@us...> - 2005-11-29 20:34:22
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16058 Modified Files: Tag: branch_1_0 cfield.c Log Message: Fix I_set_sw. Index: cfield.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/cfield.c,v retrieving revision 1.74.2.10 retrieving revision 1.74.2.11 diff -C2 -d -r1.74.2.10 -r1.74.2.11 *** cfield.c 29 Nov 2005 20:24:00 -0000 1.74.2.10 --- cfield.c 29 Nov 2005 20:34:08 -0000 1.74.2.11 *************** *** 678,682 **** field = SWAP_INT(*(unsigned int *)ptr); field = (unsigned int)SET(field, (unsigned int)val, size); ! *(unsigned int *)ptr = field; _RET(value); } --- 678,682 ---- field = SWAP_INT(*(unsigned int *)ptr); field = (unsigned int)SET(field, (unsigned int)val, size); ! *(unsigned int *)ptr = SWAP_INT(field); _RET(value); } |
From: Thomas H. <th...@us...> - 2005-11-29 20:33:08
|
Update of /cvsroot/ctypes/ctypes/ctypes/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15594 Modified Files: Tag: branch_1_0 test_byteswap.py Log Message: Make sure the tests are valid, by comparing with struct.pack. Index: test_byteswap.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/test/Attic/test_byteswap.py,v retrieving revision 1.1.2.3 retrieving revision 1.1.2.4 diff -C2 -d -r1.1.2.3 -r1.1.2.4 *** test_byteswap.py 29 Nov 2005 20:15:05 -0000 1.1.2.3 --- test_byteswap.py 29 Nov 2005 20:32:33 -0000 1.1.2.4 *************** *** 5,8 **** --- 5,10 ---- from ctypes.test import requires + import struct + requires("swap") *************** *** 42,57 **** --- 44,63 ---- self.failUnless(c_short.__ctype_le__.__ctype_be__ is c_short) s = c_short.__ctype_be__(0x1234) + self.failUnlessEqual(bin(struct.pack(">h", 0x1234)), "1234") self.failUnlessEqual(bin(s), "1234") self.failUnlessEqual(s.value, 0x1234) s = c_short.__ctype_le__(0x1234) + self.failUnlessEqual(bin(struct.pack("<h", 0x1234)), "3412") self.failUnlessEqual(bin(s), "3412") self.failUnlessEqual(s.value, 0x1234) s = c_ushort.__ctype_be__(0x1234) + self.failUnlessEqual(bin(struct.pack(">h", 0x1234)), "1234") self.failUnlessEqual(bin(s), "1234") self.failUnlessEqual(s.value, 0x1234) s = c_ushort.__ctype_le__(0x1234) + self.failUnlessEqual(bin(struct.pack("<h", 0x1234)), "3412") self.failUnlessEqual(bin(s), "3412") self.failUnlessEqual(s.value, 0x1234) *************** *** 66,81 **** --- 72,91 ---- s = c_int.__ctype_be__(0x12345678) + self.failUnlessEqual(bin(struct.pack(">i", 0x12345678)), "12345678") self.failUnlessEqual(bin(s), "12345678") self.failUnlessEqual(s.value, 0x12345678) s = c_int.__ctype_le__(0x12345678) + self.failUnlessEqual(bin(struct.pack("<i", 0x12345678)), "78563412") self.failUnlessEqual(bin(s), "78563412") self.failUnlessEqual(s.value, 0x12345678) s = c_uint.__ctype_be__(0x12345678) + self.failUnlessEqual(bin(struct.pack(">I", 0x12345678)), "12345678") self.failUnlessEqual(bin(s), "12345678") self.failUnlessEqual(s.value, 0x12345678) s = c_uint.__ctype_le__(0x12345678) + self.failUnlessEqual(bin(struct.pack("<I", 0x12345678)), "78563412") self.failUnlessEqual(bin(s), "78563412") self.failUnlessEqual(s.value, 0x12345678) |
From: Thomas H. <th...@us...> - 2005-11-29 20:24:11
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13917 Modified Files: Tag: branch_1_0 cfield.c Log Message: Fix two silly mistakes. Index: cfield.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/cfield.c,v retrieving revision 1.74.2.9 retrieving revision 1.74.2.10 diff -C2 -d -r1.74.2.9 -r1.74.2.10 *** cfield.c 29 Nov 2005 20:18:51 -0000 1.74.2.9 --- cfield.c 29 Nov 2005 20:24:00 -0000 1.74.2.10 *************** *** 676,680 **** if (get_ulong(value, &val) < 0) return NULL; ! field = SWAP_INT(*(unsigned int *)val); field = (unsigned int)SET(field, (unsigned int)val, size); *(unsigned int *)ptr = field; --- 676,680 ---- if (get_ulong(value, &val) < 0) return NULL; ! field = SWAP_INT(*(unsigned int *)ptr); field = (unsigned int)SET(field, (unsigned int)val, size); *(unsigned int *)ptr = field; *************** *** 717,723 **** if (get_long(value, &val) < 0) return NULL; ! field = *(long *)ptr; field = (long)SET(field, val, size); ! *(long *)ptr = SWAP_INT(field); _RET(value); } --- 717,723 ---- if (get_long(value, &val) < 0) return NULL; ! field = SWAP_LONG(*(long *)ptr); field = (long)SET(field, val, size); ! *(long *)ptr = SWAP_LONG(field); _RET(value); } |
From: Thomas H. <th...@us...> - 2005-11-29 20:19:00
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12933 Modified Files: Tag: branch_1_0 cfield.c Log Message: GCC complains about too large constants. Index: cfield.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/cfield.c,v retrieving revision 1.74.2.8 retrieving revision 1.74.2.9 diff -C2 -d -r1.74.2.8 -r1.74.2.9 *** cfield.c 29 Nov 2005 20:15:17 -0000 1.74.2.8 --- cfield.c 29 Nov 2005 20:18:51 -0000 1.74.2.9 *************** *** 432,442 **** #define SWAP_8(v) \ ! ( ( (v & 0x00000000000000FF) << 56 ) | \ ! ( (v & 0x000000000000FF00) << 40 ) | \ ! ( (v & 0x0000000000FF0000) << 24 ) | \ ! ( (v & 0x00000000FF000000) << 8 ) | \ ! ( (v & 0x000000FF00000000) >> 8 ) | \ ! ( (v & 0x0000FF0000000000) >> 24 ) | \ ! ( (v & 0x00FF000000000000) >> 40 ) | \ ( ((v >> 56) & 0xFF)) ) --- 432,442 ---- #define SWAP_8(v) \ ! ( ( (v & 0x00000000000000FFLL) << 56 ) | \ ! ( (v & 0x000000000000FF00LL) << 40 ) | \ ! ( (v & 0x0000000000FF0000LL) << 24 ) | \ ! ( (v & 0x00000000FF000000LL) << 8 ) | \ ! ( (v & 0x000000FF00000000LL) >> 8 ) | \ ! ( (v & 0x0000FF0000000000LL) >> 24 ) | \ ! ( (v & 0x00FF000000000000LL) >> 40 ) | \ ( ((v >> 56) & 0xFF)) ) |
From: Thomas H. <th...@us...> - 2005-11-29 20:15:28
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12399 Modified Files: Tag: branch_1_0 ctypes.h cfield.c _ctypes.c Log Message: Implement simple data types with different byte order (endian). Index: ctypes.h =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/ctypes.h,v retrieving revision 1.74.2.6 retrieving revision 1.74.2.7 diff -C2 -d -r1.74.2.6 -r1.74.2.7 *** ctypes.h 11 Nov 2005 08:10:26 -0000 1.74.2.6 --- ctypes.h 29 Nov 2005 20:15:17 -0000 1.74.2.7 *************** *** 159,162 **** --- 159,164 ---- GETFUNC getfunc; ffi_type *pffi_type; /* always statically allocated */ + SETFUNC setfunc_swapped; + GETFUNC getfunc_swapped; }; Index: cfield.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/cfield.c,v retrieving revision 1.74.2.7 retrieving revision 1.74.2.8 diff -C2 -d -r1.74.2.7 -r1.74.2.8 *** cfield.c 14 Nov 2005 18:43:31 -0000 1.74.2.7 --- cfield.c 29 Nov 2005 20:15:17 -0000 1.74.2.8 *************** *** 420,423 **** --- 420,451 ---- : v) + /* byte swapping macros */ + #define SWAP_2(v) \ + ( ( (v >> 8) & 0x00FF) | \ + ( (v << 8) & 0xFF00) ) + + #define SWAP_4(v) \ + ( ( (v & 0x000000FF) << 24 ) | \ + ( (v & 0x0000FF00) << 8 ) | \ + ( (v & 0x00FF0000) >> 8 ) | \ + ( ((v >> 24) & 0xFF)) ) + + #define SWAP_8(v) \ + ( ( (v & 0x00000000000000FF) << 56 ) | \ + ( (v & 0x000000000000FF00) << 40 ) | \ + ( (v & 0x0000000000FF0000) << 24 ) | \ + ( (v & 0x00000000FF000000) << 8 ) | \ + ( (v & 0x000000FF00000000) >> 8 ) | \ + ( (v & 0x0000FF0000000000) >> 24 ) | \ + ( (v & 0x00FF000000000000) >> 40 ) | \ + ( ((v >> 56) & 0xFF)) ) + + #define SWAP_INT SWAP_4 + + #if SIZEOF_LONG == 4 + # define SWAP_LONG SWAP_4 + #elif SIZEOF_LONG == 8 + # define SWAP_LONG SWAP_4 + #endif /***************************************************************** * The setter methods return an object which must be kept alive, to keep the *************** *** 495,498 **** --- 523,539 ---- static PyObject * + h_set_sw(void *ptr, PyObject *value, unsigned size) + { + long val; + short field; + if (get_long(value, &val) < 0) + return NULL; + field = SWAP_2(*(short *)ptr); + field = SET(field, (short)val, size); + *(short *)ptr = SWAP_2(field); + _RET(value); + } + + static PyObject * h_get(void *ptr, unsigned size) { *************** *** 503,506 **** --- 544,556 ---- static PyObject * + h_get_sw(void *ptr, unsigned size) + { + short val = *(short *)ptr; + val = SWAP_2(val); + GET_BITFIELD(val, size); + return PyInt_FromLong(val); + } + + static PyObject * H_set(void *ptr, PyObject *value, unsigned size) { *************** *** 513,521 **** } static PyObject * H_get(void *ptr, unsigned size) { ! unsigned short val = *(short *)ptr; GET_BITFIELD(val, size); return PyInt_FromLong(val); --- 563,593 ---- } + static PyObject * + H_set_sw(void *ptr, PyObject *value, unsigned size) + { + unsigned long val; + unsigned short field; + if (get_ulong(value, &val) < 0) + return NULL; + field = SWAP_2(*(unsigned short *)ptr); + field = SET(field, (unsigned short)val, size); + *(unsigned short *)ptr = SWAP_2(field); + _RET(value); + } + static PyObject * H_get(void *ptr, unsigned size) { ! unsigned short val = *(unsigned short *)ptr; ! GET_BITFIELD(val, size); ! return PyInt_FromLong(val); ! } ! ! static PyObject * ! H_get_sw(void *ptr, unsigned size) ! { ! unsigned short val = *(unsigned short *)ptr; ! val = SWAP_2(val); GET_BITFIELD(val, size); return PyInt_FromLong(val); *************** *** 532,535 **** --- 604,620 ---- } + static PyObject * + i_set_sw(void *ptr, PyObject *value, unsigned size) + { + long val; + int field; + if (get_long(value, &val) < 0) + return NULL; + field = SWAP_INT(*(int *)ptr); + field = SET(field, (int)val, size); + *(int *)ptr = SWAP_INT(field); + _RET(value); + } + static PyObject * *************** *** 541,544 **** --- 626,638 ---- } + static PyObject * + i_get_sw(void *ptr, unsigned size) + { + int val = *(int *)ptr; + val = SWAP_INT(val); + GET_BITFIELD(val, size); + return PyInt_FromLong(val); + } + #ifdef MS_WIN32 /* short BOOL - VARIANT_BOOL */ *************** *** 575,578 **** --- 669,685 ---- } + static PyObject * + I_set_sw(void *ptr, PyObject *value, unsigned size) + { + unsigned long val; + unsigned int field; + if (get_ulong(value, &val) < 0) + return NULL; + field = SWAP_INT(*(unsigned int *)val); + field = (unsigned int)SET(field, (unsigned int)val, size); + *(unsigned int *)ptr = field; + _RET(value); + } + static PyObject * *************** *** 585,588 **** --- 692,704 ---- static PyObject * + I_get_sw(void *ptr, unsigned size) + { + unsigned int val = *(unsigned int *)ptr; + val = SWAP_INT(val); + GET_BITFIELD(val, size); + return PyLong_FromUnsignedLong(val); + } + + static PyObject * l_set(void *ptr, PyObject *value, unsigned size) { *************** *** 594,597 **** --- 710,726 ---- } + static PyObject * + l_set_sw(void *ptr, PyObject *value, unsigned size) + { + long val; + long field; + if (get_long(value, &val) < 0) + return NULL; + field = *(long *)ptr; + field = (long)SET(field, val, size); + *(long *)ptr = SWAP_INT(field); + _RET(value); + } + static PyObject * *************** *** 604,607 **** --- 733,745 ---- static PyObject * + l_get_sw(void *ptr, unsigned size) + { + long val = *(long *)ptr; + val = SWAP_INT(val); + GET_BITFIELD(val, size); + return PyInt_FromLong(val); + } + + static PyObject * L_set(void *ptr, PyObject *value, unsigned size) { *************** *** 613,616 **** --- 751,767 ---- } + static PyObject * + L_set_sw(void *ptr, PyObject *value, unsigned size) + { + unsigned long val; + unsigned long field; + if (get_ulong(value, &val) < 0) + return NULL; + field = SWAP_LONG(*(unsigned long *)ptr); + field = (unsigned long)SET(field, val, size); + *(unsigned long *)ptr = SWAP_LONG(field); + _RET(value); + } + static PyObject * *************** *** 622,625 **** --- 773,785 ---- } + static PyObject * + L_get_sw(void *ptr, unsigned size) + { + unsigned long val = *(unsigned long *)ptr; + val = SWAP_LONG(val); + GET_BITFIELD(val, size); + return PyLong_FromUnsignedLong(val); + } + #ifdef HAVE_LONG_LONG static PyObject * *************** *** 634,637 **** --- 794,810 ---- static PyObject * + q_set_sw(void *ptr, PyObject *value, unsigned size) + { + PY_LONG_LONG val; + PY_LONG_LONG field; + if (get_longlong(value, &val) < 0) + return NULL; + field = SWAP_8(*(PY_LONG_LONG *)ptr); + field = (PY_LONG_LONG)SET(field, val, size); + *(PY_LONG_LONG *)ptr = SWAP_8(field); + _RET(value); + } + + static PyObject * q_get(void *ptr, unsigned size) { *************** *** 642,645 **** --- 815,827 ---- static PyObject * + q_get_sw(void *ptr, unsigned size) + { + PY_LONG_LONG val = *(PY_LONG_LONG *)ptr; + val = SWAP_8(val); + GET_BITFIELD(val, size); + return PyLong_FromLongLong(val); + } + + static PyObject * Q_set(void *ptr, PyObject *value, unsigned size) { *************** *** 652,655 **** --- 834,850 ---- static PyObject * + Q_set_sw(void *ptr, PyObject *value, unsigned size) + { + unsigned PY_LONG_LONG val; + unsigned PY_LONG_LONG field; + if (get_ulonglong(value, &val) < 0) + return NULL; + field = SWAP_8(*(unsigned PY_LONG_LONG *)ptr); + field = (unsigned PY_LONG_LONG)SET(field, val, size); + *(unsigned PY_LONG_LONG *)ptr = SWAP_8(field); + _RET(value); + } + + static PyObject * Q_get(void *ptr, unsigned size) { *************** *** 658,661 **** --- 853,865 ---- return PyLong_FromUnsignedLongLong(val); } + + static PyObject * + Q_get_sw(void *ptr, unsigned size) + { + unsigned PY_LONG_LONG val = *(unsigned PY_LONG_LONG *)ptr; + val = SWAP_8(val); + GET_BITFIELD(val, size); + return PyLong_FromUnsignedLongLong(val); + } #endif *************** *** 1136,1159 **** { 'B', B_set, B_get, &ffi_type_uchar}, { 'c', c_set, c_get, &ffi_type_schar}, ! { 'd', d_set, d_get, &ffi_type_double}, ! { 'f', f_set, f_get, &ffi_type_float}, ! { 'h', h_set, h_get, &ffi_type_sshort}, ! { 'H', H_set, H_get, &ffi_type_ushort}, ! { 'i', i_set, i_get, &ffi_type_sint}, ! { 'I', I_set, I_get, &ffi_type_uint}, /* XXX Hm, sizeof(int) == sizeof(long) doesn't hold on every platform */ /* As soon as we can get rid of the type codes, this is no longer a problem */ #if SIZEOF_LONG == 4 ! { 'l', l_set, l_get, &ffi_type_sint}, ! { 'L', L_set, L_get, &ffi_type_uint}, #elif SIZEOF_LONG == 8 ! { 'l', l_set, l_get, &ffi_type_slong}, ! { 'L', L_set, L_get, &ffi_type_ulong}, #else # error #endif #ifdef HAVE_LONG_LONG ! { 'q', q_set, q_get, &ffi_type_slong}, ! { 'Q', Q_set, Q_get, &ffi_type_ulong}, #endif { 'P', P_set, P_get, &ffi_type_pointer}, --- 1340,1363 ---- { 'B', B_set, B_get, &ffi_type_uchar}, { 'c', c_set, c_get, &ffi_type_schar}, ! { 'd', d_set, d_get, &ffi_type_double/*, d_set_sw, d_get_sw*/}, ! { 'f', f_set, f_get, &ffi_type_float/*, f_set_sw, f_get_sw*/}, ! { 'h', h_set, h_get, &ffi_type_sshort, h_set_sw, h_get_sw}, ! { 'H', H_set, H_get, &ffi_type_ushort, H_set_sw, H_get_sw}, ! { 'i', i_set, i_get, &ffi_type_sint, i_set_sw, i_get_sw}, ! { 'I', I_set, I_get, &ffi_type_uint, I_set_sw, I_get_sw}, /* XXX Hm, sizeof(int) == sizeof(long) doesn't hold on every platform */ /* As soon as we can get rid of the type codes, this is no longer a problem */ #if SIZEOF_LONG == 4 ! { 'l', l_set, l_get, &ffi_type_sint, l_set_sw, l_get_sw}, ! { 'L', L_set, L_get, &ffi_type_uint, L_set_sw, L_get_sw}, #elif SIZEOF_LONG == 8 ! { 'l', l_set, l_get, &ffi_type_slong, l_set_sw, l_get_sw}, ! { 'L', L_set, L_get, &ffi_type_ulong, L_set_sw, L_get_sw}, #else # error #endif #ifdef HAVE_LONG_LONG ! { 'q', q_set, q_get, &ffi_type_slong, q_set_sw, q_get_sw}, ! { 'Q', Q_set, Q_get, &ffi_type_ulong, Q_set_sw, Q_get_sw}, #endif { 'P', P_set, P_get, &ffi_type_pointer}, Index: _ctypes.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes.c,v retrieving revision 1.226.2.36 retrieving revision 1.226.2.37 diff -C2 -d -r1.226.2.36 -r1.226.2.37 *** _ctypes.c 8 Nov 2005 20:34:23 -0000 1.226.2.36 --- _ctypes.c 29 Nov 2005 20:15:17 -0000 1.226.2.37 *************** *** 1230,1233 **** --- 1230,1295 ---- #endif + static PyObject *CreateSwappedType(PyTypeObject *type, PyObject *args, PyObject *kwds, + PyObject *proto, struct fielddesc *fmt) + { + PyTypeObject *result; + StgDictObject *stgdict; + PyObject *name = PyTuple_GET_ITEM(args, 0); + PyObject *swapped_args = PyTuple_New(PyTuple_GET_SIZE(args)); + static PyObject *suffix; + int i; + + if (suffix == NULL) + #ifdef IS_BIG_ENDIAN + suffix = PyString_FromString("_le"); + #else + suffix = PyString_FromString("_be"); + #endif + + Py_INCREF(suffix); + PyString_ConcatAndDel(&name, suffix); + + PyTuple_SET_ITEM(swapped_args, 0, name); + for (i=1; i<PyTuple_GET_SIZE(args); ++i) { + PyObject *v = PyTuple_GET_ITEM(args, i); + Py_INCREF(v); + PyTuple_SET_ITEM(swapped_args, i, v); + } + + /* create the new instance (which is a class, + since we are a metatype!) */ + result = (PyTypeObject *)PyType_Type.tp_new(type, swapped_args, kwds); + Py_DECREF(swapped_args); + if (result == NULL) + return NULL; + + stgdict = (StgDictObject *)PyObject_CallObject( + (PyObject *)&StgDict_Type, NULL); + if (!stgdict) /* XXX leaks result! */ + return NULL; + + stgdict->ffi_type = *fmt->pffi_type; + stgdict->align = fmt->pffi_type->alignment; + stgdict->length = 0; + stgdict->size = fmt->pffi_type->size; + stgdict->setfunc = fmt->setfunc_swapped; + stgdict->getfunc = fmt->getfunc_swapped; + + Py_INCREF(proto); + stgdict->proto = proto; + + /* replace the class dict by our updated spam dict */ + if (-1 == PyDict_Update((PyObject *)stgdict, result->tp_dict)) { + Py_DECREF(result); + Py_DECREF((PyObject *)stgdict); + return NULL; + } + Py_DECREF(result->tp_dict); + result->tp_dict = (PyObject *)stgdict; + + return (PyObject *)result; + } + + static PyObject * SimpleType_new(PyTypeObject *type, PyObject *args, PyObject *kwds) *************** *** 1341,1344 **** --- 1403,1427 ---- } } + + if (type == &SimpleType_Type && fmt->setfunc_swapped && fmt->getfunc_swapped) { + PyObject *swapped = CreateSwappedType(type, args, kwds, + proto, fmt); + if (swapped == NULL) { + Py_DECREF(result); + return NULL; + } + #ifdef IS_BIG_ENDIAN + PyObject_SetAttrString((PyObject *)result, "__ctype_le__", swapped); + PyObject_SetAttrString((PyObject *)result, "__ctype_be__", (PyObject *)result); + PyObject_SetAttrString(swapped, "__ctype_be__", (PyObject *)result); + PyObject_SetAttrString(swapped, "__ctype_le__", swapped); + #else + PyObject_SetAttrString((PyObject *)result, "__ctype_be__", swapped); + PyObject_SetAttrString((PyObject *)result, "__ctype_le__", (PyObject *)result); + PyObject_SetAttrString(swapped, "__ctype_le__", (PyObject *)result); + PyObject_SetAttrString(swapped, "__ctype_be__", swapped); + #endif + }; + return (PyObject *)result; } |
From: Thomas H. <th...@us...> - 2005-11-29 20:15:18
|
Update of /cvsroot/ctypes/ctypes/ctypes/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12323 Modified Files: Tag: branch_1_0 test_byteswap.py Log Message: Implement simple data types with different byte order (endian). Index: test_byteswap.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/test/Attic/test_byteswap.py,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -C2 -d -r1.1.2.2 -r1.1.2.3 *** test_byteswap.py 10 Nov 2005 21:14:55 -0000 1.1.2.2 --- test_byteswap.py 29 Nov 2005 20:15:05 -0000 1.1.2.3 *************** *** 7,21 **** requires("swap") ! class BITS(Structure): ! _fields_ = [("i%d" % i, c_uint, 1) for i in range(32)] ! for i in range(32): ! print getattr(BITS, "i%d" % i) ! def dump(s): ! print hexlify(buffer(s)) class Test(unittest.TestCase): ! def test(self): print sys.byteorder for i in range(32): --- 7,31 ---- requires("swap") ! ##class BITS(Structure): ! ## _fields_ = [("i%d" % i, c_uint, 1) for i in range(32)] ! ##for i in range(32): ! ## print getattr(BITS, "i%d" % i) ! ##def dump(s): ! ## print hexlify(buffer(s)) ! ! def bin(s): ! return hexlify(buffer(s)).upper() ! ! # Each *simple* type that supports different byte orders has an ! # __ctype_be__ attribute that specifies the same type in BIG ENDIAN ! # byte order, and a __ctype_le__ attribute that is the same type in ! # LITTLE ENDIAN byte order. ! # ! # For Structures and Unions, these types are created on demand. class Test(unittest.TestCase): ! def X_test(self): print sys.byteorder for i in range(32): *************** *** 24,27 **** --- 34,119 ---- dump(bits) + def test_endian_short(self): + if sys.byteorder == "little": + self.failUnless(c_short.__ctype_le__ is c_short) + self.failUnless(c_short.__ctype_be__.__ctype_le__ is c_short) + else: + self.failUnless(c_short.__ctype_be__ is c_short) + self.failUnless(c_short.__ctype_le__.__ctype_be__ is c_short) + s = c_short.__ctype_be__(0x1234) + self.failUnlessEqual(bin(s), "1234") + self.failUnlessEqual(s.value, 0x1234) + + s = c_short.__ctype_le__(0x1234) + self.failUnlessEqual(bin(s), "3412") + self.failUnlessEqual(s.value, 0x1234) + + s = c_ushort.__ctype_be__(0x1234) + self.failUnlessEqual(bin(s), "1234") + self.failUnlessEqual(s.value, 0x1234) + + s = c_ushort.__ctype_le__(0x1234) + self.failUnlessEqual(bin(s), "3412") + self.failUnlessEqual(s.value, 0x1234) + + def test_endian_int(self): + if sys.byteorder == "little": + self.failUnless(c_int.__ctype_le__ is c_int) + self.failUnless(c_int.__ctype_be__.__ctype_le__ is c_int) + else: + self.failUnless(c_int.__ctype_be__ is c_int) + self.failUnless(c_int.__ctype_le__.__ctype_be__ is c_int) + + s = c_int.__ctype_be__(0x12345678) + self.failUnlessEqual(bin(s), "12345678") + self.failUnlessEqual(s.value, 0x12345678) + + s = c_int.__ctype_le__(0x12345678) + self.failUnlessEqual(bin(s), "78563412") + self.failUnlessEqual(s.value, 0x12345678) + + s = c_uint.__ctype_be__(0x12345678) + self.failUnlessEqual(bin(s), "12345678") + self.failUnlessEqual(s.value, 0x12345678) + + s = c_uint.__ctype_le__(0x12345678) + self.failUnlessEqual(bin(s), "78563412") + self.failUnlessEqual(s.value, 0x12345678) + + def test_endian_longlong(self): + if sys.byteorder == "little": + self.failUnless(c_longlong.__ctype_le__ is c_longlong) + self.failUnless(c_longlong.__ctype_be__.__ctype_le__ is c_longlong) + else: + self.failUnless(c_longlong.__ctype_be__ is c_longlong) + self.failUnless(c_longlong.__ctype_le__.__ctype_be__ is c_longlong) + + s = c_longlong.__ctype_be__(0x1234567890ABCDEF) + self.failUnlessEqual(bin(s), "1234567890ABCDEF") + self.failUnlessEqual(s.value, 0x1234567890ABCDEF) + + s = c_longlong.__ctype_le__(0x1234567890ABCDEF) + self.failUnlessEqual(bin(s), "EFCDAB9078563412") + self.failUnlessEqual(s.value, 0x1234567890ABCDEF) + + s = c_ulonglong.__ctype_be__(0x1234567890ABCDEF) + self.failUnlessEqual(bin(s), "1234567890ABCDEF") + self.failUnlessEqual(s.value, 0x1234567890ABCDEF) + + s = c_ulonglong.__ctype_le__(0x1234567890ABCDEF) + self.failUnlessEqual(bin(s), "EFCDAB9078563412") + self.failUnlessEqual(s.value, 0x1234567890ABCDEF) + + def test_endian_other(self): + self.failUnless(c_byte.__ctype_le__ is c_byte) + self.failUnless(c_byte.__ctype_be__ is c_byte) + + self.failUnless(c_ubyte.__ctype_le__ is c_ubyte) + self.failUnless(c_ubyte.__ctype_be__ is c_ubyte) + + self.failUnless(c_char.__ctype_le__ is c_char) + self.failUnless(c_char.__ctype_be__ is c_char) + + if __name__ == "__main__": unittest.main() |
From: Thomas H. <th...@us...> - 2005-11-29 20:15:05
|
Update of /cvsroot/ctypes/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12308 Modified Files: Tag: branch_1_0 __init__.py Log Message: Implement simple data types with different byte order (endian). Index: __init__.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/__init__.py,v retrieving revision 1.61.2.13 retrieving revision 1.61.2.14 diff -C2 -d -r1.61.2.13 -r1.61.2.14 *** __init__.py 8 Nov 2005 20:34:48 -0000 1.61.2.13 --- __init__.py 29 Nov 2005 20:14:57 -0000 1.61.2.14 *************** *** 170,173 **** --- 170,174 ---- class c_ubyte(_SimpleCData): _type_ = "B" + c_ubyte.__ctype_le__ = c_ubyte.__ctype_be__ = c_ubyte # backward compatibility: ##c_uchar = c_ubyte *************** *** 175,181 **** --- 176,184 ---- class c_byte(_SimpleCData): _type_ = "b" + c_byte.__ctype_le__ = c_byte.__ctype_be__ = c_byte class c_char(_SimpleCData): _type_ = "c" + c_char.__ctype_le__ = c_char.__ctype_be__ = c_char class c_char_p(_SimpleCData): |
From: Thomas H. <th...@us...> - 2005-11-18 14:48:03
|
Update of /cvsroot/ctypes/ctypes/ctypes/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21325 Modified Files: Tag: endian_branch test_byteswap.py Log Message: *** empty log message *** Index: test_byteswap.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/test/Attic/test_byteswap.py,v retrieving revision 1.1.2.2.2.5 retrieving revision 1.1.2.2.2.6 diff -C2 -d -r1.1.2.2.2.5 -r1.1.2.2.2.6 *** test_byteswap.py 18 Nov 2005 14:27:05 -0000 1.1.2.2.2.5 --- test_byteswap.py 18 Nov 2005 14:47:56 -0000 1.1.2.2.2.6 *************** *** 31,41 **** --- 31,50 ---- ("n8", c_int, 4)] + class X(Union): + _fields_ = [("nibbles", Nibbles), + ("int", c_uint)] + n = Nibbles(1, 2, 3, 4, 5, 6, 7, 8) + x = X() + x.nibbles = n + for name, typ, bits in Nibbles._fields_: print name, getattr(Nibbles, name) print "sys.byteorder:", sys.byteorder + print "int", hex(x.int) dump(n) + dump(x) sys.exit() |
From: Thomas H. <th...@us...> - 2005-11-18 14:45:27
|
Update of /cvsroot/ctypes/ctypes/ctypes/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20698 Modified Files: Tag: endian_branch endian.c Log Message: *** empty log message *** Index: endian.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/test/Attic/endian.c,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -C2 -d -r1.1.2.2 -r1.1.2.3 *** endian.c 18 Nov 2005 14:43:32 -0000 1.1.2.2 --- endian.c 18 Nov 2005 14:45:18 -0000 1.1.2.3 *************** *** 28,31 **** --- 28,34 ---- p = (unsigned char *)&n; + printf("As int: %08X\n", n); + + printf("As bytes: "); for (i = 0; i < 4; ++i) printf("%02X ", p[i]); |
From: Thomas H. <th...@us...> - 2005-11-18 14:43:40
|
Update of /cvsroot/ctypes/ctypes/ctypes/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20234 Modified Files: Tag: endian_branch endian.c Log Message: *** empty log message *** Index: endian.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/test/Attic/endian.c,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -C2 -d -r1.1.2.1 -r1.1.2.2 *** endian.c 18 Nov 2005 14:33:47 -0000 1.1.2.1 --- endian.c 18 Nov 2005 14:43:32 -0000 1.1.2.2 *************** *** 14,17 **** --- 14,20 ---- int main(int argc, char **argv) { + unsigned char *p; + int i; + n.N1 = 1; n.N2 = 2; *************** *** 23,26 **** n.N8 = 8; ! printf("%08X\n", n); } --- 26,33 ---- n.N8 = 8; ! p = (unsigned char *)&n; ! ! for (i = 0; i < 4; ++i) ! printf("%02X ", p[i]); ! printf("\n"); } |
From: Thomas H. <th...@us...> - 2005-11-18 14:33:55
|
Update of /cvsroot/ctypes/ctypes/ctypes/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18043 Added Files: Tag: endian_branch endian.c Log Message: C test program. --- NEW FILE: endian.c --- #include <stdio.h> struct Nibbles { int N1 : 4; int N2 : 4; int N3 : 4; int N4 : 4; int N5 : 4; int N6 : 4; int N7 : 4; int N8 : 4; } n; int main(int argc, char **argv) { n.N1 = 1; n.N2 = 2; n.N3 = 3; n.N4 = 4; n.N5 = 5; n.N6 = 6; n.N7 = 7; n.N8 = 8; printf("%08X\n", n); } |
From: Thomas H. <th...@us...> - 2005-11-18 14:27:15
|
Update of /cvsroot/ctypes/ctypes/ctypes/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16801 Modified Files: Tag: endian_branch test_byteswap.py Log Message: Another check. Index: test_byteswap.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/test/Attic/test_byteswap.py,v retrieving revision 1.1.2.2.2.4 retrieving revision 1.1.2.2.2.5 diff -C2 -d -r1.1.2.2.2.4 -r1.1.2.2.2.5 *** test_byteswap.py 18 Nov 2005 14:20:00 -0000 1.1.2.2.2.4 --- test_byteswap.py 18 Nov 2005 14:27:05 -0000 1.1.2.2.2.5 *************** *** 33,36 **** --- 33,39 ---- n = Nibbles(1, 2, 3, 4, 5, 6, 7, 8) + for name, typ, bits in Nibbles._fields_: + print name, getattr(Nibbles, name) + print "sys.byteorder:", sys.byteorder dump(n) |
From: Thomas H. <th...@us...> - 2005-11-18 14:20:19
|
Update of /cvsroot/ctypes/ctypes/ctypes/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15082 Modified Files: Tag: endian_branch test_byteswap.py Log Message: Check. Index: test_byteswap.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/test/Attic/test_byteswap.py,v retrieving revision 1.1.2.2.2.3 retrieving revision 1.1.2.2.2.4 diff -C2 -d -r1.1.2.2.2.3 -r1.1.2.2.2.4 *** test_byteswap.py 17 Nov 2005 21:10:59 -0000 1.1.2.2.2.3 --- test_byteswap.py 18 Nov 2005 14:20:00 -0000 1.1.2.2.2.4 *************** *** 19,22 **** --- 19,40 ---- return binascii.hexlify(buffer(s)) + if __name__ == "__main__": + from ctypes import c_int, Structure + class Nibbles(Structure): + _fields_ = [("n1", c_int, 4), + ("n2", c_int, 4), + ("n3", c_int, 4), + ("n4", c_int, 4), + ("n5", c_int, 4), + ("n6", c_int, 4), + ("n7", c_int, 4), + ("n8", c_int, 4)] + + n = Nibbles(1, 2, 3, 4, 5, 6, 7, 8) + + print "sys.byteorder:", sys.byteorder + dump(n) + + sys.exit() class Test(unittest.TestCase): |
From: Thomas H. <th...@us...> - 2005-11-17 21:11:11
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12444 Modified Files: Tag: endian_branch cfield.c Log Message: Save the current work state - swapped structures containing arrays do not yet work. The _swapped_type_ attribute must be available on every type that will be used in a byte swapped Structure. Index: cfield.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/cfield.c,v retrieving revision 1.74.2.7.2.2 retrieving revision 1.74.2.7.2.3 diff -C2 -d -r1.74.2.7.2.2 -r1.74.2.7.2.3 *** cfield.c 17 Nov 2005 20:57:16 -0000 1.74.2.7.2.2 --- cfield.c 17 Nov 2005 21:11:04 -0000 1.74.2.7.2.3 *************** *** 94,102 **** if (ENDIAN_NESS != big_endian) { /* non-native byte order */ ! PyObject *swapped_proto = PyObject_GetAttrString(desc, "_swapped_"); #ifdef _DEBUG ! _asm int 3; #endif - if (swapped_proto == NULL) { PyErr_SetString(PyExc_TypeError, "This field type does not support byte swapping"); --- 94,104 ---- if (ENDIAN_NESS != big_endian) { /* non-native byte order */ ! PyObject *swapped_proto = PyObject_GetAttrString(desc, "_swapped_type_"); ! if (swapped_proto == NULL) { #ifdef _DEBUG ! PyTypeObject *type = (PyTypeObject *)desc; /* for the debugger */ ! StgDictObject *td = PyType_stgdict(type); /* ditto */ ! _asm int 3; #endif PyErr_SetString(PyExc_TypeError, "This field type does not support byte swapping"); |
From: Thomas H. <th...@us...> - 2005-11-17 21:11:06
|
Update of /cvsroot/ctypes/ctypes/ctypes/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12423 Modified Files: Tag: endian_branch test_byteswap.py Log Message: Save the current work state - swapped structures containing arrays do not yet work. The _swapped_type_ attribute must be available on every type that will be used in a byte swapped Structure. Index: test_byteswap.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/test/Attic/test_byteswap.py,v retrieving revision 1.1.2.2.2.2 retrieving revision 1.1.2.2.2.3 diff -C2 -d -r1.1.2.2.2.2 -r1.1.2.2.2.3 *** test_byteswap.py 17 Nov 2005 20:57:11 -0000 1.1.2.2.2.2 --- test_byteswap.py 17 Nov 2005 21:10:59 -0000 1.1.2.2.2.3 *************** *** 29,33 **** self.failUnlessEqual(hexlify(x), "1234") self.failUnlessEqual(hex(x.value), "0x1234") ! self.failUnless(c_short._swapped_ is c_short_swapped) def test_short_swapped(self): --- 29,33 ---- self.failUnlessEqual(hexlify(x), "1234") self.failUnlessEqual(hex(x.value), "0x1234") ! self.failUnless(c_short._swapped_type_ is c_short_swapped) def test_short_swapped(self): *************** *** 38,42 **** self.failUnlessEqual(hexlify(x), "3412") self.failUnlessEqual(hex(x.value), "0x1234") ! self.failUnless(c_short_swapped._swapped_ is c_short) def test_short_struct(self): --- 38,42 ---- self.failUnlessEqual(hexlify(x), "3412") self.failUnlessEqual(hex(x.value), "0x1234") ! self.failUnless(c_short_swapped._swapped_type_ is c_short) def test_short_struct(self): *************** *** 59,63 **** self.failUnlessEqual(hexlify(p), "34127856") self.failUnlessEqual(hexlify(q), "12345678") ! def test(self): --- 59,82 ---- self.failUnlessEqual(hexlify(p), "34127856") self.failUnlessEqual(hexlify(q), "12345678") ! ! def test_short_struct_array(self): ! print "DISABLED!" ! return ! class P(Structure): ! _swapped_ = True ! _fields_ = [("x", c_short * 2)] ! ! class Q(Structure): ! _fields_ = [("x", c_short * 2)] ! ! q = Q(0x1234, 0x5678) ! p = P(0x1234, 0x5678) ! ! if sys.byteorder == "little": ! self.failUnlessEqual(hexlify(q), "34127856") ! self.failUnlessEqual(hexlify(p), "12345678") ! else: ! self.failUnlessEqual(hexlify(p), "34127856") ! self.failUnlessEqual(hexlify(q), "12345678") def test(self): |
From: Thomas H. <th...@us...> - 2005-11-17 21:11:02
|
Update of /cvsroot/ctypes/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12402 Modified Files: Tag: endian_branch __init__.py Log Message: Save the current work state - swapped structures containing arrays do not yet work. The _swapped_type_ attribute must be available on every type that will be used in a byte swapped Structure. Index: __init__.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/__init__.py,v retrieving revision 1.61.2.13.2.2 retrieving revision 1.61.2.13.2.3 diff -C2 -d -r1.61.2.13.2.2 -r1.61.2.13.2.3 *** __init__.py 17 Nov 2005 20:22:28 -0000 1.61.2.13.2.2 --- __init__.py 17 Nov 2005 21:10:54 -0000 1.61.2.13.2.3 *************** *** 130,135 **** class c_short_swapped(_SimpleCData): _type_ = "h" ! _swapped_ = c_short ! c_short._swapped_ = c_short_swapped class c_ushort(_SimpleCData): --- 130,137 ---- class c_short_swapped(_SimpleCData): _type_ = "h" ! _swapped_ = True ! ! c_short_swapped._swapped_type_ = c_short ! c_short._swapped_type_ = c_short_swapped class c_ushort(_SimpleCData): |