ctypes-commit Mailing List for ctypes (Page 111)
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-05-07 16:46:00
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11337 Modified Files: callproc.c callbacks.c Log Message: Callback function return types now include c_char and c_char_p (on Windows). Previously, they could only return integers. Index: callbacks.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/callbacks.c,v retrieving revision 1.37 retrieving revision 1.38 diff -C2 -d -r1.37 -r1.38 *** callbacks.c 20 Apr 2004 20:14:56 -0000 1.37 --- callbacks.c 7 May 2004 16:45:50 -0000 1.38 *************** *** 175,180 **** } else { if ((result != Py_None) ! && !PyArg_Parse(result, format, mem)) PyErr_Print(); } Done: --- 175,182 ---- } else { if ((result != Py_None) ! && !PyArg_Parse(result, format, mem)) { ! Extend_Error_Info("(callback return type) "); PyErr_Print(); + } } Done: *************** *** 189,192 **** --- 191,212 ---- #ifdef MS_WIN32 + static int __stdcall z_CallPythonObject(PyObject *callable, + PyObject *converters, + void **pArgs) + { + PyCArgObject result; + _CallPythonObject(&result.value, "z", callable, converters, pArgs); + return result.value.p; + } + + static int __stdcall c_CallPythonObject(PyObject *callable, + PyObject *converters, + void **pArgs) + { + PyCArgObject result; + _CallPythonObject(&result.value, "c", callable, converters, pArgs); + return result.value.i; + } + static int __stdcall i_CallPythonObject(PyObject *callable, PyObject *converters, *************** *** 407,410 **** --- 427,436 ---- PrepareResult(restype, &result); switch (result.tag) { + case 'z': + func = (DWORD)z_CallPythonObject; + break; + case 'c': + func = (DWORD)c_CallPythonObject; + break; /* "bBhHiIlLqQdfP" */ case 'b': Index: callproc.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/callproc.c,v retrieving revision 1.63 retrieving revision 1.64 diff -C2 -d -r1.63 -r1.64 *** callproc.c 6 May 2004 19:54:04 -0000 1.63 --- callproc.c 7 May 2004 16:45:44 -0000 1.64 *************** *** 915,919 **** attribute */ ! if (strchr("bBhHiIlLqQdfP", fmt[0])) { result->tag = fmt[0]; return; --- 915,919 ---- attribute */ ! if (strchr("zcbBhHiIlLqQdfP", fmt[0])) { result->tag = fmt[0]; return; |
From: Thomas H. <th...@us...> - 2004-05-07 07:36:59
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28152 Modified Files: test_random_things.py Log Message: Print full tracebacks when exceptions occurr in callbacks. Index: test_random_things.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_random_things.py,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** test_random_things.py 4 May 2004 09:16:23 -0000 1.3 --- test_random_things.py 7 May 2004 07:36:49 -0000 1.4 *************** *** 2,10 **** import unittest, sys ! def __del__(self): ! pass if sys.platform == "win32": class MyTestCase(unittest.TestCase): def setUp(self): from ctypes.com import IUnknown --- 2,60 ---- import unittest, sys ! def callback_func(arg): ! 42 / arg ! raise ValueError, arg ! ! class CallbackTracbackTestCase(unittest.TestCase): ! # When an exception is raised in a ctypes callback function, the C ! # code prints a traceback. ! # ! # This test makes sure the exception types *and* the exception ! # value is printed correctly - the exception value is converted ! # into a string, and '(in callback)' is prepended to it. ! ! def capture_stderr(self, func, *args, **kw): ! # helper - call function 'func', and return the captured stderr ! import StringIO ! logger = sys.stderr = StringIO.StringIO() ! try: ! func(*args, **kw) ! finally: ! sys.stderr = sys.__stderr__ ! return logger.getvalue() ! ! def test_ValueError(self): ! cb = CFUNCTYPE(c_int, c_int)(callback_func) ! out = self.capture_stderr(cb, 42) ! self.failUnlessEqual(out.splitlines()[-1], ! "ValueError: (in callback) 42") ! ! def test_IntegerDivisionError(self): ! cb = CFUNCTYPE(c_int, c_int)(callback_func) ! out = self.capture_stderr(cb, 0) ! self.failUnlessEqual(out.splitlines()[-1], ! "ZeroDivisionError: (in callback) integer division or modulo by zero") ! ! def test_FloatDivisionError(self): ! cb = CFUNCTYPE(c_int, c_double)(callback_func) ! out = self.capture_stderr(cb, 0.0) ! self.failUnlessEqual(out.splitlines()[-1], ! "ZeroDivisionError: (in callback) float division") ! ! def test_TypeErrorDivisionError(self): ! cb = CFUNCTYPE(c_int, c_char_p)(callback_func) ! out = self.capture_stderr(cb, "spam") ! self.failUnlessEqual(out.splitlines()[-1], ! "TypeError: (in callback) unsupported operand type(s) for /: 'int' and 'str'") if sys.platform == "win32": + def __del__(self): + pass + class MyTestCase(unittest.TestCase): + # This test makes sure that calling a COM method on a COM + # interface pointer raises a ValueError, when the interface + # pointer points to NULL. + def setUp(self): from ctypes.com import IUnknown |
From: Thomas H. <th...@us...> - 2004-05-06 20:04:54
|
Update of /cvsroot/ctypes/ctypes/build/lib.win32-2.4 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12622 Modified Files: _ctypes_test.pyd _ctypes.pyd Log Message: Update the changelog, and commit recompiled binaries. Index: _ctypes_test.pyd =================================================================== RCS file: /cvsroot/ctypes/ctypes/build/lib.win32-2.4/_ctypes_test.pyd,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 Binary files /tmp/cvsJi09Wd and /tmp/cvsOxZmN7 differ Index: _ctypes.pyd =================================================================== RCS file: /cvsroot/ctypes/ctypes/build/lib.win32-2.4/_ctypes.pyd,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 Binary files /tmp/cvsO06JEq and /tmp/cvsRohMJk differ |
From: Thomas H. <th...@us...> - 2004-05-06 20:04:43
|
Update of /cvsroot/ctypes/ctypes/build/lib.win32-2.3 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12581 Modified Files: _ctypes_test.pyd _ctypes.pyd Log Message: Update the changelog, and commit recompiled binaries. Index: _ctypes_test.pyd =================================================================== RCS file: /cvsroot/ctypes/ctypes/build/lib.win32-2.3/_ctypes_test.pyd,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 Binary files /tmp/cvsL324VC and /tmp/cvsftng6n differ Index: _ctypes.pyd =================================================================== RCS file: /cvsroot/ctypes/ctypes/build/lib.win32-2.3/_ctypes.pyd,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 Binary files /tmp/cvseZxfy8 and /tmp/cvs5HukbU differ |
From: Thomas H. <th...@us...> - 2004-05-06 20:04:37
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12528 Modified Files: ChangeLog Log Message: Update the changelog, and commit recompiled binaries. Index: ChangeLog =================================================================== RCS file: /cvsroot/ctypes/ctypes/ChangeLog,v retrieving revision 1.39 retrieving revision 1.40 diff -C2 -d -r1.39 -r1.40 *** ChangeLog 3 May 2004 15:17:11 -0000 1.39 --- ChangeLog 6 May 2004 20:04:23 -0000 1.40 *************** *** 1,2 **** --- 1,8 ---- + 2004-05-06 Thomas Heller <th...@py...> + + * Finally fixed the sometimes shortened traceback prints when an + exception occurrs in a callback function - only the exception + class was printed, not the value. + 2004-05-03 Thomas Heller <th...@py...> |
From: Thomas H. <th...@us...> - 2004-05-06 20:03:49
|
Update of /cvsroot/ctypes/ctypes/build/lib.win32-2.4 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12360 Modified Files: .cvsignore Log Message: Ignore the debug binaries. Index: .cvsignore =================================================================== RCS file: /cvsroot/ctypes/ctypes/build/lib.win32-2.4/.cvsignore,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** .cvsignore 20 Apr 2004 20:14:02 -0000 1.1 --- .cvsignore 6 May 2004 20:03:36 -0000 1.2 *************** *** 1 **** --- 1,5 ---- + _ctypes_d.pdb + _ctypes_d.pyd + _ctypes_test_d.pdb + _ctypes_test_d.pyd ctypes |
From: Thomas H. <th...@us...> - 2004-05-06 20:03:35
|
Update of /cvsroot/ctypes/ctypes/build/lib.win32-2.3 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12341 Modified Files: .cvsignore Log Message: Ignore the debug binaries. Index: .cvsignore =================================================================== RCS file: /cvsroot/ctypes/ctypes/build/lib.win32-2.3/.cvsignore,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** .cvsignore 20 Apr 2004 20:13:53 -0000 1.1 --- .cvsignore 6 May 2004 20:03:27 -0000 1.2 *************** *** 1 **** --- 1,3 ---- + _ctypes_d.pyd + _ctypes_test_d.pyd ctypes |
From: Thomas H. <th...@us...> - 2004-05-06 20:02:01
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11938 Modified Files: test_values.py Log Message: Fixed the test case to also work with python 2.4 Index: test_values.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_values.py,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** test_values.py 4 May 2004 09:16:23 -0000 1.9 --- test_values.py 6 May 2004 20:01:52 -0000 1.10 *************** *** 73,77 **** items.append((entry.name, entry.size)) import sys ! if sys.version_info[:2] == (2, 3): expected = [("__hello__", 104), ("__phello__", -104), ("__phello__.spam", 104)] else: --- 73,77 ---- items.append((entry.name, entry.size)) import sys ! if sys.version_info[:2] >= (2, 3): expected = [("__hello__", 104), ("__phello__", -104), ("__phello__.spam", 104)] else: |
From: Thomas H. <th...@us...> - 2004-05-06 19:54:13
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10195 Modified Files: callproc.c Log Message: Clearer code - avoid reusing variables for different things. Index: callproc.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/callproc.c,v retrieving revision 1.62 retrieving revision 1.63 diff -C2 -d -r1.62 -r1.63 *** callproc.c 6 May 2004 19:53:08 -0000 1.62 --- callproc.c 6 May 2004 19:54:04 -0000 1.63 *************** *** 1033,1040 **** PyString_ConcatAndDel(&s, msg); Py_DECREF(v); ! v = s; ! } else PyErr_Clear(); ! PyErr_Restore(tp, v, tb); } --- 1033,1041 ---- PyString_ConcatAndDel(&s, msg); Py_DECREF(v); ! PyErr_Restore(tp, s, tb); ! } else { PyErr_Clear(); ! PyErr_Restore(tp, v, tb); ! } } |
From: Thomas H. <th...@us...> - 2004-05-06 19:53:17
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9962 Modified Files: callproc.c Log Message: Fix an obvious bug. Index: callproc.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/callproc.c,v retrieving revision 1.61 retrieving revision 1.62 diff -C2 -d -r1.61 -r1.62 *** callproc.c 6 May 2004 19:24:03 -0000 1.61 --- callproc.c 6 May 2004 19:53:08 -0000 1.62 *************** *** 1033,1037 **** PyString_ConcatAndDel(&s, msg); Py_DECREF(v); ! v = msg; } else PyErr_Clear(); --- 1033,1037 ---- PyString_ConcatAndDel(&s, msg); Py_DECREF(v); ! v = s; } else PyErr_Clear(); |
From: Thomas H. <th...@us...> - 2004-05-06 19:24:26
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4315 Modified Files: callproc.c Log Message: Fix the sometimes shortened traceback prints when an exception occurrs in a callback function. Instead of printing the full traceback like this Exception: exception message only the exception class name was printed in this way: Exception The problem was that I was calling PyString_ConcatAndDel(&string, newpart) with newpart not being a Python string. Index: callproc.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/callproc.c,v retrieving revision 1.60 retrieving revision 1.61 diff -C2 -d -r1.60 -r1.61 *** callproc.c 20 Apr 2004 20:14:44 -0000 1.60 --- callproc.c 6 May 2004 19:24:03 -0000 1.61 *************** *** 1019,1023 **** { va_list vargs; ! PyObject *tp, *v, *tb, *s; va_start(vargs, fmt); --- 1019,1023 ---- { va_list vargs; ! PyObject *tp, *v, *tb, *s, *msg; va_start(vargs, fmt); *************** *** 1028,1033 **** PyErr_Fetch(&tp, &v, &tb); ! PyString_ConcatAndDel(&s, v); ! PyErr_Restore(tp, s, tb); } --- 1028,1040 ---- PyErr_Fetch(&tp, &v, &tb); ! PyErr_NormalizeException(&tp, &v, &tb); ! msg = PyObject_Str(v); ! if (msg) { ! PyString_ConcatAndDel(&s, msg); ! Py_DECREF(v); ! v = msg; ! } else ! PyErr_Clear(); ! PyErr_Restore(tp, v, tb); } |
From: Thomas H. <th...@us...> - 2004-05-04 09:21:55
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6041 Modified Files: test_stringptr.py test_internals.py Log Message: Call unittest's main() function. Index: test_stringptr.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_stringptr.py,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** test_stringptr.py 4 May 2004 09:15:19 -0000 1.5 --- test_stringptr.py 4 May 2004 09:21:16 -0000 1.6 *************** *** 73,75 **** if __name__ == '__main__': ! test() --- 73,75 ---- if __name__ == '__main__': ! unittest.main() Index: test_internals.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_internals.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** test_internals.py 4 May 2004 09:15:19 -0000 1.2 --- test_internals.py 4 May 2004 09:21:16 -0000 1.3 *************** *** 103,105 **** if __name__ == '__main__': ! test() --- 103,105 ---- if __name__ == '__main__': ! unittest.main() |
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4974 Modified Files: test_win32.py test_variant.py test_values.py test_strings.py test_random_things.py test_prototypes.py test_comobject.py Log Message: Some test code has to be reorganized. Index: test_win32.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_win32.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** test_win32.py 21 Jan 2004 19:59:48 -0000 1.2 --- test_win32.py 4 May 2004 09:16:23 -0000 1.3 *************** *** 2,53 **** from ctypes import * ! import unittest ! ! class WindowsTestCase(unittest.TestCase): ! def test_callconv_1(self): ! "Call functions with the wrong number of arguments, or the wrong calling convention" ! GetModuleHandle = windll.kernel32.GetModuleHandleA ! # ValueError: Procedure probably called with not enough arguments (4 bytes missing) ! self.assertRaises(ValueError, GetModuleHandle) ! # This one should succeeed... ! self.failUnless(GetModuleHandle(None)) ! # ValueError: Procedure probably called with too many arguments (8 bytes in excess) ! self.assertRaises(ValueError, GetModuleHandle, 0, 0, 0) ! def test_callconv_2(self): ! "Call functions with the wrong number of arguments, or the wrong calling convention" ! GetModuleHandleA = cdll.kernel32.GetModuleHandleA ! # ValueError: Procedure called with not enough arguments (4 bytes missing) ! # or wrong calling convention ! self.assertRaises(ValueError, GetModuleHandleA, None) ! self.assertRaises(ValueError, GetModuleHandleA) ! def test_SEH(self): ! """Call functions with invalid arguments, and make sure that access violations ! are trapped and raise an exception""" ! self.assertRaises(WindowsError, windll.kernel32.GetModuleHandleA, 32) ! # TODO: Add tests for passing structures (and unions?) by value. ! def test_struct_by_value(self): ! from ctypes.wintypes import POINT, RECT ! pt = POINT(10, 10) ! rect = RECT(0, 0, 20, 20) ! self.failUnlessEqual(True, windll.user32.PtInRect(byref(rect), pt)) ! def get_suite(): ! import os ! if os.name == "nt": ! return unittest.makeSuite(WindowsTestCase) ! else: ! return None ! def test(verbose=0): ! runner = unittest.TextTestRunner(verbosity=verbose) ! runner.run(get_suite()) if __name__ == '__main__': --- 2,44 ---- from ctypes import * ! import unittest, sys ! if sys.platform == "win32": ! class WindowsTestCase(unittest.TestCase): ! def test_callconv_1(self): ! "Call functions with the wrong number of arguments, or the wrong calling convention" ! GetModuleHandle = windll.kernel32.GetModuleHandleA ! # ValueError: Procedure probably called with not enough arguments (4 bytes missing) ! self.assertRaises(ValueError, GetModuleHandle) ! # This one should succeeed... ! self.failUnless(GetModuleHandle(None)) ! # ValueError: Procedure probably called with too many arguments (8 bytes in excess) ! self.assertRaises(ValueError, GetModuleHandle, 0, 0, 0) ! def test_callconv_2(self): ! "Call functions with the wrong number of arguments, or the wrong calling convention" ! GetModuleHandleA = cdll.kernel32.GetModuleHandleA ! # ValueError: Procedure called with not enough arguments (4 bytes missing) ! # or wrong calling convention ! self.assertRaises(ValueError, GetModuleHandleA, None) ! self.assertRaises(ValueError, GetModuleHandleA) ! def test_SEH(self): ! """Call functions with invalid arguments, and make sure that access violations ! are trapped and raise an exception""" ! self.assertRaises(WindowsError, windll.kernel32.GetModuleHandleA, 32) ! # TODO: Add tests for passing structures (and unions?) by value. ! def test_struct_by_value(self): ! from ctypes.wintypes import POINT, RECT ! pt = POINT(10, 10) ! rect = RECT(0, 0, 20, 20) ! self.failUnlessEqual(True, windll.user32.PtInRect(byref(rect), pt)) if __name__ == '__main__': Index: test_random_things.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_random_things.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** test_random_things.py 20 Apr 2004 20:16:28 -0000 1.2 --- test_random_things.py 4 May 2004 09:16:23 -0000 1.3 *************** *** 1,41 **** from ctypes import * ! import unittest def __del__(self): pass ! class MyTestCase(unittest.TestCase): ! def setUp(self): ! from ctypes.com import IUnknown ! self._orig_del = POINTER(IUnknown).__del__ ! # We replace the __del__ method (which calls self.Release(), ! # because it would crash. ! POINTER(IUnknown).__del__ = __del__ ! ! def tearDown(self): ! from ctypes.com import IUnknown ! POINTER(IUnknown).__del__ = self._orig_del ! ! def test_comcrash(self): ! from ctypes.com import IUnknown ! p = pointer(IUnknown()) ! try: ! p.AddRef() ! except ValueError, message: ! self.failUnlessEqual(str(message), "COM method call without VTable") ! else: ! self.fail("Exception expected") ! def get_suite(): ! import os ! if os.name == "nt": ! return unittest.makeSuite(MyTestCase) ! else: ! return None ! def test(verbose=0): ! runner = unittest.TextTestRunner(verbosity=verbose) ! runner.run(get_suite()) if __name__ == '__main__': ! test() --- 1,31 ---- from ctypes import * ! import unittest, sys def __del__(self): pass ! if sys.platform == "win32": ! class MyTestCase(unittest.TestCase): ! def setUp(self): ! from ctypes.com import IUnknown ! self._orig_del = POINTER(IUnknown).__del__ ! # We replace the __del__ method (which calls self.Release(), ! # because it would crash. ! POINTER(IUnknown).__del__ = __del__ ! def tearDown(self): ! from ctypes.com import IUnknown ! POINTER(IUnknown).__del__ = self._orig_del ! def test_comcrash(self): ! from ctypes.com import IUnknown ! p = pointer(IUnknown()) ! try: ! p.AddRef() ! except ValueError, message: ! self.failUnlessEqual(str(message), "COM method call without VTable") ! else: ! self.fail("Exception expected") if __name__ == '__main__': ! unittest.main() Index: test_values.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_values.py,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** test_values.py 20 Jan 2004 19:52:19 -0000 1.8 --- test_values.py 4 May 2004 09:16:23 -0000 1.9 *************** *** 7,12 **** import _ctypes_test - pydll = None - class ValuesTestCase(unittest.TestCase): --- 7,10 ---- *************** *** 23,97 **** self.assertRaises(ValueError, c_int.in_dll, ctdll, "Undefined_Symbol") ! class Win_ValuesTestCase(unittest.TestCase): ! """This test only works when python itself is a dll/shared library""" ! ! def test_optimizeflag(self): ! """This test accesses the Py_OptimizeFlag intger, which is ! exported by the Python dll. ! ! It's value is set depending on the -O and -OO flags: ! if not given, it is 0 and __debug__ is 1. ! If -O is given, the flag is 1, for -OO it is 2. ! docstrings are also removed in the latter case.""" ! opt = c_int.in_dll(pydll, "Py_OptimizeFlag").value ! if __debug__: ! self.failUnlessEqual(opt, 0) ! elif ValuesTestCase.__doc__ is not None: ! self.failUnlessEqual(opt, 1) ! else: ! self.failUnlessEqual(opt, 2) ! def test_frozentable(self): ! """Python exports a PyImport_FrozenModules symbol. This is a ! pointer to an array of struct _frozen entries. The end of the ! array is marked by an entry containing a NULL name and zero ! size. ! In standard Python, this table contains a __hello__ module, ! and a __phello__ package containing a spam module.""" ! class struct_frozen(Structure): ! _fields_ = [("name", c_char_p), ! ("code", POINTER(c_ubyte)), ! ("size", c_int)] ! FrozenTable = POINTER(struct_frozen) ! ft = FrozenTable.in_dll(pydll, "PyImport_FrozenModules") ! # ft is a pointer to the struct_frozen entries: ! items = [] ! for entry in ft: ! # This is dangerous. We *can* iterate over a pointer, but ! # the loop will not terminate (maybe with an access ! # violation;-) because the pointer instance has no size. ! if entry.name is None: ! break ! items.append((entry.name, entry.size)) ! import sys ! if sys.version_info[:2] == (2, 3): ! expected = [("__hello__", 104), ("__phello__", -104), ("__phello__.spam", 104)] ! else: ! expected = [("__hello__", 100), ("__phello__", -100), ("__phello__.spam", 100)] ! self.failUnlessEqual(items, expected) ! def test_undefined(self): ! self.assertRaises(ValueError, c_int.in_dll, pydll, "Undefined_Symbol") ! def test(verbose=0): ! runner = unittest.TextTestRunner(verbosity=verbose) ! runner.run(get_suite()) ! def get_suite(): ! import sys ! name = "python%s%s" % sys.version_info[:2] ! global pydll ! try: ! pydll = getattr(cdll, name) ! except: ! return unittest.makeSuite(ValuesTestCase) ! return unittest.TestSuite((unittest.makeSuite(ValuesTestCase), ! unittest.makeSuite(Win_ValuesTestCase))) if __name__ == '__main__': ! import sys ! verbose = "-v" in sys.argv ! test(verbose=verbose) --- 21,85 ---- self.assertRaises(ValueError, c_int.in_dll, ctdll, "Undefined_Symbol") ! import sys ! name = "python%s%s" % sys.version_info[:2] ! try: ! pydll = getattr(cdll, name) ! except: ! pass ! else: ! class Win_ValuesTestCase(unittest.TestCase): ! """This test only works when python itself is a dll/shared library""" ! def test_optimizeflag(self): ! """This test accesses the Py_OptimizeFlag intger, which is ! exported by the Python dll. ! It's value is set depending on the -O and -OO flags: ! if not given, it is 0 and __debug__ is 1. ! If -O is given, the flag is 1, for -OO it is 2. ! docstrings are also removed in the latter case.""" ! opt = c_int.in_dll(pydll, "Py_OptimizeFlag").value ! if __debug__: ! self.failUnlessEqual(opt, 0) ! elif ValuesTestCase.__doc__ is not None: ! self.failUnlessEqual(opt, 1) ! else: ! self.failUnlessEqual(opt, 2) ! def test_frozentable(self): ! """Python exports a PyImport_FrozenModules symbol. This is a ! pointer to an array of struct _frozen entries. The end of the ! array is marked by an entry containing a NULL name and zero ! size. ! In standard Python, this table contains a __hello__ module, ! and a __phello__ package containing a spam module.""" ! class struct_frozen(Structure): ! _fields_ = [("name", c_char_p), ! ("code", POINTER(c_ubyte)), ! ("size", c_int)] ! FrozenTable = POINTER(struct_frozen) ! ft = FrozenTable.in_dll(pydll, "PyImport_FrozenModules") ! # ft is a pointer to the struct_frozen entries: ! items = [] ! for entry in ft: ! # This is dangerous. We *can* iterate over a pointer, but ! # the loop will not terminate (maybe with an access ! # violation;-) because the pointer instance has no size. ! if entry.name is None: ! break ! items.append((entry.name, entry.size)) ! import sys ! if sys.version_info[:2] == (2, 3): ! expected = [("__hello__", 104), ("__phello__", -104), ("__phello__.spam", 104)] ! else: ! expected = [("__hello__", 100), ("__phello__", -100), ("__phello__.spam", 100)] ! self.failUnlessEqual(items, expected) ! def test_undefined(self): ! self.assertRaises(ValueError, c_int.in_dll, pydll, "Undefined_Symbol") if __name__ == '__main__': ! unittest.main() Index: test_prototypes.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_prototypes.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** test_prototypes.py 20 Apr 2004 20:16:28 -0000 1.2 --- test_prototypes.py 4 May 2004 09:16:23 -0000 1.3 *************** *** 119,177 **** ## self.failUnlessEqual(0, func(X())) ! class WCharPointersTestCase(unittest.TestCase): ! ! def setUp(self): ! func = testdll._testfunc_p_p ! func.restype = c_int ! func.argtypes = None - def test_POINTER_c_wchar_arg(self): - func = testdll._testfunc_p_p - func.restype = c_wchar_p - func.argtypes = POINTER(c_wchar), ! self.failUnlessEqual(None, func(None)) ! self.failUnlessEqual(u"123", func(u"123")) ! self.failUnlessEqual(None, func(c_wchar_p(None))) ! self.failUnlessEqual(u"123", func(c_wchar_p(u"123"))) ! self.failUnlessEqual(u"123", func(c_wbuffer(u"123"))) ! ca = c_wchar("a") ! self.failUnlessEqual(u"a", func(pointer(ca))[0]) ! self.failUnlessEqual(u"a", func(byref(ca))[0]) ! def test_c_wchar_p_arg(self): ! func = testdll._testfunc_p_p ! func.restype = c_wchar_p ! func.argtypes = c_wchar_p, ! c_wchar_p.from_param(u"123") ! ! self.failUnlessEqual(None, func(None)) ! self.failUnlessEqual("123", func(u"123")) ! self.failUnlessEqual(None, func(c_wchar_p(None))) ! self.failUnlessEqual("123", func(c_wchar_p("123"))) ! # XXX Currently, these raise TypeErrors, although they shouldn't: ! self.failUnlessEqual("123", func(c_wbuffer("123"))) ! ca = c_wchar("a") ! self.failUnlessEqual("a", func(pointer(ca))[0]) ! self.failUnlessEqual("a", func(byref(ca))[0]) ! ################################################################ ! def get_suite(): ! try: ! c_wchar ! except NameError: ! return unittest.makeSuite(CharPointersTestCase) ! else: ! return unittest.TestSuite((unittest.makeSuite(CharPointersTestCase), ! unittest.makeSuite(WCharPointersTestCase))) ! def test(verbose=0): ! runner = unittest.TextTestRunner(verbosity=verbose) ! runner.run(get_suite()) if __name__ == '__main__': --- 119,169 ---- ## self.failUnlessEqual(0, func(X())) ! try: ! c_wchar ! except NameError: ! pass ! else: ! class WCharPointersTestCase(unittest.TestCase): + def setUp(self): + func = testdll._testfunc_p_p + func.restype = c_int + func.argtypes = None ! def test_POINTER_c_wchar_arg(self): ! func = testdll._testfunc_p_p ! func.restype = c_wchar_p ! func.argtypes = POINTER(c_wchar), ! self.failUnlessEqual(None, func(None)) ! self.failUnlessEqual(u"123", func(u"123")) ! self.failUnlessEqual(None, func(c_wchar_p(None))) ! self.failUnlessEqual(u"123", func(c_wchar_p(u"123"))) ! self.failUnlessEqual(u"123", func(c_wbuffer(u"123"))) ! ca = c_wchar("a") ! self.failUnlessEqual(u"a", func(pointer(ca))[0]) ! self.failUnlessEqual(u"a", func(byref(ca))[0]) ! def test_c_wchar_p_arg(self): ! func = testdll._testfunc_p_p ! func.restype = c_wchar_p ! func.argtypes = c_wchar_p, ! c_wchar_p.from_param(u"123") ! self.failUnlessEqual(None, func(None)) ! self.failUnlessEqual("123", func(u"123")) ! self.failUnlessEqual(None, func(c_wchar_p(None))) ! self.failUnlessEqual("123", func(c_wchar_p("123"))) ! # XXX Currently, these raise TypeErrors, although they shouldn't: ! self.failUnlessEqual("123", func(c_wbuffer("123"))) ! ca = c_wchar("a") ! self.failUnlessEqual("a", func(pointer(ca))[0]) ! self.failUnlessEqual("a", func(byref(ca))[0]) ! ################################################################ if __name__ == '__main__': Index: test_variant.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_variant.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** test_variant.py 20 Apr 2004 20:16:25 -0000 1.2 --- test_variant.py 4 May 2004 09:16:23 -0000 1.3 *************** *** 9,84 **** return comptr.Release() ! class VariantTestCase(unittest.TestCase): ! ! def __init__(self, *args): ! # We cannot import these at module level, but want these to be ! # available in the global namespace ! global IUnknown, VARIANT, LoadTypeLibEx, DISPPARAMS, LoadRegTypeLib, GUID ! from ctypes.com import IUnknown, GUID ! from ctypes.com.automation import VARIANT, LoadTypeLibEx, DISPPARAMS, LoadRegTypeLib ! unittest.TestCase.__init__(self, *args) ! def test_com_refcounts(self): ! # typelib for Internet Explorer ! tlb = LoadRegTypeLib(GUID("{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}"), 1, 1, 0) ! self.failUnlessEqual(get_refcnt(tlb), 1) ! p = POINTER(IUnknown)() ! tlb.QueryInterface(byref(IUnknown._iid_), byref(p)) ! self.failUnlessEqual(get_refcnt(tlb), 2) ! del p ! self.failUnlessEqual(get_refcnt(tlb), 1) ! ! def test_com_pointers(self): ! """Storing a COM interface pointer in a VARIANT increments the refcount, ! changing the variant to contain something else decrements it""" ! tlb = LoadRegTypeLib(GUID("{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}"), 1, 1, 0) ! self.failUnlessEqual(get_refcnt(tlb), 1) - v = VARIANT(tlb) - self.failUnlessEqual(get_refcnt(tlb), 2) ! p = v.value ! self.failUnlessEqual(get_refcnt(tlb), 3) ! del p ! self.failUnlessEqual(get_refcnt(tlb), 2) ! v.value = None ! self.failUnlessEqual(get_refcnt(tlb), 1) ! def test_null_com_pointers(self): ! p = POINTER(IUnknown)() ! self.failUnlessEqual(get_refcnt(p), 0) - v = VARIANT(p) - self.failUnlessEqual(get_refcnt(p), 0) ! def test_dispparams(self): ! # DISPPARAMS is a complex structure, well worth testing. ! d = DISPPARAMS() ! d.rgvarg = (VARIANT * 3)() ! # XXX The following line fails, which is a real bug in ctypes: ! # SystemError: ...\Objects\listobject.c:105: bad argument to internal function ! ## d.rgvarg[0].value = 1 ! def test_pythonobjects(self): ! objects = [None, 42, 3.14, True, False, "abc", u"abc"] ! for x in objects: ! v = VARIANT(x) ! self.failUnlessEqual(x, v.value) ! ################################################################ ! def get_suite(): ! if os.name == "nt": ! return unittest.makeSuite(VariantTestCase) ! return None ! def test(verbose=0): ! runner = unittest.TextTestRunner(verbosity=verbose) ! runner.run(get_suite()) if __name__ == '__main__': --- 9,76 ---- return comptr.Release() ! if os.name == "nt": ! class VariantTestCase(unittest.TestCase): ! def __init__(self, *args): ! # We cannot import these at module level, but want these to be ! # available in the global namespace ! global IUnknown, VARIANT, LoadTypeLibEx, DISPPARAMS, LoadRegTypeLib, GUID ! from ctypes.com import IUnknown, GUID ! from ctypes.com.automation import VARIANT, LoadTypeLibEx, DISPPARAMS, LoadRegTypeLib ! unittest.TestCase.__init__(self, *args) ! def test_com_refcounts(self): ! # typelib for Internet Explorer ! tlb = LoadRegTypeLib(GUID("{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}"), 1, 1, 0) ! self.failUnlessEqual(get_refcnt(tlb), 1) ! p = POINTER(IUnknown)() ! tlb.QueryInterface(byref(IUnknown._iid_), byref(p)) ! self.failUnlessEqual(get_refcnt(tlb), 2) ! del p ! self.failUnlessEqual(get_refcnt(tlb), 1) ! def test_com_pointers(self): ! """Storing a COM interface pointer in a VARIANT increments the refcount, ! changing the variant to contain something else decrements it""" ! tlb = LoadRegTypeLib(GUID("{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}"), 1, 1, 0) ! self.failUnlessEqual(get_refcnt(tlb), 1) ! v = VARIANT(tlb) ! self.failUnlessEqual(get_refcnt(tlb), 2) + p = v.value + self.failUnlessEqual(get_refcnt(tlb), 3) + del p + self.failUnlessEqual(get_refcnt(tlb), 2) ! v.value = None ! self.failUnlessEqual(get_refcnt(tlb), 1) ! def test_null_com_pointers(self): ! p = POINTER(IUnknown)() ! self.failUnlessEqual(get_refcnt(p), 0) ! v = VARIANT(p) ! self.failUnlessEqual(get_refcnt(p), 0) ! def test_dispparams(self): ! # DISPPARAMS is a complex structure, well worth testing. ! d = DISPPARAMS() ! d.rgvarg = (VARIANT * 3)() ! # XXX The following line fails, which is a real bug in ctypes: ! # SystemError: ...\Objects\listobject.c:105: bad argument to internal function ! ## d.rgvarg[0].value = 1 ! def test_pythonobjects(self): ! objects = [None, 42, 3.14, True, False, "abc", u"abc"] ! for x in objects: ! v = VARIANT(x) ! self.failUnlessEqual(x, v.value) ! ################################################################ if __name__ == '__main__': Index: test_comobject.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_comobject.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** test_comobject.py 20 Apr 2004 20:16:28 -0000 1.2 --- test_comobject.py 4 May 2004 09:16:23 -0000 1.3 *************** *** 1,3 **** ! import unittest, os from ctypes import * --- 1,3 ---- ! import unittest, os, sys from ctypes import * *************** *** 8,82 **** return comptr.Release() ! class ComTestCase(unittest.TestCase): ! def __init__(self, *args): ! unittest.TestCase.__init__(self, *args) ! global COMObject, IUnknown, GUID ! from ctypes.com import COMObject, IUnknown, GUID ! def setUp(self): ! class Factory(object): ! def LockServer(self, *args): ! pass ! class MyObject(COMObject): ! _factory = Factory() ! _com_interfaces_ = [IUnknown] ! self.impl = MyObject() ! def tearDown(self): ! self.impl = None ! ################ ! def test_comobject(self): ! impl = self.impl ! self.failUnlessEqual(impl._refcnt, 0) ! p = pointer(impl._com_pointers_[0][1]) ! p.AddRef() ! self.failUnlessEqual(impl._refcnt, 1) ! self.failUnlessEqual(get_refcnt(p), 1) ! del p ! self.failUnlessEqual(impl._refcnt, 0) ! def test_qi(self): ! impl = self.impl ! self.failUnlessEqual(impl._refcnt, 0) ! p = pointer(impl._com_pointers_[0][1]) ! p.AddRef() ! self.failUnlessEqual(get_refcnt(p), 1) ! p2 = POINTER(IUnknown)() ! p.QueryInterface(byref(IUnknown._iid_), byref(p2)) ! self.failUnlessEqual(get_refcnt(p), 2) ! def test_from_progid(self): ! g = GUID.from_progid("InternetExplorer.Application") ! self.failUnlessEqual(g, GUID("{0002DF01-0000-0000-C000-000000000046}")) ! def test_GUID(self): ! g1 = GUID("{00000000-0001-0002-0003-000000000000}") ! g2 = GUID("{00000000-0001-0002-0003-000000000000}") ! g3 = GUID("{00000000-0001-0002-0003-000000000001}") ! self.failUnlessEqual(g1, g2) ! # for now, GUID instances are unhashable. ! ## d = {} ! ## d[g1] = None ! ## self.failUnlessEqual(g1 in d, True) ! ## self.failUnlessEqual(g2 in d, True) ! ## self.failUnlessEqual(g3 in d, False) ################################################################ - def get_suite(): - if os.name == "nt": - return unittest.makeSuite(ComTestCase) - return None - - def test(verbose=0): - runner = unittest.TextTestRunner(verbosity=verbose) - runner.run(get_suite()) - if __name__ == '__main__': unittest.main() --- 8,74 ---- return comptr.Release() ! if sys.platform == "win32": ! class ComTestCase(unittest.TestCase): ! def __init__(self, *args): ! unittest.TestCase.__init__(self, *args) ! global COMObject, IUnknown, GUID ! from ctypes.com import COMObject, IUnknown, GUID ! def setUp(self): ! class Factory(object): ! def LockServer(self, *args): ! pass ! class MyObject(COMObject): ! _factory = Factory() ! _com_interfaces_ = [IUnknown] ! self.impl = MyObject() ! def tearDown(self): ! self.impl = None ! ################ ! def test_comobject(self): ! impl = self.impl ! self.failUnlessEqual(impl._refcnt, 0) ! p = pointer(impl._com_pointers_[0][1]) ! p.AddRef() ! self.failUnlessEqual(impl._refcnt, 1) ! self.failUnlessEqual(get_refcnt(p), 1) ! del p ! self.failUnlessEqual(impl._refcnt, 0) ! def test_qi(self): ! impl = self.impl ! self.failUnlessEqual(impl._refcnt, 0) ! p = pointer(impl._com_pointers_[0][1]) ! p.AddRef() ! self.failUnlessEqual(get_refcnt(p), 1) ! p2 = POINTER(IUnknown)() ! p.QueryInterface(byref(IUnknown._iid_), byref(p2)) ! self.failUnlessEqual(get_refcnt(p), 2) ! def test_from_progid(self): ! g = GUID.from_progid("InternetExplorer.Application") ! self.failUnlessEqual(g, GUID("{0002DF01-0000-0000-C000-000000000046}")) ! def test_GUID(self): ! g1 = GUID("{00000000-0001-0002-0003-000000000000}") ! g2 = GUID("{00000000-0001-0002-0003-000000000000}") ! g3 = GUID("{00000000-0001-0002-0003-000000000001}") ! self.failUnlessEqual(g1, g2) ! # for now, GUID instances are unhashable. ! ## d = {} ! ## d[g1] = None ! ## self.failUnlessEqual(g1 in d, True) ! ## self.failUnlessEqual(g2 in d, True) ! ## self.failUnlessEqual(g3 in d, False) ################################################################ if __name__ == '__main__': unittest.main() Index: test_strings.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_strings.py,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** test_strings.py 20 Apr 2004 20:16:27 -0000 1.13 --- test_strings.py 4 May 2004 09:16:23 -0000 1.14 *************** *** 54,72 **** ## print BUF.from_param(BUF(*"pyth")) ! class WStringArrayTestCase(unittest.TestCase): ! def test(self): ! BUF = c_wchar * 4 ! buf = BUF(u"a", u"b", u"c") ! self.failUnless(buf.value == u"abc") ! buf.value = u"ABCD" ! self.failUnless(buf.value == u"ABCD") ! buf.value = u"x" ! self.failUnless(buf.value == u"x") ! buf[1] = u"Z" ! self.failUnless(buf.value == u"xZCD") class StringTestCase(unittest.TestCase): --- 54,77 ---- ## print BUF.from_param(BUF(*"pyth")) ! try: ! c_wchar ! except NameError: ! pass ! else: ! class WStringArrayTestCase(unittest.TestCase): ! def test(self): ! BUF = c_wchar * 4 ! buf = BUF(u"a", u"b", u"c") ! self.failUnless(buf.value == u"abc") ! buf.value = u"ABCD" ! self.failUnless(buf.value == u"ABCD") ! buf.value = u"x" ! self.failUnless(buf.value == u"x") ! buf[1] = u"Z" ! self.failUnless(buf.value == u"xZCD") class StringTestCase(unittest.TestCase): *************** *** 131,174 **** ## check_perf() ! class WStringTestCase(unittest.TestCase): ! def test_wchar(self): ! c_wchar(u"x") ! repr(byref(c_wchar(u"x"))) ! c_wchar("x") ! - def X_test_basic_wstrings(self): - cs = c_wstring(u"abcdef") ! # XXX This behaviour is about to change: ! # len returns the size of the internal buffer in bytes. ! # This includes the terminating NUL character. ! self.failUnless(sizeof(cs) == 14) ! # The value property is the string up to the first terminating NUL. ! self.failUnless(cs.value == u"abcdef") ! self.failUnless(c_wstring(u"abc\000def").value == u"abc") ! self.failUnless(c_wstring(u"abc\000def").value == u"abc") ! # The raw property is the total buffer contents: ! self.failUnless(cs.raw == u"abcdef\000") ! self.failUnless(c_wstring(u"abc\000def").raw == u"abc\000def\000") ! # We can change the value: ! cs.value = u"ab" ! self.failUnless(cs.value == u"ab") ! self.failUnless(cs.raw == u"ab\000\000\000\000\000") ! self.assertRaises(TypeError, c_wstring, "123") ! self.assertRaises(ValueError, c_wstring, 0) ! def X_test_toolong(self): ! cs = c_wstring(u"abcdef") ! # Much too long string: ! self.assertRaises(ValueError, setattr, cs, "value", u"123456789012345") ! # One char too long values: ! self.assertRaises(ValueError, setattr, cs, "value", u"1234567") --- 136,184 ---- ## check_perf() ! try: ! c_wchar ! except NameError: ! pass ! else: ! class WStringTestCase(unittest.TestCase): ! def test_wchar(self): ! c_wchar(u"x") ! repr(byref(c_wchar(u"x"))) ! c_wchar("x") ! def X_test_basic_wstrings(self): ! cs = c_wstring(u"abcdef") ! # XXX This behaviour is about to change: ! # len returns the size of the internal buffer in bytes. ! # This includes the terminating NUL character. ! self.failUnless(sizeof(cs) == 14) ! # The value property is the string up to the first terminating NUL. ! self.failUnless(cs.value == u"abcdef") ! self.failUnless(c_wstring(u"abc\000def").value == u"abc") ! self.failUnless(c_wstring(u"abc\000def").value == u"abc") ! # The raw property is the total buffer contents: ! self.failUnless(cs.raw == u"abcdef\000") ! self.failUnless(c_wstring(u"abc\000def").raw == u"abc\000def\000") ! # We can change the value: ! cs.value = u"ab" ! self.failUnless(cs.value == u"ab") ! self.failUnless(cs.raw == u"ab\000\000\000\000\000") ! self.assertRaises(TypeError, c_wstring, "123") ! self.assertRaises(ValueError, c_wstring, 0) ! def X_test_toolong(self): ! cs = c_wstring(u"abcdef") ! # Much too long string: ! self.assertRaises(ValueError, setattr, cs, "value", u"123456789012345") ! ! # One char too long values: ! self.assertRaises(ValueError, setattr, cs, "value", u"1234567") *************** *** 200,221 **** # c_string('abc'): 3.67 us - def get_suite(): - try: - from ctypes import c_wchar - except ImportError: - return unittest.TestSuite((unittest.makeSuite(StringTestCase), - unittest.makeSuite(StringArrayTestCase))) - return unittest.TestSuite((unittest.makeSuite(StringTestCase), - unittest.makeSuite(WStringTestCase), - unittest.makeSuite(StringArrayTestCase) - ## unittest.makeSuite(WStringArrayTestCase) - )) - - def test(verbose=0): - runner = unittest.TextTestRunner(verbosity=verbose) - runner.run(get_suite()) if __name__ == '__main__': ## check_perf() ! ## unittest.main() ! test() --- 210,215 ---- # c_string('abc'): 3.67 us if __name__ == '__main__': ## check_perf() ! unittest.main() |
From: Thomas H. <th...@us...> - 2004-05-04 09:15:37
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4812 Modified Files: test_structures.py test_stringptr.py test_returnfuncptrs.py test_refcounts.py test_pointers.py test_parameters.py test_numbers.py test_internals.py test_integers.py test_incomplete.py test_functions.py test_funcptr.py test_callbacks.py test_arrays.py Log Message: Test cases are now found automatically. This removes a lot of boilerplate code from the test modules. Index: test_integers.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_integers.py,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** test_integers.py 24 Jan 2003 19:10:04 -0000 1.4 --- test_integers.py 4 May 2004 09:15:19 -0000 1.5 *************** *** 2,12 **** import unittest - def get_suite(): - return None - - def test(verbose=0): - runner = unittest.TextTestRunner(verbosity=verbose) - runner.run(get_suite()) - if __name__ == '__main__': unittest.main() --- 2,5 ---- Index: test_functions.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_functions.py,v retrieving revision 1.34 retrieving revision 1.35 diff -C2 -d -r1.34 -r1.35 *** test_functions.py 23 Jan 2004 11:40:52 -0000 1.34 --- test_functions.py 4 May 2004 09:15:19 -0000 1.35 *************** *** 332,342 **** self.failUnlessEqual(got, expected) - def get_suite(): - return unittest.makeSuite(FunctionTestCase) - - def test(verbose=0): - runner = unittest.TextTestRunner(verbosity=verbose) - runner.run(get_suite()) - if __name__ == '__main__': unittest.main() --- 332,335 ---- Index: test_internals.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_internals.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** test_internals.py 8 Jul 2003 14:40:38 -0000 1.1 --- test_internals.py 4 May 2004 09:15:19 -0000 1.2 *************** *** 102,112 **** ##XXX print x.data._objects - def get_suite(): - return unittest.makeSuite(ObjectsTestCase) - - def test(verbose=0): - runner = unittest.TextTestRunner(verbosity=verbose) - runner.run(get_suite()) - if __name__ == '__main__': test() --- 102,105 ---- Index: test_callbacks.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_callbacks.py,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** test_callbacks.py 20 Apr 2004 20:16:28 -0000 1.8 --- test_callbacks.py 4 May 2004 09:15:19 -0000 1.9 *************** *** 23,35 **** self.failUnless(diff < 0.01, "%s not less than 0.01" % diff) - - - - def get_suite(): - return unittest.makeSuite(CallbacksTestCase) - - def test(verbose=0): - runner = unittest.TextTestRunner(verbosity=verbose) - runner.run(get_suite()) if __name__ == '__main__': --- 23,26 ---- Index: test_stringptr.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_stringptr.py,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** test_stringptr.py 20 Apr 2004 20:16:28 -0000 1.4 --- test_stringptr.py 4 May 2004 09:15:19 -0000 1.5 *************** *** 72,82 **** x1 = r[0], r[1], r[2], r[3], r[4] - def get_suite(): - return unittest.makeSuite(StringPtrTestCase) - - def test(verbose=0): - runner = unittest.TextTestRunner(verbosity=verbose) - runner.run(get_suite()) - if __name__ == '__main__': test() --- 72,75 ---- Index: test_parameters.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_parameters.py,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** test_parameters.py 30 Apr 2004 14:49:38 -0000 1.22 --- test_parameters.py 4 May 2004 09:15:19 -0000 1.23 *************** *** 131,141 **** # c_int.from_param(c_int(42)): 0.50 us - def get_suite(): - return unittest.makeSuite(SimpleTypesTestCase) - - def test(verbose=0): - runner = unittest.TextTestRunner(verbosity=verbose) - runner.run(get_suite()) - if __name__ == '__main__': import sys --- 131,134 ---- Index: test_returnfuncptrs.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_returnfuncptrs.py,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** test_returnfuncptrs.py 20 Jan 2004 19:52:19 -0000 1.3 --- test_returnfuncptrs.py 4 May 2004 09:15:19 -0000 1.4 *************** *** 29,39 **** self.assertRaises(TypeError, strchr, "abcdef") - def get_suite(): - return unittest.makeSuite(ReturnFuncPtrTestCase) - - def test(verbose=0): - runner = unittest.TextTestRunner(verbosity=verbose) - runner.run(get_suite()) - if __name__ == "__main__": unittest.main() --- 29,32 ---- Index: test_refcounts.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_refcounts.py,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** test_refcounts.py 20 Jan 2004 19:52:19 -0000 1.12 --- test_refcounts.py 4 May 2004 09:15:19 -0000 1.13 *************** *** 84,94 **** - def get_suite(): - return unittest.makeSuite(RefcountTestCase) - - def test(verbose=0): - runner = unittest.TextTestRunner(verbosity=verbose) - runner.run(get_suite()) - if __name__ == '__main__': unittest.main() --- 84,87 ---- Index: test_funcptr.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_funcptr.py,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** test_funcptr.py 20 Jan 2004 21:01:33 -0000 1.12 --- test_funcptr.py 4 May 2004 09:15:19 -0000 1.13 *************** *** 128,138 **** self.failUnlessEqual(strtok(None, "\n"), None) - def get_suite(): - return unittest.makeSuite(CFuncPtrTestCase) - - def test(verbose=0): - runner = unittest.TextTestRunner(verbosity=verbose) - runner.run(get_suite()) - if __name__ == '__main__': unittest.main() --- 128,131 ---- Index: test_pointers.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_pointers.py,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** test_pointers.py 20 Jan 2004 19:52:19 -0000 1.13 --- test_pointers.py 4 May 2004 09:15:19 -0000 1.14 *************** *** 138,148 **** self.failUnlessEqual(result, [42] * 8) - def get_suite(): - return unittest.makeSuite(PointersTestCase) - - def test(verbose=0): - runner = unittest.TextTestRunner(verbosity=verbose) - runner.run(get_suite()) - if __name__ == '__main__': unittest.main() --- 138,141 ---- Index: test_incomplete.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_incomplete.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** test_incomplete.py 8 Jul 2003 14:40:38 -0000 1.2 --- test_incomplete.py 4 May 2004 09:15:19 -0000 1.3 *************** *** 35,45 **** ################################################################ - def get_suite(): - return unittest.makeSuite(MyTestCase) - - def test(verbose=0): - runner = unittest.TextTestRunner(verbosity=verbose) - runner.run(get_suite()) - if __name__ == '__main__': ! test() --- 35,38 ---- ################################################################ if __name__ == '__main__': ! unittest.main() Index: test_arrays.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_arrays.py,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** test_arrays.py 23 Jan 2004 11:41:06 -0000 1.6 --- test_arrays.py 4 May 2004 09:15:19 -0000 1.7 *************** *** 92,102 **** self.failUnless(ARRAY(c_int, 3) is ARRAY(c_int, 3)) - def get_suite(): - return unittest.makeSuite(ArrayTestCase) - - def test(verbose=0): - runner = unittest.TextTestRunner(verbosity=verbose) - runner.run(get_suite()) - if __name__ == '__main__': unittest.main() --- 92,95 ---- Index: test_numbers.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_numbers.py,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** test_numbers.py 20 Apr 2004 20:16:28 -0000 1.16 --- test_numbers.py 4 May 2004 09:15:19 -0000 1.17 *************** *** 235,245 **** # c_int_S(999): 9.85 us - def get_suite(): - return unittest.makeSuite(NumberTestCase) - - def test(verbose=0): - runner = unittest.TextTestRunner(verbosity=verbose) - runner.run(get_suite()) - if __name__ == '__main__': check_perf() --- 235,238 ---- Index: test_structures.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_structures.py,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** test_structures.py 25 Apr 2003 18:28:40 -0000 1.11 --- test_structures.py 4 May 2004 09:15:18 -0000 1.12 *************** *** 227,237 **** - def get_suite(): - return unittest.makeSuite(StructureTestCase) - - def test(verbose=0): - runner = unittest.TextTestRunner(verbosity=verbose) - runner.run(get_suite()) - if __name__ == '__main__': unittest.main() --- 227,230 ---- |
From: Thomas H. <th...@us...> - 2004-05-04 09:15:19
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4775 Modified Files: setup.py Log Message: Test cases are now found automatically. This removes a lot of boilerplate code from the test modules. Index: setup.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/setup.py,v retrieving revision 1.40 retrieving revision 1.41 diff -C2 -d -r1.40 -r1.41 *** setup.py 30 Apr 2004 14:35:07 -0000 1.40 --- setup.py 4 May 2004 09:15:09 -0000 1.41 *************** *** 136,160 **** self.announce("testing") - # build include path for test test_suites = [] - for case in self.test_suffixes: ! TEST = __import__(self.test_prefix+case, ! globals(), locals(), ! ['']) ! ! # Test modules must either expose a test() function which ! # will be called to run the test, or a get_suite() function ! # which returns a TestSuite. ! try: ! suite = TEST.get_suite() ! except AttributeError: ! self.announce("\t%s" % (self.test_prefix+case)) ! TEST.test(verbose=self.verbose) ! else: ! if suite: ! test_suites.append(suite) ! if test_suites: --- 136,151 ---- self.announce("testing") + # Import all test modules, collect unittest.TestCase classes, + # and build a TestSuite from them. test_suites = [] for case in self.test_suffixes: ! mod = __import__(os.path.splitext(self.test_prefix + case)[0]) ! for name in dir(mod): ! if name.startswith("_"): ! continue ! o = getattr(mod, name) ! if type(o) is type(unittest.TestCase) and issubclass(o, unittest.TestCase): ! test_suites.append(unittest.makeSuite(o)) if test_suites: |
From: Thomas H. <th...@us...> - 2004-05-03 15:17:57
|
Update of /cvsroot/ctypes/ctypes/win32/com In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17757 Modified Files: client.py Log Message: win32\com\client.py: Add a COMError class, compatible to that used in pywin32. If _DispMethod.__call__ fails, a COMError is now raised, with more detailed information. Index: client.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/win32/com/client.py,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** client.py 23 Apr 2004 19:27:16 -0000 1.3 --- client.py 3 May 2004 15:17:19 -0000 1.4 *************** *** 151,154 **** --- 151,164 ---- ################################################################ + class COMError(WindowsError): + def __init__(self, *args): + WindowsError.__init__(self, *args) + self.args = args + + def __str__(self): + return str(self.args) + + ################################################################ + class _Constants(object): def __init__(self, ti): *************** *** 361,372 **** parms = self._build_parms(*args, **kw) result = VARIANT() ! self._comobj.Invoke(self.fd.memid, ! byref(guid_null), ! 0, # LCID ! self.fd.invkind, ! byref(parms), ! byref(result), # pVarResult ! None, # pExcepInfo ! None) # puArgError return _wrap(result) --- 371,388 ---- parms = self._build_parms(*args, **kw) result = VARIANT() ! excepinfo = EXCEPINFO() ! uArgError = c_uint() ! try: ! self._comobj.Invoke(self.fd.memid, ! byref(guid_null), ! 0, # LCID ! self.fd.invkind, ! byref(parms), ! byref(result), # pVarResult ! byref(excepinfo), # pExcepInfo ! byref(uArgError)) # puArgError ! except WindowsError, (errno, strerror): ! assert excepinfo.pfnDeferredFillIn == 0 ! raise COMError(errno, strerror, excepinfo.as_tuple(), uArgError.value) return _wrap(result) |
From: Thomas H. <th...@us...> - 2004-05-03 15:17:22
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17736 Modified Files: ChangeLog Log Message: win32\com\client.py: Add a COMError class, compatible to that used in pywin32. If _DispMethod.__call__ fails, a COMError is now raised, with more detailed information. Index: ChangeLog =================================================================== RCS file: /cvsroot/ctypes/ctypes/ChangeLog,v retrieving revision 1.38 retrieving revision 1.39 diff -C2 -d -r1.38 -r1.39 *** ChangeLog 20 Apr 2004 20:12:49 -0000 1.38 --- ChangeLog 3 May 2004 15:17:11 -0000 1.39 *************** *** 1,2 **** --- 1,11 ---- + 2004-05-03 Thomas Heller <th...@py...> + + * win32\com\client.py: Add a COMError class, compatible to that + used in pywin32. If _DispMethod.__call__ fails, a COMError is now + raised, with more detailed information. + + * ctypes\__init__.py: The WinError function does now accept an + optional second parameter, this is the textual error description. + 2004-04-20 Thomas Heller <th...@py...> |
From: Thomas H. <th...@us...> - 2004-05-03 15:06:14
|
Update of /cvsroot/ctypes/ctypes/win32/com In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15009 Modified Files: automation.py Log Message: Add an as_tuple() method to the EXCEPINFO structure. Index: automation.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/win32/com/automation.py,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** automation.py 23 Apr 2004 18:31:43 -0000 1.15 --- automation.py 3 May 2004 15:05:50 -0000 1.16 *************** *** 466,469 **** --- 466,472 ---- ("pfnDeferredFillIn", c_int), # XXX ("scode", SCODE)] + def as_tuple(self): + return (self.wCode, self.bstrSource, self.bstrDescription, + self.bstrHelpFile, self.dwHelpContext, self.scode) assert(sizeof(EXCEPINFO) == 32) |
From: Thomas H. <th...@us...> - 2004-05-03 15:01:09
|
Update of /cvsroot/ctypes/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13652 Modified Files: __init__.py Log Message: The WinError function does now accept a second parameter, normally this should be the textual error description. Index: __init__.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/__init__.py,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** __init__.py 20 Apr 2004 20:14:11 -0000 1.24 --- __init__.py 3 May 2004 15:01:00 -0000 1.25 *************** *** 323,328 **** GetLastError = windll.kernel32.GetLastError ! def WinError(code=None): if code is None: code = GetLastError() ! return WindowsError(code, FormatError(code).strip()) --- 323,330 ---- GetLastError = windll.kernel32.GetLastError ! def WinError(code=None, descr=None): if code is None: code = GetLastError() ! if descr is None: ! descr = FormatError(code).strip() ! return WindowsError(code, descr) |
From: Thomas H. <th...@us...> - 2004-04-30 19:24:36
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19007 Modified Files: Tag: libffi_msvc_branch ctypes.h Log Message: Remove unneeded forward declaration. Index: ctypes.h =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/ctypes.h,v retrieving revision 1.38 retrieving revision 1.38.2.1 diff -C2 -d -r1.38 -r1.38.2.1 *** ctypes.h 20 Apr 2004 16:26:20 -0000 1.38 --- ctypes.h 30 Apr 2004 19:24:28 -0000 1.38.2.1 *************** *** 240,246 **** int index, int size, char *ptr); - #ifdef MS_WIN32 - extern void SetException(unsigned long code); - #endif extern void Extend_Error_Info(char *fmt, ...); --- 240,243 ---- |
From: Thomas H. <th...@us...> - 2004-04-30 19:10:51
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16465 Modified Files: Tag: libffi_msvc_branch cfield.c Log Message: Remove an MSVC specific breakpoint. Index: cfield.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/cfield.c,v retrieving revision 1.28.2.1 retrieving revision 1.28.2.2 diff -C2 -d -r1.28.2.1 -r1.28.2.2 *** cfield.c 29 Apr 2004 20:56:13 -0000 1.28.2.1 --- cfield.c 30 Apr 2004 19:10:42 -0000 1.28.2.2 *************** *** 37,43 **** GETFUNC getfunc = NULL; StgDictObject *dict; ! #ifdef _DEBUG ! _asm int 3; ! #endif self = (CFieldObject *)PyObject_CallObject((PyObject *)&CField_Type, NULL); --- 37,41 ---- GETFUNC getfunc = NULL; StgDictObject *dict; ! self = (CFieldObject *)PyObject_CallObject((PyObject *)&CField_Type, NULL); |
From: Thomas H. <th...@us...> - 2004-04-30 18:29:07
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7895 Modified Files: Tag: libffi_msvc_branch test_stringptr.py test_parameters.py Log Message: Merge changes made to the trunk: * source\_ctypes.c: Added c_char_p_from_param and c_void_p_from_param class methods to the _SimpleCData type. These are later used as from_param class methods for the c_void_p, c_char_p, and POINTER(c_char) types. Added unittests for them. Index: test_parameters.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_parameters.py,v retrieving revision 1.20 retrieving revision 1.20.6.1 diff -C2 -d -r1.20 -r1.20.6.1 *** test_parameters.py 16 May 2003 16:41:54 -0000 1.20 --- test_parameters.py 30 Apr 2004 18:28:59 -0000 1.20.6.1 *************** *** 20,24 **** self.failUnless(c_char_p.from_param(a) is a) ! self.failUnless(c_char_p.from_param(None)._obj is None) # Hm, how to check the c_char_p(xxx)._as_parameter_ attribute? --- 20,24 ---- self.failUnless(c_char_p.from_param(a) is a) ! self.failUnless(c_char_p.from_param(None) is None) # Hm, how to check the c_char_p(xxx)._as_parameter_ attribute? *************** *** 41,45 **** pa = c_wchar_p.from_param(c_wchar_p(u"123")) self.failUnless(type(pa) == c_wchar_p) ! self.failUnless(c_wchar_p.from_param(None)._obj is None) --- 41,45 ---- pa = c_wchar_p.from_param(c_wchar_p(u"123")) self.failUnless(type(pa) == c_wchar_p) ! self.failUnless(c_wchar_p.from_param(None) is None) Index: test_stringptr.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_stringptr.py,v retrieving revision 1.3.6.1 retrieving revision 1.3.6.2 diff -C2 -d -r1.3.6.1 -r1.3.6.2 *** test_stringptr.py 29 Apr 2004 20:56:13 -0000 1.3.6.1 --- test_stringptr.py 30 Apr 2004 18:28:59 -0000 1.3.6.2 *************** *** 58,65 **** # c_char_p and Python string is compatible ! # c_char_p and c_buffer is NOT compatible strchr.argtypes = c_char_p, c_char self.failUnlessEqual(strchr("abcdef", "c"), "cdef") ! self.failUnlessRaises(TypeError, strchr, c_buffer("abcdef"), "c") # POINTER(c_char) and Python string is NOT compatible --- 58,65 ---- # c_char_p and Python string is compatible ! # c_char_p and c_buffer are now compatible strchr.argtypes = c_char_p, c_char self.failUnlessEqual(strchr("abcdef", "c"), "cdef") ! self.failUnlessEqual(strchr(c_buffer("abcdef"), "c"), "cdef") # POINTER(c_char) and Python string is NOT compatible *************** *** 68,72 **** buf = c_buffer("abcdef") self.failUnlessEqual(strchr(buf, "c"), "cdef") ! self.failUnlessRaises(TypeError, strchr, "abcdef", "c") # XXX These calls are dangerous, because the first argument --- 68,72 ---- buf = c_buffer("abcdef") self.failUnlessEqual(strchr(buf, "c"), "cdef") ! self.failUnlessEqual(strchr("abcdef", "c"), "cdef") # XXX These calls are dangerous, because the first argument |
From: Thomas H. <th...@us...> - 2004-04-30 18:29:00
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7859 Modified Files: Tag: libffi_msvc_branch _ctypes.c Log Message: Merge changes made to the trunk: * source\_ctypes.c: Added c_char_p_from_param and c_void_p_from_param class methods to the _SimpleCData type. These are later used as from_param class methods for the c_void_p, c_char_p, and POINTER(c_char) types. Added unittests for them. Index: _ctypes.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes.c,v retrieving revision 1.136 retrieving revision 1.136.2.1 diff -C2 -d -r1.136 -r1.136.2.1 *** _ctypes.c 20 Apr 2004 16:26:20 -0000 1.136 --- _ctypes.c 30 Apr 2004 18:28:51 -0000 1.136.2.1 *************** *** 604,609 **** char *ptr; int size; ! if (-1 == PyString_AsStringAndSize(value, &ptr, &size)) return -1; if (size > self->b_size) { PyErr_SetString(PyExc_ValueError, --- 604,614 ---- char *ptr; int size; ! if (PyBuffer_Check(value)) { ! size = value->ob_type->tp_as_buffer->bf_getreadbuffer(value, 0, &ptr); ! if (size < 0) ! return -1; ! } else if (-1 == PyString_AsStringAndSize(value, &ptr, &size)) { return -1; + } if (size > self->b_size) { PyErr_SetString(PyExc_ValueError, *************** *** 920,923 **** --- 925,1126 ---- static PyObject * + c_wchar_p_from_param(PyObject *type, PyObject *value) + { + #if (PYTHON_API_VERSION < 1012) + if (!PyArg_ParseTuple(value, "OO", &type, &value)) + return NULL; + #endif + if (value == Py_None) { + Py_INCREF(Py_None); + return Py_None; + } + if (PyUnicode_Check(value)) { + PyCArgObject *parg; + struct fielddesc *fd = getentry("Z"); + + parg = new_CArgObject(); + parg->tag = 'Z'; + parg->obj = fd->setfunc(&parg->value, value, 0); + if (parg->obj == NULL) { + Py_DECREF(parg); + return NULL; + } + return (PyObject *)parg; + } + if (PyObject_IsInstance(value, type)) { + Py_INCREF(value); + return value; + } + if (ArrayObject_Check(value) || PointerObject_Check(value)) { + /* c_wchar array instance or pointer(c_wchar(...)) */ + StgDictObject *dt = PyObject_stgdict(value); + StgDictObject *dict = dt && dt->proto ? PyType_stgdict(dt->proto) : NULL; + if (dict && (dict->setfunc == getentry("u")->setfunc)) { + Py_INCREF(value); + return value; + } + } + if (PyCArg_CheckExact(value)) { + /* byref(c_char(...)) */ + PyCArgObject *a = (PyCArgObject *)value; + StgDictObject *dict = PyObject_stgdict(a->obj); + if (dict && (dict->setfunc == getentry("u")->setfunc)) { + Py_INCREF(value); + return value; + } + } + /* XXX better message */ + PyErr_SetString(PyExc_TypeError, + "wrong type"); + return NULL; + } + + static PyObject * + c_char_p_from_param(PyObject *type, PyObject *value) + { + #if (PYTHON_API_VERSION < 1012) + if (!PyArg_ParseTuple(value, "OO", &type, &value)) + return NULL; + #endif + if (value == Py_None) { + Py_INCREF(Py_None); + return Py_None; + } + if (PyString_Check(value)) { + PyCArgObject *parg; + struct fielddesc *fd = getentry("z"); + + parg = new_CArgObject(); + parg->tag = 'z'; + parg->obj = fd->setfunc(&parg->value, value, 0); + if (parg->obj == NULL) { + Py_DECREF(parg); + return NULL; + } + return (PyObject *)parg; + } + if (PyObject_IsInstance(value, type)) { + Py_INCREF(value); + return value; + } + if (ArrayObject_Check(value) || PointerObject_Check(value)) { + /* c_char array instance or pointer(c_char(...)) */ + StgDictObject *dt = PyObject_stgdict(value); + StgDictObject *dict = dt && dt->proto ? PyType_stgdict(dt->proto) : NULL; + if (dict && (dict->setfunc == getentry("c")->setfunc)) { + Py_INCREF(value); + return value; + } + } + if (PyCArg_CheckExact(value)) { + /* byref(c_char(...)) */ + PyCArgObject *a = (PyCArgObject *)value; + StgDictObject *dict = PyObject_stgdict(a->obj); + if (dict && (dict->setfunc == getentry("c")->setfunc)) { + Py_INCREF(value); + return value; + } + } + /* XXX better message */ + PyErr_SetString(PyExc_TypeError, + "wrong type"); + return NULL; + } + + static PyObject * + c_void_p_from_param(PyObject *type, PyObject *value) + { + StgDictObject *stgd; + #if (PYTHON_API_VERSION < 1012) + if (!PyArg_ParseTuple(value, "OO", &type, &value)) + return NULL; + #endif + + if (value == Py_None) { + Py_INCREF(Py_None); + return Py_None; + } + if (PyString_Check(value)) { + PyCArgObject *parg; + struct fielddesc *fd = getentry("z"); + + parg = new_CArgObject(); + parg->tag = 'z'; + parg->obj = fd->setfunc(&parg->value, value, 0); + if (parg->obj == NULL) { + Py_DECREF(parg); + return NULL; + } + return (PyObject *)parg; + } + if (PyUnicode_Check(value)) { + PyCArgObject *parg; + struct fielddesc *fd = getentry("Z"); + + parg = new_CArgObject(); + parg->tag = 'Z'; + parg->obj = fd->setfunc(&parg->value, value, 0); + if (parg->obj == NULL) { + Py_DECREF(parg); + return NULL; + } + return (PyObject *)parg; + } + if (PyObject_IsInstance(value, type)) { + /* c_void_p instances */ + Py_INCREF(value); + return value; + } + if (ArrayObject_Check(value) || PointerObject_Check(value)) { + /* Any array or pointer is accepted */ + Py_INCREF(value); + return value; + } + if (PyCArg_CheckExact(value)) { + /* byref(c_xxx()) */ + PyCArgObject *a = (PyCArgObject *)value; + if (a->tag == 'P') { + Py_INCREF(value); + return value; + } + } + stgd = PyObject_stgdict(value); + if (stgd && CDataObject_Check(value) && stgd->proto && PyString_Check(stgd->proto)) { + PyCArgObject *parg; + + switch (PyString_AS_STRING(stgd->proto)[0]) { + case 'z': /* c_char_p */ + case 'Z': /* c_wchar_p */ + parg = new_CArgObject(); + if (parg == NULL) + return NULL; + parg->tag = 'Z'; + Py_INCREF(value); + parg->obj = value; + /* Remember: b_ptr points to where the pointer is stored! */ + parg->value.p = *(void **)(((CDataObject *)value)->b_ptr); + return (PyObject *)parg; + } + } + /* XXX better message */ + PyErr_SetString(PyExc_TypeError, + "wrong type"); + return NULL; + } + #if (PYTHON_API_VERSION >= 1012) + + static PyMethodDef c_void_p_method = { "from_param", c_void_p_from_param, METH_O }; + static PyMethodDef c_char_p_method = { "from_param", c_char_p_from_param, METH_O }; + static PyMethodDef c_wchar_p_method = { "from_param", c_wchar_p_from_param, METH_O }; + + #else + + static PyMethodDef c_void_p_method = { "from_param", c_void_p_from_param, METH_VARARGS }; + static PyMethodDef c_char_p_method = { "from_param", c_char_p_from_param, METH_VARARGS }; + static PyMethodDef c_wchar_p_method = { "from_param", c_wchar_p_from_param, METH_VARARGS }; + + #endif + + static PyObject * SimpleType_new(PyTypeObject *type, PyObject *args, PyObject *kwds) { *************** *** 925,928 **** --- 1128,1132 ---- StgDictObject *stgdict; PyObject *proto; + PyMethodDef *ml; struct fielddesc *fmt; *************** *** 972,975 **** --- 1176,1225 ---- Py_DECREF(result->tp_dict); result->tp_dict = (PyObject *)stgdict; + + switch (PyString_AS_STRING(proto)[0]) { + case 'z': /* c_char_p */ + ml = &c_char_p_method; + break; + case 'Z': /* c_wchar_p */ + ml = &c_wchar_p_method; + break; + case 'P': /* c_void_p */ + ml = &c_void_p_method; + break; + default: + ml = NULL; + break; + } + + if (ml) { + #if (PYTHON_API_VERSION >= 1012) + PyObject *meth; + int x; + meth = PyDescr_NewClassMethod(result, ml); + if (!meth) + return NULL; + #else + PyObject *meth, *func; + int x; + func = PyCFunction_New(ml, NULL); + if (!func) + return NULL; + meth = PyObject_CallFunctionObjArgs( + (PyObject *)&PyClassMethod_Type, + func, NULL); + Py_DECREF(func); + if (!meth) { + return NULL; + } + #endif + x = PyDict_SetItemString(result->tp_dict, + ml->ml_name, + meth); + Py_DECREF(meth); + if (x == -1) { + Py_DECREF(result); + return NULL; + } + } return (PyObject *)result; } |
From: Thomas H. <th...@us...> - 2004-04-30 18:28:51
|
Update of /cvsroot/ctypes/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7836 Modified Files: Tag: libffi_msvc_branch __init__.py Log Message: Merge changes made to the trunk: * source\_ctypes.c: Added c_char_p_from_param and c_void_p_from_param class methods to the _SimpleCData type. These are later used as from_param class methods for the c_void_p, c_char_p, and POINTER(c_char) types. Added unittests for them. Index: __init__.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/__init__.py,v retrieving revision 1.23 retrieving revision 1.23.4.1 diff -C2 -d -r1.23 -r1.23.4.1 *** __init__.py 15 Jan 2004 20:09:39 -0000 1.23 --- __init__.py 30 Apr 2004 18:28:42 -0000 1.23.4.1 *************** *** 191,194 **** --- 191,199 ---- return klass + POINTER(c_char).from_param = c_char_p.from_param #_SimpleCData.c_char_p_from_param + + if _os.name == "nt": + POINTER(c_wchar).from_param = c_wchar_p.from_param #_SimpleCData.c_wchar_p_from_param + def SetPointerType(pointer, cls): if _pointer_type_cache.get(cls, None) is not None: |
From: Thomas H. <th...@us...> - 2004-04-30 14:49:56
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28287 Modified Files: test_parameters.py Log Message: Use failUnlessEqual because of the better error message, whereever possible. Index: test_parameters.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_parameters.py,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** test_parameters.py 20 Apr 2004 20:16:28 -0000 1.21 --- test_parameters.py 30 Apr 2004 14:49:38 -0000 1.22 *************** *** 34,38 **** pa = c_wchar_p.from_param(c_wchar_p(u"123")) ! self.failUnless(type(pa) == c_wchar_p) def test_int_pointers(self): --- 34,38 ---- pa = c_wchar_p.from_param(c_wchar_p(u"123")) ! self.failUnlessEqual(type(pa), c_wchar_p) def test_int_pointers(self): *************** *** 43,50 **** ## x = LPINT.from_param(p) x = LPINT.from_param(pointer(c_int(42))) ! self.failUnless(x.contents.value == 42) ! self.failUnless(LPINT(c_int(42)).contents.value == 42) ! self.failUnless(LPINT.from_param(None) == 0) self.assertRaises(TypeError, LPINT.from_param, pointer(c_long(42))) --- 43,50 ---- ## x = LPINT.from_param(p) x = LPINT.from_param(pointer(c_int(42))) ! self.failUnlessEqual(x.contents.value, 42) ! self.failUnlessEqual(LPINT(c_int(42)).contents.value, 42) ! self.failUnlessEqual(LPINT.from_param(None), 0) self.assertRaises(TypeError, LPINT.from_param, pointer(c_long(42))) *************** *** 79,84 **** INTARRAY = c_int * 3 ia = INTARRAY() ! self.failUnless(len(ia) == 3) ! self.failUnless([ia[i] for i in range(3)] == [0, 0, 0]) # Pointers are only compatible with arrays containing items of --- 79,84 ---- INTARRAY = c_int * 3 ia = INTARRAY() ! self.failUnlessEqual(len(ia), 3) ! self.failUnlessEqual([ia[i] for i in range(3)], [0, 0, 0]) # Pointers are only compatible with arrays containing items of |