ctypes-commit Mailing List for ctypes (Page 87)
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...> - 2004-10-19 09:38:46
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7425 Modified Files: test_cfuncs.py Log Message: Works on Win and OS X. Index: test_cfuncs.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_cfuncs.py,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** test_cfuncs.py 19 Oct 2004 09:26:43 -0000 1.18 --- test_cfuncs.py 19 Oct 2004 09:38:28 -0000 1.19 *************** *** 5,193 **** from ctypes import * - # These two functions report the argument in the last call to one of - # the tf_? functions. - import _ctypes_test - testdll = CDLL(_ctypes_test.__file__) - - def S(): - return c_longlong.in_dll(testdll, "last_tf_arg_s").value - def U(): - return c_ulonglong.in_dll(testdll, "last_tf_arg_u").value class CFunctions(unittest.TestCase): def test_byte(self): ! testdll.tf_b.restype = c_byte ! testdll.tf_b.argtypes = (c_byte,) ! self.failUnlessEqual(testdll.tf_b(-126), -42) ! self.failUnlessEqual(S(), -126) def test_byte_plus(self): ! testdll.tf_bb.restype = c_byte ! testdll.tf_bb.argtypes = (c_byte, c_byte) ! self.failUnlessEqual(testdll.tf_bb(0, -126), -42) ! self.failUnlessEqual(S(), -126) def test_ubyte(self): ! testdll.tf_B.restype = c_ubyte ! testdll.tf_B.argtypes = (c_ubyte,) ! self.failUnlessEqual(testdll.tf_B(255), 85) ! self.failUnlessEqual(U(), 255) def test_ubyte_plus(self): ! testdll.tf_bB.restype = c_ubyte ! testdll.tf_bB.argtypes = (c_byte, c_ubyte) ! self.failUnlessEqual(testdll.tf_bB(0, 255), 85) ! self.failUnlessEqual(U(), 255) def test_short(self): ! testdll.tf_h.restype = c_short ! self.failUnlessEqual(testdll.tf_h(-32766), -10922) ! self.failUnlessEqual(S(), -32766) def test_short_plus(self): ! testdll.tf_bh.restype = c_short ! self.failUnlessEqual(testdll.tf_bh(0, -32766), -10922) ! self.failUnlessEqual(S(), -32766) def test_ushort(self): ! testdll.tf_H.restype = c_ushort ! self.failUnlessEqual(testdll.tf_H(65535), 21845) ! self.failUnlessEqual(U(), 65535) def test_ushort_plus(self): ! testdll.tf_bH.restype = c_ushort ! self.failUnlessEqual(testdll.tf_bH(0, 65535), 21845) ! self.failUnlessEqual(U(), 65535) def test_int(self): ! testdll.tf_i.restype = c_int ! self.failUnlessEqual(testdll.tf_i(-2147483646), -715827882) ! self.failUnlessEqual(S(), -2147483646) def test_int_plus(self): ! testdll.tf_bi.restype = c_int ! self.failUnlessEqual(testdll.tf_bi(0, -2147483646), -715827882) ! self.failUnlessEqual(S(), -2147483646) def test_uint(self): ! testdll.tf_I.restype = c_uint ! self.failUnlessEqual(testdll.tf_I(4294967295), 1431655765) ! self.failUnlessEqual(U(), 4294967295) def test_uint_plus(self): ! testdll.tf_bI.restype = c_uint ! self.failUnlessEqual(testdll.tf_bI(0, 4294967295), 1431655765) ! self.failUnlessEqual(U(), 4294967295) def test_long(self): ! testdll.tf_l.restype = c_long ! testdll.tf_l.argtypes = (c_long,) ! self.failUnlessEqual(testdll.tf_l(-2147483646), -715827882) ! self.failUnlessEqual(S(), -2147483646) def test_long_plus(self): ! testdll.tf_bl.restype = c_long ! testdll.tf_bl.argtypes = (c_byte, c_long) ! self.failUnlessEqual(testdll.tf_bl(0, -2147483646), -715827882) ! self.failUnlessEqual(S(), -2147483646) def test_ulong(self): ! testdll.tf_L.restype = c_ulong ! self.failUnlessEqual(testdll.tf_L(4294967295), 1431655765) ! self.failUnlessEqual(U(), 4294967295) def test_ulong_plus(self): ! testdll.tf_bL.restype = c_ulong ! self.failUnlessEqual(testdll.tf_bL(0, 4294967295), 1431655765) ! self.failUnlessEqual(U(), 4294967295) def test_longlong(self): ! testdll.tf_q.restype = c_longlong ! testdll.tf_q.argtypes = (c_longlong, ) ! self.failUnlessEqual(testdll.tf_q(-9223372036854775806), -3074457345618258602) ! self.failUnlessEqual(S(), -9223372036854775806) def test_longlong_plus(self): ! testdll.tf_bq.restype = c_longlong ! testdll.tf_bq.argtypes = (c_byte, c_longlong) ! self.failUnlessEqual(testdll.tf_bq(0, -9223372036854775806), -3074457345618258602) ! self.failUnlessEqual(S(), -9223372036854775806) def test_ulonglong(self): ! testdll.tf_Q.restype = c_ulonglong ! testdll.tf_Q.argtypes = (c_ulonglong, ) ! self.failUnlessEqual(testdll.tf_Q(18446744073709551615), 6148914691236517205) ! self.failUnlessEqual(U(), 18446744073709551615) def test_ulonglong_plus(self): ! testdll.tf_bQ.restype = c_ulonglong ! testdll.tf_bQ.argtypes = (c_byte, c_ulonglong) ! self.failUnlessEqual(testdll.tf_bQ(0, 18446744073709551615), 6148914691236517205) ! self.failUnlessEqual(U(), 18446744073709551615) def test_float(self): ! testdll.tf_f.restype = c_float ! testdll.tf_f.argtypes = (c_float,) ! self.failUnlessEqual(testdll.tf_f(-42.), -14.) ! self.failUnlessEqual(S(), -42) def test_float_plus(self): ! testdll.tf_bf.restype = c_float ! testdll.tf_bf.argtypes = (c_byte, c_float) ! self.failUnlessEqual(testdll.tf_bf(0, -42.), -14.) ! self.failUnlessEqual(S(), -42) def test_double(self): ! testdll.tf_d.restype = c_double ! testdll.tf_d.argtypes = (c_double,) ! self.failUnlessEqual(testdll.tf_d(42.), 14.) ! self.failUnlessEqual(S(), 42) def test_double_plus(self): ! testdll.tf_bd.restype = c_double ! testdll.tf_bd.argtypes = (c_byte, c_double) ! self.failUnlessEqual(testdll.tf_bd(0, 42.), 14.) ! self.failUnlessEqual(S(), 42) def test_callwithresult(self): def process_result(result): return result * 2 ! testdll.tf_i.restype = process_result ! testdll.tf_i.argtypes = (c_int,) ! self.failUnlessEqual(testdll.tf_i(42), 28) ! self.failUnlessEqual(S(), 42) ! self.failUnlessEqual(testdll.tf_i(-42), -28) ! self.failUnlessEqual(S(), -42) def test_void(self): ! testdll.tv_i.restype = None ! testdll.tv_i.argtypes = (c_int,) ! self.failUnlessEqual(testdll.tv_i(42), None) ! self.failUnlessEqual(S(), 42) ! self.failUnlessEqual(testdll.tv_i(-42), None) ! self.failUnlessEqual(S(), -42) # The following repeates the above tests with stdcall functions (where # they are available) ! ##try: ! ## WinDLL ! ##except NameError: ! ## pass ! ##else: ! ## class stdcall_dll(WinDLL): ! ## def __getattr__(self, name): ! ## if name[:2] == '__' and name[-2:] == '__': ! ## raise AttributeError, name ! ## func = self._StdcallFuncPtr("s_" + name, self) ! ## setattr(self, name, func) ! ## return func ! ! ## class stdcallCFunctions(CFunctions): ! ## def __init__(self, *args): ! ## unittest.TestCase.__init__(self, *args) ! ## testdll = stdcall_dll(find_test_dll()) if __name__ == '__main__': --- 5,188 ---- from ctypes import * import _ctypes_test class CFunctions(unittest.TestCase): + _dll = CDLL(_ctypes_test.__file__) + + def S(self): + return c_longlong.in_dll(self._dll, "last_tf_arg_s").value + def U(self): + return c_ulonglong.in_dll(self._dll, "last_tf_arg_u").value def test_byte(self): ! self._dll.tf_b.restype = c_byte ! self._dll.tf_b.argtypes = (c_byte,) ! self.failUnlessEqual(self._dll.tf_b(-126), -42) ! self.failUnlessEqual(self.S(), -126) def test_byte_plus(self): ! self._dll.tf_bb.restype = c_byte ! self._dll.tf_bb.argtypes = (c_byte, c_byte) ! self.failUnlessEqual(self._dll.tf_bb(0, -126), -42) ! self.failUnlessEqual(self.S(), -126) def test_ubyte(self): ! self._dll.tf_B.restype = c_ubyte ! self._dll.tf_B.argtypes = (c_ubyte,) ! self.failUnlessEqual(self._dll.tf_B(255), 85) ! self.failUnlessEqual(self.U(), 255) def test_ubyte_plus(self): ! self._dll.tf_bB.restype = c_ubyte ! self._dll.tf_bB.argtypes = (c_byte, c_ubyte) ! self.failUnlessEqual(self._dll.tf_bB(0, 255), 85) ! self.failUnlessEqual(self.U(), 255) def test_short(self): ! self._dll.tf_h.restype = c_short ! self.failUnlessEqual(self._dll.tf_h(-32766), -10922) ! self.failUnlessEqual(self.S(), -32766) def test_short_plus(self): ! self._dll.tf_bh.restype = c_short ! self.failUnlessEqual(self._dll.tf_bh(0, -32766), -10922) ! self.failUnlessEqual(self.S(), -32766) def test_ushort(self): ! self._dll.tf_H.restype = c_ushort ! self.failUnlessEqual(self._dll.tf_H(65535), 21845) ! self.failUnlessEqual(self.U(), 65535) def test_ushort_plus(self): ! self._dll.tf_bH.restype = c_ushort ! self.failUnlessEqual(self._dll.tf_bH(0, 65535), 21845) ! self.failUnlessEqual(self.U(), 65535) def test_int(self): ! self._dll.tf_i.restype = c_int ! self.failUnlessEqual(self._dll.tf_i(-2147483646), -715827882) ! self.failUnlessEqual(self.S(), -2147483646) def test_int_plus(self): ! self._dll.tf_bi.restype = c_int ! self.failUnlessEqual(self._dll.tf_bi(0, -2147483646), -715827882) ! self.failUnlessEqual(self.S(), -2147483646) def test_uint(self): ! self._dll.tf_I.restype = c_uint ! self.failUnlessEqual(self._dll.tf_I(4294967295), 1431655765) ! self.failUnlessEqual(self.U(), 4294967295) def test_uint_plus(self): ! self._dll.tf_bI.restype = c_uint ! self.failUnlessEqual(self._dll.tf_bI(0, 4294967295), 1431655765) ! self.failUnlessEqual(self.U(), 4294967295) def test_long(self): ! self._dll.tf_l.restype = c_long ! self._dll.tf_l.argtypes = (c_long,) ! self.failUnlessEqual(self._dll.tf_l(-2147483646), -715827882) ! self.failUnlessEqual(self.S(), -2147483646) def test_long_plus(self): ! self._dll.tf_bl.restype = c_long ! self._dll.tf_bl.argtypes = (c_byte, c_long) ! self.failUnlessEqual(self._dll.tf_bl(0, -2147483646), -715827882) ! self.failUnlessEqual(self.S(), -2147483646) def test_ulong(self): ! self._dll.tf_L.restype = c_ulong ! self.failUnlessEqual(self._dll.tf_L(4294967295), 1431655765) ! self.failUnlessEqual(self.U(), 4294967295) def test_ulong_plus(self): ! self._dll.tf_bL.restype = c_ulong ! self.failUnlessEqual(self._dll.tf_bL(0, 4294967295), 1431655765) ! self.failUnlessEqual(self.U(), 4294967295) def test_longlong(self): ! self._dll.tf_q.restype = c_longlong ! self._dll.tf_q.argtypes = (c_longlong, ) ! self.failUnlessEqual(self._dll.tf_q(-9223372036854775806), -3074457345618258602) ! self.failUnlessEqual(self.S(), -9223372036854775806) def test_longlong_plus(self): ! self._dll.tf_bq.restype = c_longlong ! self._dll.tf_bq.argtypes = (c_byte, c_longlong) ! self.failUnlessEqual(self._dll.tf_bq(0, -9223372036854775806), -3074457345618258602) ! self.failUnlessEqual(self.S(), -9223372036854775806) def test_ulonglong(self): ! self._dll.tf_Q.restype = c_ulonglong ! self._dll.tf_Q.argtypes = (c_ulonglong, ) ! self.failUnlessEqual(self._dll.tf_Q(18446744073709551615), 6148914691236517205) ! self.failUnlessEqual(self.U(), 18446744073709551615) def test_ulonglong_plus(self): ! self._dll.tf_bQ.restype = c_ulonglong ! self._dll.tf_bQ.argtypes = (c_byte, c_ulonglong) ! self.failUnlessEqual(self._dll.tf_bQ(0, 18446744073709551615), 6148914691236517205) ! self.failUnlessEqual(self.U(), 18446744073709551615) def test_float(self): ! self._dll.tf_f.restype = c_float ! self._dll.tf_f.argtypes = (c_float,) ! self.failUnlessEqual(self._dll.tf_f(-42.), -14.) ! self.failUnlessEqual(self.S(), -42) def test_float_plus(self): ! self._dll.tf_bf.restype = c_float ! self._dll.tf_bf.argtypes = (c_byte, c_float) ! self.failUnlessEqual(self._dll.tf_bf(0, -42.), -14.) ! self.failUnlessEqual(self.S(), -42) def test_double(self): ! self._dll.tf_d.restype = c_double ! self._dll.tf_d.argtypes = (c_double,) ! self.failUnlessEqual(self._dll.tf_d(42.), 14.) ! self.failUnlessEqual(self.S(), 42) def test_double_plus(self): ! self._dll.tf_bd.restype = c_double ! self._dll.tf_bd.argtypes = (c_byte, c_double) ! self.failUnlessEqual(self._dll.tf_bd(0, 42.), 14.) ! self.failUnlessEqual(self.S(), 42) def test_callwithresult(self): def process_result(result): return result * 2 ! self._dll.tf_i.restype = process_result ! self._dll.tf_i.argtypes = (c_int,) ! self.failUnlessEqual(self._dll.tf_i(42), 28) ! self.failUnlessEqual(self.S(), 42) ! self.failUnlessEqual(self._dll.tf_i(-42), -28) ! self.failUnlessEqual(self.S(), -42) def test_void(self): ! self._dll.tv_i.restype = None ! self._dll.tv_i.argtypes = (c_int,) ! self.failUnlessEqual(self._dll.tv_i(42), None) ! self.failUnlessEqual(self.S(), 42) ! self.failUnlessEqual(self._dll.tv_i(-42), None) ! self.failUnlessEqual(self.S(), -42) # The following repeates the above tests with stdcall functions (where # they are available) ! try: ! WinDLL ! except NameError: ! pass ! else: ! class stdcall_dll(WinDLL): ! def __getattr__(self, name): ! if name[:2] == '__' and name[-2:] == '__': ! raise AttributeError, name ! func = self._StdcallFuncPtr("s_" + name, self) ! setattr(self, name, func) ! return func ! class stdcallCFunctions(CFunctions): ! _dll = stdcall_dll(_ctypes_test.__file__) ! pass if __name__ == '__main__': |
From: Thomas H. <th...@us...> - 2004-10-19 09:26:59
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4978 Modified Files: test_cfuncs.py Log Message: Does this change make it work on OS X? Index: test_cfuncs.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_cfuncs.py,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** test_cfuncs.py 19 Oct 2004 09:09:03 -0000 1.17 --- test_cfuncs.py 19 Oct 2004 09:26:43 -0000 1.18 *************** *** 8,157 **** # the tf_? functions. ! def find_test_dll(): ! import _ctypes_test ! return _ctypes_test.__file__ class CFunctions(unittest.TestCase): - def __init__(self, *args): - unittest.TestCase.__init__(self, *args) - self.dll = CDLL(find_test_dll()) - global S, U - def S(): - return c_longlong.in_dll(self.dll, "last_tf_arg_s").value - def U(): - return c_ulonglong.in_dll(self.dll, "last_tf_arg_u").value def test_byte(self): ! self.dll.tf_b.restype = c_byte ! self.dll.tf_b.argtypes = (c_byte,) ! self.failUnlessEqual(self.dll.tf_b(-126), -42) self.failUnlessEqual(S(), -126) def test_byte_plus(self): ! self.dll.tf_bb.restype = c_byte ! self.dll.tf_bb.argtypes = (c_byte, c_byte) ! self.failUnlessEqual(self.dll.tf_bb(0, -126), -42) self.failUnlessEqual(S(), -126) def test_ubyte(self): ! self.dll.tf_B.restype = c_ubyte ! self.dll.tf_B.argtypes = (c_ubyte,) ! self.failUnlessEqual(self.dll.tf_B(255), 85) self.failUnlessEqual(U(), 255) def test_ubyte_plus(self): ! self.dll.tf_bB.restype = c_ubyte ! self.dll.tf_bB.argtypes = (c_byte, c_ubyte) ! self.failUnlessEqual(self.dll.tf_bB(0, 255), 85) self.failUnlessEqual(U(), 255) def test_short(self): ! self.dll.tf_h.restype = c_short ! self.failUnlessEqual(self.dll.tf_h(-32766), -10922) self.failUnlessEqual(S(), -32766) def test_short_plus(self): ! self.dll.tf_bh.restype = c_short ! self.failUnlessEqual(self.dll.tf_bh(0, -32766), -10922) self.failUnlessEqual(S(), -32766) def test_ushort(self): ! self.dll.tf_H.restype = c_ushort ! self.failUnlessEqual(self.dll.tf_H(65535), 21845) self.failUnlessEqual(U(), 65535) def test_ushort_plus(self): ! self.dll.tf_bH.restype = c_ushort ! self.failUnlessEqual(self.dll.tf_bH(0, 65535), 21845) self.failUnlessEqual(U(), 65535) def test_int(self): ! self.dll.tf_i.restype = c_int ! self.failUnlessEqual(self.dll.tf_i(-2147483646), -715827882) self.failUnlessEqual(S(), -2147483646) def test_int_plus(self): ! self.dll.tf_bi.restype = c_int ! self.failUnlessEqual(self.dll.tf_bi(0, -2147483646), -715827882) self.failUnlessEqual(S(), -2147483646) def test_uint(self): ! self.dll.tf_I.restype = c_uint ! self.failUnlessEqual(self.dll.tf_I(4294967295), 1431655765) self.failUnlessEqual(U(), 4294967295) def test_uint_plus(self): ! self.dll.tf_bI.restype = c_uint ! self.failUnlessEqual(self.dll.tf_bI(0, 4294967295), 1431655765) self.failUnlessEqual(U(), 4294967295) def test_long(self): ! self.dll.tf_l.restype = c_long ! self.dll.tf_l.argtypes = (c_long,) ! self.failUnlessEqual(self.dll.tf_l(-2147483646), -715827882) self.failUnlessEqual(S(), -2147483646) def test_long_plus(self): ! self.dll.tf_bl.restype = c_long ! self.dll.tf_bl.argtypes = (c_byte, c_long) ! self.failUnlessEqual(self.dll.tf_bl(0, -2147483646), -715827882) self.failUnlessEqual(S(), -2147483646) def test_ulong(self): ! self.dll.tf_L.restype = c_ulong ! self.failUnlessEqual(self.dll.tf_L(4294967295), 1431655765) self.failUnlessEqual(U(), 4294967295) def test_ulong_plus(self): ! self.dll.tf_bL.restype = c_ulong ! self.failUnlessEqual(self.dll.tf_bL(0, 4294967295), 1431655765) self.failUnlessEqual(U(), 4294967295) def test_longlong(self): ! self.dll.tf_q.restype = c_longlong ! self.dll.tf_q.argtypes = (c_longlong, ) ! self.failUnlessEqual(self.dll.tf_q(-9223372036854775806), -3074457345618258602) self.failUnlessEqual(S(), -9223372036854775806) def test_longlong_plus(self): ! self.dll.tf_bq.restype = c_longlong ! self.dll.tf_bq.argtypes = (c_byte, c_longlong) ! self.failUnlessEqual(self.dll.tf_bq(0, -9223372036854775806), -3074457345618258602) self.failUnlessEqual(S(), -9223372036854775806) def test_ulonglong(self): ! self.dll.tf_Q.restype = c_ulonglong ! self.dll.tf_Q.argtypes = (c_ulonglong, ) ! self.failUnlessEqual(self.dll.tf_Q(18446744073709551615), 6148914691236517205) self.failUnlessEqual(U(), 18446744073709551615) def test_ulonglong_plus(self): ! self.dll.tf_bQ.restype = c_ulonglong ! self.dll.tf_bQ.argtypes = (c_byte, c_ulonglong) ! self.failUnlessEqual(self.dll.tf_bQ(0, 18446744073709551615), 6148914691236517205) self.failUnlessEqual(U(), 18446744073709551615) def test_float(self): ! self.dll.tf_f.restype = c_float ! self.dll.tf_f.argtypes = (c_float,) ! self.failUnlessEqual(self.dll.tf_f(-42.), -14.) self.failUnlessEqual(S(), -42) def test_float_plus(self): ! self.dll.tf_bf.restype = c_float ! self.dll.tf_bf.argtypes = (c_byte, c_float) ! self.failUnlessEqual(self.dll.tf_bf(0, -42.), -14.) self.failUnlessEqual(S(), -42) def test_double(self): ! self.dll.tf_d.restype = c_double ! self.dll.tf_d.argtypes = (c_double,) ! self.failUnlessEqual(self.dll.tf_d(42.), 14.) self.failUnlessEqual(S(), 42) def test_double_plus(self): ! self.dll.tf_bd.restype = c_double ! self.dll.tf_bd.argtypes = (c_byte, c_double) ! self.failUnlessEqual(self.dll.tf_bd(0, 42.), 14.) self.failUnlessEqual(S(), 42) --- 8,153 ---- # the tf_? functions. ! import _ctypes_test ! testdll = CDLL(_ctypes_test.__file__) ! ! def S(): ! return c_longlong.in_dll(testdll, "last_tf_arg_s").value ! def U(): ! return c_ulonglong.in_dll(testdll, "last_tf_arg_u").value class CFunctions(unittest.TestCase): def test_byte(self): ! testdll.tf_b.restype = c_byte ! testdll.tf_b.argtypes = (c_byte,) ! self.failUnlessEqual(testdll.tf_b(-126), -42) self.failUnlessEqual(S(), -126) def test_byte_plus(self): ! testdll.tf_bb.restype = c_byte ! testdll.tf_bb.argtypes = (c_byte, c_byte) ! self.failUnlessEqual(testdll.tf_bb(0, -126), -42) self.failUnlessEqual(S(), -126) def test_ubyte(self): ! testdll.tf_B.restype = c_ubyte ! testdll.tf_B.argtypes = (c_ubyte,) ! self.failUnlessEqual(testdll.tf_B(255), 85) self.failUnlessEqual(U(), 255) def test_ubyte_plus(self): ! testdll.tf_bB.restype = c_ubyte ! testdll.tf_bB.argtypes = (c_byte, c_ubyte) ! self.failUnlessEqual(testdll.tf_bB(0, 255), 85) self.failUnlessEqual(U(), 255) def test_short(self): ! testdll.tf_h.restype = c_short ! self.failUnlessEqual(testdll.tf_h(-32766), -10922) self.failUnlessEqual(S(), -32766) def test_short_plus(self): ! testdll.tf_bh.restype = c_short ! self.failUnlessEqual(testdll.tf_bh(0, -32766), -10922) self.failUnlessEqual(S(), -32766) def test_ushort(self): ! testdll.tf_H.restype = c_ushort ! self.failUnlessEqual(testdll.tf_H(65535), 21845) self.failUnlessEqual(U(), 65535) def test_ushort_plus(self): ! testdll.tf_bH.restype = c_ushort ! self.failUnlessEqual(testdll.tf_bH(0, 65535), 21845) self.failUnlessEqual(U(), 65535) def test_int(self): ! testdll.tf_i.restype = c_int ! self.failUnlessEqual(testdll.tf_i(-2147483646), -715827882) self.failUnlessEqual(S(), -2147483646) def test_int_plus(self): ! testdll.tf_bi.restype = c_int ! self.failUnlessEqual(testdll.tf_bi(0, -2147483646), -715827882) self.failUnlessEqual(S(), -2147483646) def test_uint(self): ! testdll.tf_I.restype = c_uint ! self.failUnlessEqual(testdll.tf_I(4294967295), 1431655765) self.failUnlessEqual(U(), 4294967295) def test_uint_plus(self): ! testdll.tf_bI.restype = c_uint ! self.failUnlessEqual(testdll.tf_bI(0, 4294967295), 1431655765) self.failUnlessEqual(U(), 4294967295) def test_long(self): ! testdll.tf_l.restype = c_long ! testdll.tf_l.argtypes = (c_long,) ! self.failUnlessEqual(testdll.tf_l(-2147483646), -715827882) self.failUnlessEqual(S(), -2147483646) def test_long_plus(self): ! testdll.tf_bl.restype = c_long ! testdll.tf_bl.argtypes = (c_byte, c_long) ! self.failUnlessEqual(testdll.tf_bl(0, -2147483646), -715827882) self.failUnlessEqual(S(), -2147483646) def test_ulong(self): ! testdll.tf_L.restype = c_ulong ! self.failUnlessEqual(testdll.tf_L(4294967295), 1431655765) self.failUnlessEqual(U(), 4294967295) def test_ulong_plus(self): ! testdll.tf_bL.restype = c_ulong ! self.failUnlessEqual(testdll.tf_bL(0, 4294967295), 1431655765) self.failUnlessEqual(U(), 4294967295) def test_longlong(self): ! testdll.tf_q.restype = c_longlong ! testdll.tf_q.argtypes = (c_longlong, ) ! self.failUnlessEqual(testdll.tf_q(-9223372036854775806), -3074457345618258602) self.failUnlessEqual(S(), -9223372036854775806) def test_longlong_plus(self): ! testdll.tf_bq.restype = c_longlong ! testdll.tf_bq.argtypes = (c_byte, c_longlong) ! self.failUnlessEqual(testdll.tf_bq(0, -9223372036854775806), -3074457345618258602) self.failUnlessEqual(S(), -9223372036854775806) def test_ulonglong(self): ! testdll.tf_Q.restype = c_ulonglong ! testdll.tf_Q.argtypes = (c_ulonglong, ) ! self.failUnlessEqual(testdll.tf_Q(18446744073709551615), 6148914691236517205) self.failUnlessEqual(U(), 18446744073709551615) def test_ulonglong_plus(self): ! testdll.tf_bQ.restype = c_ulonglong ! testdll.tf_bQ.argtypes = (c_byte, c_ulonglong) ! self.failUnlessEqual(testdll.tf_bQ(0, 18446744073709551615), 6148914691236517205) self.failUnlessEqual(U(), 18446744073709551615) def test_float(self): ! testdll.tf_f.restype = c_float ! testdll.tf_f.argtypes = (c_float,) ! self.failUnlessEqual(testdll.tf_f(-42.), -14.) self.failUnlessEqual(S(), -42) def test_float_plus(self): ! testdll.tf_bf.restype = c_float ! testdll.tf_bf.argtypes = (c_byte, c_float) ! self.failUnlessEqual(testdll.tf_bf(0, -42.), -14.) self.failUnlessEqual(S(), -42) def test_double(self): ! testdll.tf_d.restype = c_double ! testdll.tf_d.argtypes = (c_double,) ! self.failUnlessEqual(testdll.tf_d(42.), 14.) self.failUnlessEqual(S(), 42) def test_double_plus(self): ! testdll.tf_bd.restype = c_double ! testdll.tf_bd.argtypes = (c_byte, c_double) ! self.failUnlessEqual(testdll.tf_bd(0, 42.), 14.) self.failUnlessEqual(S(), 42) *************** *** 159,197 **** def process_result(result): return result * 2 ! self.dll.tf_i.restype = process_result ! self.dll.tf_i.argtypes = (c_int,) ! self.failUnlessEqual(self.dll.tf_i(42), 28) self.failUnlessEqual(S(), 42) ! self.failUnlessEqual(self.dll.tf_i(-42), -28) self.failUnlessEqual(S(), -42) def test_void(self): ! self.dll.tv_i.restype = None ! self.dll.tv_i.argtypes = (c_int,) ! self.failUnlessEqual(self.dll.tv_i(42), None) self.failUnlessEqual(S(), 42) ! self.failUnlessEqual(self.dll.tv_i(-42), None) self.failUnlessEqual(S(), -42) # The following repeates the above tests with stdcall functions (where # they are available) ! try: ! WinDLL ! except NameError: ! pass ! else: ! class stdcall_dll(WinDLL): ! def __getattr__(self, name): ! if name[:2] == '__' and name[-2:] == '__': ! raise AttributeError, name ! func = self._StdcallFuncPtr("s_" + name, self) ! setattr(self, name, func) ! return func ! class stdcallCFunctions(CFunctions): ! def __init__(self, *args): ! unittest.TestCase.__init__(self, *args) ! self.dll = stdcall_dll(find_test_dll()) if __name__ == '__main__': --- 155,193 ---- def process_result(result): return result * 2 ! testdll.tf_i.restype = process_result ! testdll.tf_i.argtypes = (c_int,) ! self.failUnlessEqual(testdll.tf_i(42), 28) self.failUnlessEqual(S(), 42) ! self.failUnlessEqual(testdll.tf_i(-42), -28) self.failUnlessEqual(S(), -42) def test_void(self): ! testdll.tv_i.restype = None ! testdll.tv_i.argtypes = (c_int,) ! self.failUnlessEqual(testdll.tv_i(42), None) self.failUnlessEqual(S(), 42) ! self.failUnlessEqual(testdll.tv_i(-42), None) self.failUnlessEqual(S(), -42) # The following repeates the above tests with stdcall functions (where # they are available) ! ##try: ! ## WinDLL ! ##except NameError: ! ## pass ! ##else: ! ## class stdcall_dll(WinDLL): ! ## def __getattr__(self, name): ! ## if name[:2] == '__' and name[-2:] == '__': ! ## raise AttributeError, name ! ## func = self._StdcallFuncPtr("s_" + name, self) ! ## setattr(self, name, func) ! ## return func ! ## class stdcallCFunctions(CFunctions): ! ## def __init__(self, *args): ! ## unittest.TestCase.__init__(self, *args) ! ## testdll = stdcall_dll(find_test_dll()) if __name__ == '__main__': |
From: Thomas H. <th...@us...> - 2004-10-19 09:09:13
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1478 Modified Files: test_cfuncs.py Log Message: Mixing ctypes exported function calls and Python functions in _ctypes_test didn't work too well, on OS X at least. It seems several instances of the _ctypes_test extension got loaded, and we could not retrieve the correct value from the last function calls. Index: test_cfuncs.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_cfuncs.py,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** test_cfuncs.py 15 Sep 2004 22:12:23 -0000 1.16 --- test_cfuncs.py 19 Oct 2004 09:09:03 -0000 1.17 *************** *** 8,15 **** # the tf_? functions. - from _ctypes_test import \ - get_last_tf_arg_s as S, \ - get_last_tf_arg_u as U - def find_test_dll(): import _ctypes_test --- 8,11 ---- *************** *** 20,23 **** --- 16,24 ---- unittest.TestCase.__init__(self, *args) self.dll = CDLL(find_test_dll()) + global S, U + def S(): + return c_longlong.in_dll(self.dll, "last_tf_arg_s").value + def U(): + return c_ulonglong.in_dll(self.dll, "last_tf_arg_u").value def test_byte(self): |
From: Thomas H. <th...@us...> - 2004-10-19 09:09:12
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1409 Modified Files: _ctypes_test.c Log Message: Mixing ctypes exported function calls and Python functions in _ctypes_test didn't work too well, on OS X at least. It seems several instances of the _ctypes_test extension got loaded, and we could not retrieve the correct value from the last function calls. Index: _ctypes_test.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes_test.c,v retrieving revision 1.33 retrieving revision 1.34 diff -C2 -d -r1.33 -r1.34 *** _ctypes_test.c 13 Oct 2004 19:05:40 -0000 1.33 --- _ctypes_test.c 19 Oct 2004 09:08:53 -0000 1.34 *************** *** 288,305 **** } ! PY_LONG_LONG last_tf_arg_s; ! unsigned PY_LONG_LONG last_tf_arg_u; ! ! PyObject * ! get_last_tf_arg_s(PyObject *self, PyObject *arg) ! { ! return PyLong_FromLongLong(last_tf_arg_s); ! } ! ! PyObject * ! get_last_tf_arg_u(PyObject *self, PyObject *arg) ! { ! return PyLong_FromUnsignedLongLong(last_tf_arg_u); ! } struct BITS { --- 288,293 ---- } ! EXPORT(PY_LONG_LONG) last_tf_arg_s; ! EXPORT(unsigned PY_LONG_LONG) last_tf_arg_u; struct BITS { *************** *** 356,361 **** PyMethodDef module_methods[] = { ! {"get_last_tf_arg_s", get_last_tf_arg_s, METH_NOARGS}, ! {"get_last_tf_arg_u", get_last_tf_arg_u, METH_NOARGS}, {"func_si", py_func_si, METH_VARARGS}, {"func", py_func, METH_NOARGS}, --- 344,349 ---- PyMethodDef module_methods[] = { ! // {"get_last_tf_arg_s", get_last_tf_arg_s, METH_NOARGS}, ! // {"get_last_tf_arg_u", get_last_tf_arg_u, METH_NOARGS}, {"func_si", py_func_si, METH_VARARGS}, {"func", py_func, METH_NOARGS}, |
From: Thomas H. <th...@us...> - 2004-10-18 15:47:08
|
Update of /cvsroot/ctypes/ctypes/sandbox/libffi_test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15425/libffi_test Removed Files: cls_sint Log Message: --- cls_sint DELETED --- |
From: Thomas H. <th...@us...> - 2004-10-18 15:43:51
|
Update of /cvsroot/ctypes/ctypes/sandbox/libffi_test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14681/libffi_test Added Files: Makefile cls_sint cls_sint.c ffitest.h Log Message: --- NEW FILE: cls_sint.c --- /* Area: closure_call Purpose: Check return value sint32. Limitations: none. PR: none. Originator: <and...@gc...> 20031108 */ /* { dg-do run { xfail mips*-*-* arm*-*-* strongarm*-*-* xscale*-*-* } } */ #include "ffitest.h" static void cls_ret_sint_fn(ffi_cif* cif,void* resp,void** args, void* userdata) { *(ffi_arg*)resp = *(signed int *)args[0]; printf("%d: %d\n",*(signed int *)args[0], *(ffi_arg*)resp); } typedef signed int (*cls_ret_sint)(signed int); int main (void) { ffi_cif cif; #ifndef USING_MMAP static ffi_closure cl; #endif ffi_closure *pcl; ffi_type * cl_arg_types[2]; signed int res; #ifdef USING_MMAP pcl = allocate_mmap (sizeof(ffi_closure)); #else pcl = &cl; #endif cl_arg_types[0] = &ffi_type_sint32; cl_arg_types[1] = NULL; /* Initialize the cif */ CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, &ffi_type_sint32, cl_arg_types) == FFI_OK); CHECK(ffi_prep_closure(pcl, &cif, cls_ret_sint_fn, NULL) == FFI_OK); res = (*((cls_ret_sint)pcl))(65534); /* { dg-output "65534: 65534" } */ printf("res: %d\n",res); /* { dg-output "\nres: 65534" } */ exit(0); } --- NEW FILE: Makefile --- FFI=${HOME}/ctypes/build/temp.linux-i686-2.4/libffi CFLAGS=-I ${FFI}/include -I ${FFI} -L ${FFI}/../lib cls_sint: cls_sint.c gcc ${CFLAGS} cls_sint.c -lffi -o cls_sint --- NEW FILE: cls_sint --- (This appears to be a binary file; contents omitted.) --- NEW FILE: ffitest.h --- #include <stdlib.h> #include <stdio.h> #include <string.h> #include <fcntl.h> #include <ffi.h> #include "fficonfig.h" #define MAX_ARGS 256 #define CHECK(x) !(x) ? abort() : 0 /* Prefer MAP_ANON(YMOUS) to /dev/zero, since we don't need to keep a file open. */ #ifdef HAVE_MMAP_ANON # undef HAVE_MMAP_DEV_ZERO # include <sys/mman.h> # ifndef MAP_FAILED # define MAP_FAILED -1 # endif # if !defined (MAP_ANONYMOUS) && defined (MAP_ANON) # define MAP_ANONYMOUS MAP_ANON # endif # define USING_MMAP #endif #ifdef HAVE_MMAP_DEV_ZERO # include <sys/mman.h> # ifndef MAP_FAILED # define MAP_FAILED -1 # endif # define USING_MMAP #endif #ifdef USING_MMAP static inline void * allocate_mmap (size_t size) { void *page; #if defined (HAVE_MMAP_DEV_ZERO) static int dev_zero_fd = -1; #endif #ifdef HAVE_MMAP_DEV_ZERO if (dev_zero_fd == -1) { dev_zero_fd = open ("/dev/zero", O_RDONLY); if (dev_zero_fd == -1) { perror ("open /dev/zero: %m"); exit (1); } } #endif #ifdef HAVE_MMAP_ANON page = mmap (NULL, size, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); #endif #ifdef HAVE_MMAP_DEV_ZERO page = mmap (NULL, size, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE, dev_zero_fd, 0); #endif if (page == (void *) MAP_FAILED) { perror ("virtual memory exhausted"); exit (1); } return page; } #endif |
From: Thomas H. <th...@us...> - 2004-10-18 15:42:28
|
Update of /cvsroot/ctypes/ctypes/sandbox/libffi_test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14370/libffi_test Log Message: Directory /cvsroot/ctypes/ctypes/sandbox/libffi_test added to the repository |
From: Thomas H. <th...@us...> - 2004-10-18 08:25:41
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3894 Modified Files: test_unicode.py Log Message: Fix silly mistake. Index: test_unicode.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_unicode.py,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** test_unicode.py 18 Oct 2004 08:17:25 -0000 1.4 --- test_unicode.py 18 Oct 2004 08:25:32 -0000 1.5 *************** *** 5,9 **** try: ctypes.c_wchar ! except NameError: pass else: --- 5,9 ---- try: ctypes.c_wchar ! except AttributeError: pass else: |
From: Thomas H. <th...@us...> - 2004-10-18 08:17:34
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2197 Modified Files: test_unicode.py Log Message: Skip these tests when unicode not available. Index: test_unicode.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_unicode.py,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** test_unicode.py 12 Oct 2004 19:23:38 -0000 1.3 --- test_unicode.py 18 Oct 2004 08:17:25 -0000 1.4 *************** *** 3,109 **** import ctypes ! import _ctypes_test ! libc = ctypes.CDLL(_ctypes_test.__file__) ! wcslen = libc.my_wcslen ! wcslen.argtypes = [ctypes.c_wchar_p] ! class UnicodeTestCase(unittest.TestCase): ! def setUp(self): ! self.prev_conv_mode = ctypes.set_conversion_mode("ascii", "strict") ! def tearDown(self): ! ctypes.set_conversion_mode(*self.prev_conv_mode) ! def test_ascii_strict(self): ! ctypes.set_conversion_mode("ascii", "strict") ! # no conversions take place with unicode arguments ! self.failUnlessEqual(wcslen(u"abc"), 3) ! self.failUnlessEqual(wcslen(u"ab\u2070"), 3) ! # string args are converted ! self.failUnlessEqual(wcslen("abc"), 3) ! self.failUnlessRaises(ctypes.ArgumentError, wcslen, "abä") ! def test_ascii_replace(self): ! ctypes.set_conversion_mode("ascii", "replace") ! self.failUnlessEqual(wcslen(u"abc"), 3) ! self.failUnlessEqual(wcslen(u"ab\u2070"), 3) ! self.failUnlessEqual(wcslen("abc"), 3) ! self.failUnlessEqual(wcslen("abä"), 3) ! def test_ascii_ignore(self): ! ctypes.set_conversion_mode("ascii", "ignore") ! self.failUnlessEqual(wcslen(u"abc"), 3) ! self.failUnlessEqual(wcslen(u"ab\u2070"), 3) ! # ignore error mode skips non-ascii characters ! self.failUnlessEqual(wcslen("abc"), 3) ! self.failUnlessEqual(wcslen("äöüß"), 0) ! def test_latin1_strict(self): ! ctypes.set_conversion_mode("latin-1", "strict") ! self.failUnlessEqual(wcslen(u"abc"), 3) ! self.failUnlessEqual(wcslen(u"ab\u2070"), 3) ! self.failUnlessEqual(wcslen("abc"), 3) ! self.failUnlessEqual(wcslen("äöüß"), 4) ! def test_buffers(self): ! ctypes.set_conversion_mode("ascii", "strict") ! buf = ctypes.create_unicode_buffer("abc") ! self.failUnlessEqual(len(buf), 3+1) ! ctypes.set_conversion_mode("ascii", "replace") ! buf = ctypes.create_unicode_buffer("abäöü") ! self.failUnlessEqual(buf[:], u"ab\uFFFD\uFFFD\uFFFD\0") ! ctypes.set_conversion_mode("ascii", "ignore") ! buf = ctypes.create_unicode_buffer("abäöü") ! # is that correct? not sure. But with 'ignore', you get what you pay for.. ! self.failUnlessEqual(buf[:], u"ab\0\0\0\0") ! import _ctypes_test ! func = ctypes.CDLL(_ctypes_test.__file__)._testfunc_p_p ! class StringTestCase(UnicodeTestCase): ! def setUp(self): ! self.prev_conv_mode = ctypes.set_conversion_mode("ascii", "strict") ! func.argtypes = [ctypes.c_char_p] ! func.restype = ctypes.c_char_p ! def tearDown(self): ! ctypes.set_conversion_mode(*self.prev_conv_mode) ! func.argtypes = None ! func.restype = ctypes.c_int ! def test_ascii_replace(self): ! ctypes.set_conversion_mode("ascii", "strict") ! self.failUnlessEqual(func("abc"), "abc") ! self.failUnlessEqual(func(u"abc"), "abc") ! self.assertRaises(ctypes.ArgumentError, func, u"abä") ! def test_ascii_ignore(self): ! ctypes.set_conversion_mode("ascii", "ignore") ! self.failUnlessEqual(func("abc"), "abc") ! self.failUnlessEqual(func(u"abc"), "abc") ! self.failUnlessEqual(func(u"äöüß"), "") ! def test_ascii_replace(self): ! ctypes.set_conversion_mode("ascii", "replace") ! self.failUnlessEqual(func("abc"), "abc") ! self.failUnlessEqual(func(u"abc"), "abc") ! self.failUnlessEqual(func(u"äöüß"), "????") ! def test_buffers(self): ! ctypes.set_conversion_mode("ascii", "strict") ! buf = ctypes.create_string_buffer(u"abc") ! self.failUnlessEqual(len(buf), 3+1) ! ctypes.set_conversion_mode("ascii", "replace") ! buf = ctypes.create_string_buffer(u"abäöü") ! self.failUnlessEqual(buf[:], "ab???\0") ! ctypes.set_conversion_mode("ascii", "ignore") ! buf = ctypes.create_string_buffer(u"abäöü") ! # is that correct? not sure. But with 'ignore', you get what you pay for.. ! self.failUnlessEqual(buf[:], "ab\0\0\0\0") if __name__ == '__main__': --- 3,114 ---- import ctypes ! try: ! ctypes.c_wchar ! except NameError: ! pass ! else: ! import _ctypes_test ! libc = ctypes.CDLL(_ctypes_test.__file__) ! wcslen = libc.my_wcslen ! wcslen.argtypes = [ctypes.c_wchar_p] ! class UnicodeTestCase(unittest.TestCase): ! def setUp(self): ! self.prev_conv_mode = ctypes.set_conversion_mode("ascii", "strict") ! def tearDown(self): ! ctypes.set_conversion_mode(*self.prev_conv_mode) ! def test_ascii_strict(self): ! ctypes.set_conversion_mode("ascii", "strict") ! # no conversions take place with unicode arguments ! self.failUnlessEqual(wcslen(u"abc"), 3) ! self.failUnlessEqual(wcslen(u"ab\u2070"), 3) ! # string args are converted ! self.failUnlessEqual(wcslen("abc"), 3) ! self.failUnlessRaises(ctypes.ArgumentError, wcslen, "abä") ! def test_ascii_replace(self): ! ctypes.set_conversion_mode("ascii", "replace") ! self.failUnlessEqual(wcslen(u"abc"), 3) ! self.failUnlessEqual(wcslen(u"ab\u2070"), 3) ! self.failUnlessEqual(wcslen("abc"), 3) ! self.failUnlessEqual(wcslen("abä"), 3) ! def test_ascii_ignore(self): ! ctypes.set_conversion_mode("ascii", "ignore") ! self.failUnlessEqual(wcslen(u"abc"), 3) ! self.failUnlessEqual(wcslen(u"ab\u2070"), 3) ! # ignore error mode skips non-ascii characters ! self.failUnlessEqual(wcslen("abc"), 3) ! self.failUnlessEqual(wcslen("äöüß"), 0) ! def test_latin1_strict(self): ! ctypes.set_conversion_mode("latin-1", "strict") ! self.failUnlessEqual(wcslen(u"abc"), 3) ! self.failUnlessEqual(wcslen(u"ab\u2070"), 3) ! self.failUnlessEqual(wcslen("abc"), 3) ! self.failUnlessEqual(wcslen("äöüß"), 4) ! def test_buffers(self): ! ctypes.set_conversion_mode("ascii", "strict") ! buf = ctypes.create_unicode_buffer("abc") ! self.failUnlessEqual(len(buf), 3+1) ! ctypes.set_conversion_mode("ascii", "replace") ! buf = ctypes.create_unicode_buffer("abäöü") ! self.failUnlessEqual(buf[:], u"ab\uFFFD\uFFFD\uFFFD\0") ! ctypes.set_conversion_mode("ascii", "ignore") ! buf = ctypes.create_unicode_buffer("abäöü") ! # is that correct? not sure. But with 'ignore', you get what you pay for.. ! self.failUnlessEqual(buf[:], u"ab\0\0\0\0") ! import _ctypes_test ! func = ctypes.CDLL(_ctypes_test.__file__)._testfunc_p_p ! class StringTestCase(UnicodeTestCase): ! def setUp(self): ! self.prev_conv_mode = ctypes.set_conversion_mode("ascii", "strict") ! func.argtypes = [ctypes.c_char_p] ! func.restype = ctypes.c_char_p ! def tearDown(self): ! ctypes.set_conversion_mode(*self.prev_conv_mode) ! func.argtypes = None ! func.restype = ctypes.c_int ! def test_ascii_replace(self): ! ctypes.set_conversion_mode("ascii", "strict") ! self.failUnlessEqual(func("abc"), "abc") ! self.failUnlessEqual(func(u"abc"), "abc") ! self.assertRaises(ctypes.ArgumentError, func, u"abä") ! def test_ascii_ignore(self): ! ctypes.set_conversion_mode("ascii", "ignore") ! self.failUnlessEqual(func("abc"), "abc") ! self.failUnlessEqual(func(u"abc"), "abc") ! self.failUnlessEqual(func(u"äöüß"), "") ! def test_ascii_replace(self): ! ctypes.set_conversion_mode("ascii", "replace") ! self.failUnlessEqual(func("abc"), "abc") ! self.failUnlessEqual(func(u"abc"), "abc") ! self.failUnlessEqual(func(u"äöüß"), "????") ! def test_buffers(self): ! ctypes.set_conversion_mode("ascii", "strict") ! buf = ctypes.create_string_buffer(u"abc") ! self.failUnlessEqual(len(buf), 3+1) ! ctypes.set_conversion_mode("ascii", "replace") ! buf = ctypes.create_string_buffer(u"abäöü") ! self.failUnlessEqual(buf[:], "ab???\0") ! ctypes.set_conversion_mode("ascii", "ignore") ! buf = ctypes.create_string_buffer(u"abäöü") ! # is that correct? not sure. But with 'ignore', you get what you pay for.. ! self.failUnlessEqual(buf[:], "ab\0\0\0\0") if __name__ == '__main__': |
From: Thomas H. <th...@us...> - 2004-10-18 08:13:23
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1292 Modified Files: cfield.c Log Message: Prevent segfault when CTYPES_UNICODE not defined. Index: cfield.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/cfield.c,v retrieving revision 1.61 retrieving revision 1.62 diff -C2 -d -r1.61 -r1.62 *** cfield.c 18 Oct 2004 08:07:05 -0000 1.61 --- cfield.c 18 Oct 2004 08:13:11 -0000 1.62 *************** *** 1108,1111 **** --- 1108,1112 ---- if (!initialized) { initialized = 1; + #ifdef CTYPES_UNICODE if (sizeof(wchar_t) == sizeof(short)) getentry("u")->pffi_type = &ffi_type_sshort; *************** *** 1114,1117 **** --- 1115,1119 ---- else if (sizeof(wchar_t) == sizeof(long)) getentry("u")->pffi_type = &ffi_type_slong; + #endif } |
From: Thomas H. <th...@us...> - 2004-10-18 08:07:18
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32432 Modified Files: stgdict.c ctypes.h cfield.c callproc.c _ctypes.c Log Message: We need Py_USING_UNICODE *and* HAVE_WCHAR_H for unicode/wchar_t support. Index: ctypes.h =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/ctypes.h,v retrieving revision 1.55 retrieving revision 1.56 diff -C2 -d -r1.55 -r1.56 *** ctypes.h 15 Oct 2004 07:00:21 -0000 1.55 --- ctypes.h 18 Oct 2004 08:07:05 -0000 1.56 *************** *** 291,296 **** /* Python's PyUnicode_*WideChar functions are broken ... */ ! #ifdef Py_USING_UNICODE # undef PyUnicode_FromWideChar # define PyUnicode_FromWideChar My_PyUnicode_FromWideChar --- 291,300 ---- /* Python's PyUnicode_*WideChar functions are broken ... */ ! #if defined(Py_USING_UNICODE) && defined(HAVE_WCHAR_H) ! # define CTYPES_UNICODE ! #endif + + #ifdef CTYPES_UNICODE # undef PyUnicode_FromWideChar # define PyUnicode_FromWideChar My_PyUnicode_FromWideChar *************** *** 299,311 **** # define PyUnicode_AsWideChar My_PyUnicode_AsWideChar - /* see comment in Python's Include/unicodeobject.h */ - # ifdef Py_UNICODE_WIDE - # define My_PyUnicode_FromWideChar My_PyUnicodeUCS4_FromWideChar - # define My_PyUnicode_AsWideChar My_PyUnicodeUCS4_AsWideChar - # else - # define My_PyUnicode_FromWideChar My_PyUnicodeUCS2_FromWideChar - # define My_PyUnicode_AsWideChar My_PyUnicodeUCS2_AsWideChar - # endif - extern PyObject *My_PyUnicode_FromWideChar(const wchar_t *, int); extern int My_PyUnicode_AsWideChar(PyUnicodeObject *, wchar_t *, int); --- 303,306 ---- Index: stgdict.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/stgdict.c,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** stgdict.c 14 Oct 2004 18:14:35 -0000 1.20 --- stgdict.c 18 Oct 2004 08:07:05 -0000 1.21 *************** *** 216,220 **** case FFI_TYPE_SINT32: if (dict->getfunc != getentry("c")->getfunc ! #ifdef Py_USING_UNICODE && dict->getfunc != getentry("u")->getfunc #endif --- 216,220 ---- case FFI_TYPE_SINT32: if (dict->getfunc != getentry("c")->getfunc ! #ifdef CTYPES_UNICODE && dict->getfunc != getentry("u")->getfunc #endif Index: callproc.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/callproc.c,v retrieving revision 1.111 retrieving revision 1.112 diff -C2 -d -r1.111 -r1.112 *** callproc.c 15 Oct 2004 16:55:42 -0000 1.111 --- callproc.c 18 Oct 2004 08:07:05 -0000 1.112 *************** *** 501,505 **** } ! #ifdef Py_USING_UNICODE if (PyUnicode_Check(obj)) { #ifdef HAVE_USABLE_WCHAR_T --- 501,505 ---- } ! #ifdef CTYPES_UNICODE if (PyUnicode_Check(obj)) { #ifdef HAVE_USABLE_WCHAR_T *************** *** 1244,1248 **** } ! #ifdef Py_USING_UNICODE static PyObject * --- 1244,1248 ---- } ! #ifdef CTYPES_UNICODE static PyObject * *************** *** 1387,1391 **** {"memset", c_memset, METH_VARARGS, memset_doc}, {"cast", cast, METH_VARARGS, cast_doc}, ! #ifdef Py_USING_UNICODE {"set_conversion_mode", set_conversion_mode, METH_VARARGS, set_conversion_mode_doc}, #endif --- 1387,1391 ---- {"memset", c_memset, METH_VARARGS, memset_doc}, {"cast", cast, METH_VARARGS, cast_doc}, ! #ifdef CTYPES_UNICODE {"set_conversion_mode", set_conversion_mode, METH_VARARGS, set_conversion_mode_doc}, #endif Index: cfield.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/cfield.c,v retrieving revision 1.60 retrieving revision 1.61 diff -C2 -d -r1.60 -r1.61 *** cfield.c 14 Oct 2004 14:43:45 -0000 1.60 --- cfield.c 18 Oct 2004 08:07:05 -0000 1.61 *************** *** 110,114 **** setfunc = fd->setfunc; } ! #ifdef Py_USING_UNICODE if (idict->getfunc == getentry("u")->getfunc) { struct fielddesc *fd = getentry("U"); --- 110,114 ---- setfunc = fd->setfunc; } ! #ifdef CTYPES_UNICODE if (idict->getfunc == getentry("u")->getfunc) { struct fielddesc *fd = getentry("U"); *************** *** 683,687 **** } ! #ifdef Py_USING_UNICODE /* u - a single wchar_t character */ static PyObject * --- 683,687 ---- } ! #ifdef CTYPES_UNICODE /* u - a single wchar_t character */ static PyObject * *************** *** 886,890 **** } ! #ifdef Py_USING_UNICODE static PyObject * Z_set(void *ptr, PyObject *value, unsigned size) --- 886,890 ---- } ! #ifdef CTYPES_UNICODE static PyObject * Z_set(void *ptr, PyObject *value, unsigned size) *************** *** 1088,1092 **** { 'P', P_set, P_get, &ffi_type_pointer}, { 'z', z_set, z_get, &ffi_type_pointer}, ! #ifdef Py_USING_UNICODE { 'u', u_set, u_get, NULL}, /* ffi_type set later */ { 'U', U_set, U_get, &ffi_type_pointer}, --- 1088,1092 ---- { 'P', P_set, P_get, &ffi_type_pointer}, { 'z', z_set, z_get, &ffi_type_pointer}, ! #ifdef CTYPES_UNICODE { 'u', u_set, u_get, NULL}, /* ffi_type set later */ { 'U', U_set, U_get, &ffi_type_pointer}, Index: _ctypes.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes.c,v retrieving revision 1.171 retrieving revision 1.172 diff -C2 -d -r1.171 -r1.172 *** _ctypes.c 15 Oct 2004 19:00:09 -0000 1.171 --- _ctypes.c 18 Oct 2004 08:07:05 -0000 1.172 *************** *** 782,786 **** }; ! #ifdef Py_USING_UNICODE static PyObject * WCharArray_get_value(CDataObject *self) --- 782,786 ---- }; ! #ifdef CTYPES_UNICODE static PyObject * WCharArray_get_value(CDataObject *self) *************** *** 972,976 **** if (-1 == add_getset(result, CharArray_getsets)) return NULL; ! #ifdef Py_USING_UNICODE } else if (itemdict->getfunc == getentry("u")->getfunc) { if (-1 == add_getset(result, WCharArray_getsets)) --- 972,976 ---- if (-1 == add_getset(result, CharArray_getsets)) return NULL; ! #ifdef CTYPES_UNICODE } else if (itemdict->getfunc == getentry("u")->getfunc) { if (-1 == add_getset(result, WCharArray_getsets)) *************** *** 3031,3035 **** char *ptr = (char *)self->b_ptr; return PyString_FromStringAndSize(ptr + ilow, len); ! #ifdef Py_USING_UNICODE } else if (itemdict->getfunc == getentry("u")->getfunc) { wchar_t *ptr = (wchar_t *)self->b_ptr; --- 3031,3035 ---- char *ptr = (char *)self->b_ptr; return PyString_FromStringAndSize(ptr + ilow, len); ! #ifdef CTYPES_UNICODE } else if (itemdict->getfunc == getentry("u")->getfunc) { wchar_t *ptr = (wchar_t *)self->b_ptr; *************** *** 3560,3564 **** char *ptr = *(char **)self->b_ptr; return PyString_FromStringAndSize(ptr + ilow, len); ! #ifdef Py_USING_UNICODE } else if (itemdict->getfunc == getentry("u")->getfunc) { wchar_t *ptr = *(wchar_t **)self->b_ptr; --- 3560,3564 ---- char *ptr = *(char **)self->b_ptr; return PyString_FromStringAndSize(ptr + ilow, len); ! #ifdef CTYPES_UNICODE } else if (itemdict->getfunc == getentry("u")->getfunc) { wchar_t *ptr = *(wchar_t **)self->b_ptr; |
From: Thomas H. <th...@us...> - 2004-10-18 07:25:53
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23556 Modified Files: test_leaks.py Log Message: Shorter error msgs. Index: test_leaks.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_leaks.py,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** test_leaks.py 14 Oct 2004 18:23:11 -0000 1.3 --- test_leaks.py 18 Oct 2004 07:25:44 -0000 1.4 *************** *** 29,33 **** return # test passed last_refcount = total_refcount ! self.fail("it seems the total refcounts grows without bounds") def test_no_cycles_objcount(self): --- 29,33 ---- return # test passed last_refcount = total_refcount ! self.fail("leaking refcounts") def test_no_cycles_objcount(self): *************** *** 44,48 **** return # test passed last_objcount = total_objcount ! self.fail("it seems the number of objects grows without bounds") ################ --- 44,48 ---- return # test passed last_objcount = total_objcount ! self.fail("leaking objects") ################ *************** *** 68,72 **** return last_refcount = total_refcount ! self.fail("it seems the total refcounts grows without bounds") def test_cycles_objcount(self): --- 68,72 ---- return last_refcount = total_refcount ! self.fail("leaking refcounts") def test_cycles_objcount(self): *************** *** 83,87 **** return last_objcount = total_objcount ! self.fail("it seems the number of objects grows without bounds") if __name__ == "__main__": --- 83,87 ---- return last_objcount = total_objcount ! self.fail("leaking objects") if __name__ == "__main__": |
From: Thomas H. <th...@us...> - 2004-10-15 19:09:52
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4271 Added Files: test_lazy_struct.py Log Message: The leaks are back, but lazy Structures work again. --- NEW FILE: test_lazy_struct.py --- import unittest from ctypes import * class LazyStructTest(unittest.TestCase): def test(self): class POINT(Structure): pass POINT._fields_ = [("x", c_int), ("y", c_int)] p = POINT(1, 2) self.failUnlessEqual((p.x, p.y), (1, 2)) def test_pointers(self): class List(Structure): pass List._fields_ = [("num", c_int), ("pnext", POINTER(List))] a = List(1) b = List(2) self.failUnlessEqual(bool(a.pnext), False) self.failUnlessEqual(bool(b.pnext), False) a.pnext = pointer(b) b.pnext = pointer(a) self.failUnlessEqual(a.num, 1) self.failUnlessEqual(a.pnext[0].num, 2) self.failUnlessEqual(a.pnext[0].pnext[0].num, 1) def test_reassign(self): class List(Structure): pass List._fields_ = [("num", c_int), ("pnext", POINTER(List))] self.assertRaises(AttributeError, setattr, List, "_fields_", [("num", c_int)]) def test_subclasses(self): class Point(Structure): _fields_ = [("x", c_int), ("y", c_int)] class ColoredPoint(Point): _fields_ = Point._fields_ + [("color", c_int)] self.failUnlessEqual(sizeof(ColoredPoint), sizeof(c_int) * 3) # This has to wait - it currently fails with: # _fields_ cannot be overwritten. ## class HeavyPoint(Point): ## pass ## HeavyPoint._fields_ = Point._fields_ + [("weight", c_int)] ## self.failUnlessEqual(sizeof(HeavyPoint), sizeof(c_int) * 3) if __name__ == "__main__": unittest.main() |
From: Thomas H. <th...@us...> - 2004-10-15 19:00:56
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2123 Modified Files: _ctypes.c Log Message: The leaks are back, but lazy Structures work again. Index: _ctypes.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes.c,v retrieving revision 1.170 retrieving revision 1.171 diff -C2 -d -r1.170 -r1.171 *** _ctypes.c 15 Oct 2004 08:22:45 -0000 1.170 --- _ctypes.c 15 Oct 2004 19:00:09 -0000 1.171 *************** *** 584,598 **** assert(dict); - /* FIXME/CHECKME: What about subclasses? */ old_type = PyDict_GetItemString((PyObject *)dict, "_type_"); ! if (old_type == type) ! goto done; /* nothing to do */ ! ! if (old_type && old_type != type && type != Py_None) { PyErr_SetString(PyExc_AttributeError, "_type_ already set"); return NULL; } - if (-1 == PointerType_SetProto(dict, type)) return NULL; --- 584,593 ---- assert(dict); old_type = PyDict_GetItemString((PyObject *)dict, "_type_"); ! if (old_type && old_type != type) { PyErr_SetString(PyExc_AttributeError, "_type_ already set"); return NULL; } if (-1 == PointerType_SetProto(dict, type)) return NULL; *************** *** 600,604 **** if (-1 == PyDict_SetItemString((PyObject *)dict, "_type_", type)) return NULL; ! done: Py_INCREF(Py_None); return Py_None; --- 595,599 ---- if (-1 == PyDict_SetItemString((PyObject *)dict, "_type_", type)) return NULL; ! Py_INCREF(Py_None); return Py_None; |
From: Thomas H. <th...@us...> - 2004-10-15 16:56:47
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7545 Modified Files: test_memfunctions.py Log Message: Add memset function. Index: test_memfunctions.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_memfunctions.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** test_memfunctions.py 15 Oct 2004 14:36:38 -0000 1.1 --- test_memfunctions.py 15 Oct 2004 16:55:50 -0000 1.2 *************** *** 10,13 **** --- 10,23 ---- self.failUnlessEqual(get_string(result), "Hello, World") + self.failUnlessEqual(get_string(result, 5), "Hello") + self.failUnlessEqual(get_string(result, 16), "Hello, World\0\0\0\0") + + def test_memset(self): + a = create_string_buffer(32) + result = memset(a, ord('x'), 16) + + self.failUnlessEqual(get_string(result), "xxxxxxxxxxxxxxxx") + self.failUnlessEqual(get_string(a), "xxxxxxxxxxxxxxxx") + self.failUnlessEqual(a.value, "xxxxxxxxxxxxxxxx") if __name__ == "__main__": |
From: Thomas H. <th...@us...> - 2004-10-15 16:56:35
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7502 Modified Files: callproc.c Log Message: Add memset function. Index: callproc.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/callproc.c,v retrieving revision 1.110 retrieving revision 1.111 diff -C2 -d -r1.110 -r1.111 *** callproc.c 15 Oct 2004 14:36:24 -0000 1.110 --- callproc.c 15 Oct 2004 16:55:42 -0000 1.111 *************** *** 1291,1295 **** if (!PyArg_ParseTuple(args, "OO", &obj, &ctype)) return NULL; ! if (-1 == ConvParam(obj, 0, &a)) return NULL; result = (CDataObject *)PyObject_CallFunctionObjArgs(ctype, NULL); --- 1291,1295 ---- if (!PyArg_ParseTuple(args, "OO", &obj, &ctype)) return NULL; ! if (-1 == ConvParam(obj, 1, &a)) return NULL; result = (CDataObject *)PyObject_CallFunctionObjArgs(ctype, NULL); *************** *** 1304,1310 **** static char memmove_doc[] = ! "memmove(dst, src, size) -> adress\n\ \n\ ! Copy size bytes from src to dst, return the destination address as integer.\n"; static PyObject * --- 1304,1310 ---- static char memmove_doc[] = ! "memmove(dst, src, count) -> adress\n\ \n\ ! Copy count bytes from src to dst, return the dst address as integer.\n"; static PyObject * *************** *** 1321,1327 **** if (!PyArg_ParseTuple(args, "OOi", &dst, &src, &size)) return NULL; ! if (-1 == ConvParam(dst, 0, &a_dst)) goto done; ! if (-1 == ConvParam(src, 1, &a_src)) goto done; c_result = memmove(a_dst.value.p, a_src.value.p, size); --- 1321,1327 ---- if (!PyArg_ParseTuple(args, "OOi", &dst, &src, &size)) return NULL; ! if (-1 == ConvParam(dst, 1, &a_dst)) goto done; ! if (-1 == ConvParam(src, 2, &a_src)) goto done; c_result = memmove(a_dst.value.p, a_src.value.p, size); *************** *** 1333,1350 **** } static char get_string_doc[] = ! "get_string(addr) -> string\n\ \n\ Return the string at addr.\n"; static PyObject * ! get_string(PyObject *self, PyObject *arg) { PyObject *result = NULL; struct argument a_arg; ! if (-1 == ConvParam(arg, 0, &a_arg)) ! goto done; ! result = PyString_FromString(a_arg.value.p); ! done: Py_XDECREF(a_arg.keep); return result; --- 1333,1381 ---- } + static char memset_doc[] = + "memset(dst, c, count) -> adress\n\ + \n\ + Set count bytes starting at dst to c, return the dst address as integer.\n"; + static PyObject * + c_memset(PyObject *self, PyObject *args) + { + PyObject *dst, *result; + struct argument a_dst; + void *c_result; + int c, count; + + if (!PyArg_ParseTuple(args, "Oii", &dst, &c, &count)) + return NULL; + memset(&a_dst, 0, sizeof(struct argument)); + if (-1 == ConvParam(dst, 1, &a_dst)) + return NULL; + c_result = memset(a_dst.value.p, c, count); + result = PyLong_FromVoidPtr(c_result); + Py_XDECREF(a_dst.keep); + return result; + } + static char get_string_doc[] = ! "get_string(addr[, size]) -> string\n\ \n\ Return the string at addr.\n"; static PyObject * ! get_string(PyObject *self, PyObject *args) { PyObject *result = NULL; + PyObject *src; struct argument a_arg; ! int size; ! ! if (!PyArg_ParseTuple(args, "O|i", &src, &size)) ! return NULL; ! memset(&a_arg, 0, sizeof(struct argument)); ! if (-1 == ConvParam(src, 1, &a_arg)) ! return NULL; ! if (PyTuple_GET_SIZE(args) == 1) ! result = PyString_FromString(a_arg.value.p); ! else ! result = PyString_FromStringAndSize(a_arg.value.p, size); Py_XDECREF(a_arg.keep); return result; *************** *** 1352,1357 **** PyMethodDef module_methods[] = { ! {"get_string", get_string, METH_O, get_string_doc}, {"memmove", c_memmove, METH_VARARGS, memmove_doc}, {"cast", cast, METH_VARARGS, cast_doc}, #ifdef Py_USING_UNICODE --- 1383,1389 ---- PyMethodDef module_methods[] = { ! {"get_string", get_string, METH_VARARGS, get_string_doc}, {"memmove", c_memmove, METH_VARARGS, memmove_doc}, + {"memset", c_memset, METH_VARARGS, memset_doc}, {"cast", cast, METH_VARARGS, cast_doc}, #ifdef Py_USING_UNICODE |
From: Thomas H. <th...@us...> - 2004-10-15 16:56:22
|
Update of /cvsroot/ctypes/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7467 Modified Files: __init__.py Log Message: Add memset function. Index: __init__.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/__init__.py,v retrieving revision 1.41 retrieving revision 1.42 diff -C2 -d -r1.41 -r1.42 *** __init__.py 15 Oct 2004 14:36:13 -0000 1.41 --- __init__.py 15 Oct 2004 16:55:30 -0000 1.42 *************** *** 379,381 **** # functions ! from _ctypes import memmove, get_string --- 379,381 ---- # functions ! from _ctypes import memmove, memset, get_string |
From: Thomas H. <th...@us...> - 2004-10-15 14:37:30
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5936 Added Files: test_memfunctions.py Log Message: Added memmove and get_string functions. --- NEW FILE: test_memfunctions.py --- import unittest from ctypes import * class MemFunctionsTest(unittest.TestCase): def test_memmove(self): a = create_string_buffer(32) p = "Hello, World" result = memmove(a, p, len(p)) self.failUnlessEqual(a.value, "Hello, World") self.failUnlessEqual(get_string(result), "Hello, World") if __name__ == "__main__": unittest.main() |
From: Thomas H. <th...@us...> - 2004-10-15 14:37:13
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5863 Modified Files: callproc.c Log Message: Added memmove and get_string functions. Index: callproc.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/callproc.c,v retrieving revision 1.109 retrieving revision 1.110 diff -C2 -d -r1.109 -r1.110 *** callproc.c 13 Oct 2004 15:24:12 -0000 1.109 --- callproc.c 15 Oct 2004 14:36:24 -0000 1.110 *************** *** 1303,1307 **** --- 1303,1357 ---- } + static char memmove_doc[] = + "memmove(dst, src, size) -> adress\n\ + \n\ + Copy size bytes from src to dst, return the destination address as integer.\n"; + + static PyObject * + c_memmove(PyObject *self, PyObject *args) + { + struct argument a_dst, a_src; + int size; + void *c_result; + PyObject *result = NULL; + PyObject *dst, *src; + + memset(&a_dst, 0, sizeof(struct argument)); + memset(&a_src, 0, sizeof(struct argument)); + if (!PyArg_ParseTuple(args, "OOi", &dst, &src, &size)) + return NULL; + if (-1 == ConvParam(dst, 0, &a_dst)) + goto done; + if (-1 == ConvParam(src, 1, &a_src)) + goto done; + c_result = memmove(a_dst.value.p, a_src.value.p, size); + result = PyLong_FromVoidPtr(c_result); + done: + Py_XDECREF(a_dst.keep); + Py_XDECREF(a_src.keep); + return result; + } + + static char get_string_doc[] = + "get_string(addr) -> string\n\ + \n\ + Return the string at addr.\n"; + + static PyObject * + get_string(PyObject *self, PyObject *arg) + { + PyObject *result = NULL; + struct argument a_arg; + if (-1 == ConvParam(arg, 0, &a_arg)) + goto done; + result = PyString_FromString(a_arg.value.p); + done: + Py_XDECREF(a_arg.keep); + return result; + } + PyMethodDef module_methods[] = { + {"get_string", get_string, METH_O, get_string_doc}, + {"memmove", c_memmove, METH_VARARGS, memmove_doc}, {"cast", cast, METH_VARARGS, cast_doc}, #ifdef Py_USING_UNICODE |
From: Thomas H. <th...@us...> - 2004-10-15 14:36:52
|
Update of /cvsroot/ctypes/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5824 Modified Files: __init__.py Log Message: Added memmove and get_string functions. Index: __init__.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/__init__.py,v retrieving revision 1.40 retrieving revision 1.41 diff -C2 -d -r1.40 -r1.41 *** __init__.py 12 Oct 2004 19:02:29 -0000 1.40 --- __init__.py 15 Oct 2004 14:36:13 -0000 1.41 *************** *** 376,377 **** --- 376,381 ---- _pointer_type_cache[None] = c_void_p + + # functions + + from _ctypes import memmove, get_string |
From: Thomas H. <th...@us...> - 2004-10-15 14:35:21
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5413 Modified Files: callbacks.c Log Message: Slighlty better error reporting, although it doesn't really help. Index: callbacks.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/callbacks.c,v retrieving revision 1.60 retrieving revision 1.61 diff -C2 -d -r1.60 -r1.61 *** callbacks.c 16 Sep 2004 10:26:36 -0000 1.60 --- callbacks.c 15 Oct 2004 14:34:40 -0000 1.61 *************** *** 473,477 **** Py_DECREF(func); if (!result) { ! MyPyErr_Print(NULL); return E_FAIL; } --- 473,477 ---- Py_DECREF(func); if (!result) { ! MyPyErr_Print("Called DllGetClassObject"); return E_FAIL; } *************** *** 479,483 **** retval = PyInt_AsLong(result); if (PyErr_Occurred()) ! MyPyErr_Print(NULL); Py_DECREF(result); return retval; --- 479,483 ---- retval = PyInt_AsLong(result); if (PyErr_Occurred()) ! MyPyErr_Print("Convert result of DllGetClassObject to int"); Py_DECREF(result); return retval; *************** *** 514,518 **** mod = PyImport_ImportModule("ctypes.com.server"); if (!mod) { ! MyPyErr_Print(NULL); return E_FAIL; } --- 514,518 ---- mod = PyImport_ImportModule("ctypes.com.server"); if (!mod) { ! MyPyErr_Print("Importing ctypes.com.server in Call_CanUnloadNow"); return E_FAIL; } |
From: Thomas H. <th...@us...> - 2004-10-15 08:23:37
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17271 Modified Files: ChangeLog Log Message: Record changes. Index: ChangeLog =================================================================== RCS file: /cvsroot/ctypes/ctypes/ChangeLog,v retrieving revision 1.66 retrieving revision 1.67 diff -C2 -d -r1.66 -r1.67 *** ChangeLog 15 Oct 2004 07:03:40 -0000 1.66 --- ChangeLog 15 Oct 2004 08:23:18 -0000 1.67 *************** *** 1,4 **** --- 1,8 ---- 2004-10-15 Thomas Heller <th...@py...> + * Reinstalled the magic _abstract_ attribute for Structure and + Union types. If this attribute is defined, the _fields_ attribute + looses it's special meaning. Kept for backwards compatibility. + * Work around a bug in Python's PyUnicode_FromWideChar and PyUnicode_AsWideChar api functions. |
From: Thomas H. <th...@us...> - 2004-10-15 08:23:08
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17010 Modified Files: _ctypes.c Log Message: Reinstall the magic _abstract_ attribute for Structure and Union. Index: _ctypes.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes.c,v retrieving revision 1.169 retrieving revision 1.170 diff -C2 -d -r1.169 -r1.170 *** _ctypes.c 15 Oct 2004 07:00:21 -0000 1.169 --- _ctypes.c 15 Oct 2004 08:22:45 -0000 1.170 *************** *** 132,135 **** --- 132,139 ---- return NULL; + /* keep this for bw compatibility */ + if (PyDict_GetItemString(result->tp_dict, "_abstract_")) + return (PyObject *)result; + fields = PyObject_GetAttrString((PyObject *)result, "_fields_"); if (fields == NULL) { *************** *** 331,334 **** --- 335,342 ---- int isStruct) { + /* keep this for bw compatibility */ + if (PyDict_GetItemString(self->tp_dict, "_abstract_")) + return PyObject_GenericSetAttr((PyObject *)self, name, value); + if (PyString_Check(name) && 0 == strcmp("_fields_", PyString_AS_STRING(name))) { |
From: Thomas H. <th...@us...> - 2004-10-15 08:21:48
|
Update of /cvsroot/ctypes/ctypes/samples In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16740 Modified Files: test_argcount.py Log Message: Comment out a test that no longer works. Index: test_argcount.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/samples/test_argcount.py,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** test_argcount.py 18 Nov 2003 12:43:20 -0000 1.7 --- test_argcount.py 15 Oct 2004 08:21:27 -0000 1.8 *************** *** 15,24 **** strchr.argtypes = [c_char_p, c_int] ! try: ! strchr("abc", 2, 3) ! except TypeError: ! pass ! else: ! raise Exception("didn't catch wrong number of args") try: --- 15,26 ---- strchr.argtypes = [c_char_p, c_int] ! # It is now possible to call cdecl functions with more arguments ! # than specified ibn argtypes (as in C) ! ##try: ! ## strchr("abc", 2, 3) ! ##except TypeError: ! ## pass ! ##else: ! ## raise Exception("didn't catch wrong number of args") try: |
From: Thomas H. <th...@us...> - 2004-10-15 07:03:57
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32270 Modified Files: ChangeLog Log Message: Record changes. Index: ChangeLog =================================================================== RCS file: /cvsroot/ctypes/ctypes/ChangeLog,v retrieving revision 1.65 retrieving revision 1.66 diff -C2 -d -r1.65 -r1.66 *** ChangeLog 13 Oct 2004 19:39:00 -0000 1.65 --- ChangeLog 15 Oct 2004 07:03:40 -0000 1.66 *************** *** 1,2 **** --- 1,13 ---- + 2004-10-15 Thomas Heller <th...@py...> + + * Work around a bug in Python's PyUnicode_FromWideChar and + PyUnicode_AsWideChar api functions. + + 2004-10-14 Thomas Heller <th...@py...> + + * Implemented cycle GC for several internal types fixed some + leaks. Fixed another memory leak and a refcount leak. + Added a unittest to check for leaks. + 2004-10-13 Thomas Heller <th...@py...> *************** *** 5,8 **** --- 16,20 ---- specifies the number of bits in this field. Bit fields are only allowed for numeric types, not for character types like c_char. + Tested on several x86, windows and linux. 2004-10-12 Thomas Heller <th...@py...> |