ctypes-commit Mailing List for ctypes (Page 100)
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-07-22 17:59:52
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28084 Modified Files: test_structures.py Log Message: Another test case. Index: test_structures.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_structures.py,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** test_structures.py 22 Jul 2004 10:09:35 -0000 1.15 --- test_structures.py 22 Jul 2004 17:59:39 -0000 1.16 *************** *** 2,6 **** from ctypes import * from struct import calcsize - from _ctypes import alignment class StructureTestCase(unittest.TestCase): --- 2,5 ---- *************** *** 37,40 **** --- 36,40 ---- def test_struct_alignment(self): + from _ctypes import alignment class X(Structure): _fields_ = [("x", c_char * 3)] *************** *** 68,71 **** --- 68,72 ---- def test_emtpy(self): + from _ctypes import alignment # I had problems with these # *************** *** 229,232 **** --- 230,252 ---- + class PointerMemberTestCase(unittest.TestCase): + + def test(self): + # a Structure with a POINTER field + class S(Structure): + _fields_ = [("array", POINTER(c_int))] + + s = S() + # We can assign arrays of the correct type + s.array = (c_int * 3)(1, 2, 3) + items = [s.array[i] for i in range(3)] + self.failUnlessEqual(items, [1, 2, 3]) + + # The following are bugs: + # This fails with SystemError: bad arg to internal function + # s.array[0] = 42 + # and this one with IndexError: invalid index + # s.array[1] = 42 + if __name__ == '__main__': unittest.main() |
From: Thomas H. <th...@us...> - 2004-07-22 17:28:05
|
Update of /cvsroot/ctypes/ctypes/docs In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22713 Modified Files: tutorial.stx Log Message: Add c_float and c_double to the simple data types table. Untabbify the file. Index: tutorial.stx =================================================================== RCS file: /cvsroot/ctypes/ctypes/docs/tutorial.stx,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** tutorial.stx 15 Jan 2004 19:13:44 -0000 1.22 --- tutorial.stx 22 Jul 2004 17:27:55 -0000 1.23 *************** *** 171,187 **** |---------------------------------------------| |'c_longlong' |'__int64' or |long | ! | |'long long' | | |---------------------------------------------| |'c_ulonglong'|'unsigned __int64' or|long | ! | |'unsigned long long'| | |---------------------------------------------| ! |'c_char_p' |'char *' |string or | ! | |(NUL terminated) |'None' | |---------------------------------------------| |'c_wchar_p' |'wchar_t *' |unicode or | ! | |(NUL terminated) |'None' | |---------------------------------------------| ! |'c_void_p' |'void *' |integer or | ! | | |'None' | |---------------------------------------------| --- 171,191 ---- |---------------------------------------------| |'c_longlong' |'__int64' or |long | ! | |'long long' | | |---------------------------------------------| |'c_ulonglong'|'unsigned __int64' or|long | ! | |'unsigned long long'| | |---------------------------------------------| ! |'c_float' |'float' |float | ! |---------------------------------------------| ! |'c_double' |'double' |float | ! |---------------------------------------------| ! |'c_char_p' |'char *' |string or | ! | |(NUL terminated) |'None' | |---------------------------------------------| |'c_wchar_p' |'wchar_t *' |unicode or | ! | |(NUL terminated) |'None' | |---------------------------------------------| ! |'c_void_p' |'void *' |integer or | ! | | |'None' | |---------------------------------------------| *************** *** 414,418 **** Traceback (most recent call last): File "<stdin>", line 1, in ? ! File "<stdin>", line 3, in ValidHandle WindowsError: [Errno 126] The specified module could not be found. >>> --- 418,422 ---- Traceback (most recent call last): File "<stdin>", line 1, in ? ! File "<stdin>", line 3, in ValidHandle WindowsError: [Errno 126] The specified module could not be found. >>> *************** *** 553,557 **** >>> class MyStruct(Structure): ... _fields_ = [("a", c_int), ! ... ("b", float), ... ("point_array", POINT * 4)] >>> --- 557,561 ---- >>> class MyStruct(Structure): ... _fields_ = [("a", c_int), ! ... ("b", float), ... ("point_array", POINT * 4)] >>> *************** *** 676,680 **** Traceback (most recent call last): File "<stdin>", line 1, in ? ! File "<stdin>", line 2, in cell NameError: name 'cell' is not defined >>> --- 680,684 ---- Traceback (most recent call last): File "<stdin>", line 1, in ? ! File "<stdin>", line 2, in cell NameError: name 'cell' is not defined >>> |
From: Thomas H. <th...@us...> - 2004-07-22 15:22:28
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29652 Modified Files: setup.py Log Message: Use the correct MANIFEST template. Index: setup.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/setup.py,v retrieving revision 1.95 retrieving revision 1.96 diff -C2 -d -r1.95 -r1.96 *** setup.py 22 Jul 2004 15:13:56 -0000 1.95 --- setup.py 22 Jul 2004 15:22:19 -0000 1.96 *************** *** 423,427 **** options["sdist"] = {"template": "MANIFEST.windows.in", "force_manifest": 1} else: ! options["sdist"] = {"template": "MANIFEST.windows.in", "force_manifest": 1} if __name__ == '__main__': --- 423,427 ---- options["sdist"] = {"template": "MANIFEST.windows.in", "force_manifest": 1} else: ! options["sdist"] = {"template": "MANIFEST.other.in", "force_manifest": 1} if __name__ == '__main__': |
From: Thomas H. <th...@us...> - 2004-07-22 15:14:04
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28614 Modified Files: setup.py Log Message: options was not defined. Index: setup.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/setup.py,v retrieving revision 1.94 retrieving revision 1.95 diff -C2 -d -r1.94 -r1.95 *** setup.py 22 Jul 2004 14:00:46 -0000 1.94 --- setup.py 22 Jul 2004 15:13:56 -0000 1.95 *************** *** 418,421 **** --- 418,423 ---- # Use different MANIFEST templates, to minimize the distribution size. # Also, the MANIFEST templates behave differently on Windows and Linux (distutils bug?) + options = {} + if sys.platform == 'win32': options["sdist"] = {"template": "MANIFEST.windows.in", "force_manifest": 1} |
From: Thomas H. <th...@us...> - 2004-07-22 14:13:06
|
Update of /cvsroot/ctypes/ctypes/build/lib.win32-2.2 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18804/lib.win32-2.2 Log Message: Directory /cvsroot/ctypes/ctypes/build/lib.win32-2.2 added to the repository |
From: Thomas H. <th...@us...> - 2004-07-22 14:02:31
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16423 Added Files: MANIFEST.windows.in MANIFEST.other.in Log Message: MANIFEST.in no longer needed, platform specific MANIFEST templates will be used. --- NEW FILE: MANIFEST.other.in --- include MANIFEST MANIFES.other.in LICENSE.txt NEWS.txt README* include source/*.c source/*.h include source/darwin/*.c source/darwin/*.h include ctypes/.CTYPES_DEVEL recursive-include source/gcc * include unittests *.py include docs/*.html include docs/*.css include docs/*.stx include samples/rt recursive-include samples *.py prune samples/Windows --- NEW FILE: MANIFEST.windows.in --- include MANIFEST MANIFEST.windows.in LICENSE.txt NEWS.txt README* include ctypes/.CTYPES_DEVEL recursive-include unittests *.py include docs/*.html include docs/*.css include docs/*.stx include samples/rt recursive-include samples *.py |
From: Thomas H. <th...@us...> - 2004-07-22 14:02:06
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16311 Removed Files: MANIFEST.in Log Message: MANIFEST.in no longer needed, platform specific MANIFEST templates will be used. --- MANIFEST.in DELETED --- |
From: Thomas H. <th...@us...> - 2004-07-22 14:00:55
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16068 Modified Files: setup.py Log Message: Add the ctypes.com.samples.server.IExplorer directory (package). Use different MANIFEST.in template files on Windows and other systems. Index: setup.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/setup.py,v retrieving revision 1.93 retrieving revision 1.94 diff -C2 -d -r1.93 -r1.94 *** setup.py 22 Jul 2004 13:46:49 -0000 1.93 --- setup.py 22 Jul 2004 14:00:46 -0000 1.94 *************** *** 130,133 **** --- 130,136 ---- package_dir["ctypes.com.samples.server.control"] = "win32/com/samples/server/control" + packages.append("ctypes.com.samples.server.IExplorer") + package_dir["ctypes.com.samples.server.IExplorer"] = "win32/com/samples/server/IExplorer" + ################################################################ *************** *** 284,288 **** # class test - options = {} if (hasattr(distutils.core, 'setup_keywords') and 'classifiers' in distutils.core.setup_keywords): --- 287,290 ---- *************** *** 414,417 **** --- 416,426 ---- clean.clean.run(self) + # Use different MANIFEST templates, to minimize the distribution size. + # Also, the MANIFEST templates behave differently on Windows and Linux (distutils bug?) + if sys.platform == 'win32': + options["sdist"] = {"template": "MANIFEST.windows.in", "force_manifest": 1} + else: + options["sdist"] = {"template": "MANIFEST.windows.in", "force_manifest": 1} + if __name__ == '__main__': setup(name="ctypes", *************** *** 430,434 **** cmdclass = {'test': test, 'build_py': my_build_py, 'build_ext': my_build_ext, 'clean': my_clean}, ! **options ) --- 439,443 ---- cmdclass = {'test': test, 'build_py': my_build_py, 'build_ext': my_build_ext, 'clean': my_clean}, ! options = options ) |
From: Thomas H. <th...@us...> - 2004-07-22 13:48:12
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14095 Modified Files: _ctypes.c Log Message: Approaching version 0.9.0. The _ctypes extension now has a version number as well, and ctypes/__init__.py checks that the version numbers match. Index: _ctypes.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes.c,v retrieving revision 1.149 retrieving revision 1.150 diff -C2 -d -r1.149 -r1.150 *** _ctypes.c 22 Jul 2004 08:41:30 -0000 1.149 --- _ctypes.c 22 Jul 2004 13:48:03 -0000 1.150 *************** *** 3684,3687 **** --- 3684,3688 ---- #endif PyModule_AddObject(m, "FUNCFLAG_CDECL", PyInt_FromLong(FUNCFLAG_CDECL)); + PyModule_AddStringConstant(m, "__version__", "0.9.0"); /************************************************* |
From: Thomas H. <th...@us...> - 2004-07-22 13:48:03
|
Update of /cvsroot/ctypes/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14036 Modified Files: __init__.py Log Message: Approaching version 0.9.0. The _ctypes extension now has a version number as well, and ctypes/__init__.py checks that the version numbers match. Index: __init__.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/__init__.py,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** __init__.py 3 May 2004 15:01:00 -0000 1.25 --- __init__.py 22 Jul 2004 13:47:53 -0000 1.26 *************** *** 9,17 **** del os, _magicfile ! __version__ = "0.6.3" from _ctypes import Union, Structure, Array from _ctypes import _Pointer from _ctypes import CFuncPtr as _CFuncPtr import os as _os --- 9,21 ---- del os, _magicfile ! __version__ = "0.9.0" from _ctypes import Union, Structure, Array from _ctypes import _Pointer from _ctypes import CFuncPtr as _CFuncPtr + from _ctypes import __version__ as _ctypes_version + + if __version__ != _ctypes_version: + raise Exception, ("Version number mismatch", __version__, _ctypes_version) import os as _os |
From: Thomas H. <th...@us...> - 2004-07-22 13:46:58
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13915 Modified Files: setup.py Log Message: Approaching version 0.9.0. Index: setup.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/setup.py,v retrieving revision 1.92 retrieving revision 1.93 diff -C2 -d -r1.92 -r1.93 *** setup.py 22 Jul 2004 12:43:00 -0000 1.92 --- setup.py 22 Jul 2004 13:46:49 -0000 1.93 *************** *** 420,424 **** packages = packages, ! version="0.6.3", description="create and manipulate C data types in Python", long_description = __doc__, --- 420,424 ---- packages = packages, ! version="0.9.0", description="create and manipulate C data types in Python", long_description = __doc__, |
From: Thomas H. <th...@us...> - 2004-07-22 12:43:10
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3014 Modified Files: setup.py Log Message: types.c is no longer needed. Index: setup.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/setup.py,v retrieving revision 1.91 retrieving revision 1.92 diff -C2 -d -r1.91 -r1.92 *** setup.py 21 Jul 2004 19:55:18 -0000 1.91 --- setup.py 22 Jul 2004 12:43:00 -0000 1.92 *************** *** 44,48 **** if os.name == "nt": kw["sources"].extend([ ! "source/libffi_msvc/types.c", "source/libffi_msvc/ffi.c", "source/libffi_msvc/prep_cif.c", --- 44,48 ---- if os.name == "nt": kw["sources"].extend([ ! # types.c is no longer needed, ffi_type defs are in cfield.c "source/libffi_msvc/ffi.c", "source/libffi_msvc/prep_cif.c", |
From: Thomas H. <th...@us...> - 2004-07-22 12:41:38
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2625 Modified Files: test_stringptr.py Log Message: Handle the case where libc.so can not be loaded. Index: test_stringptr.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_stringptr.py,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** test_stringptr.py 11 Jun 2004 09:43:11 -0000 1.7 --- test_stringptr.py 22 Jul 2004 12:41:26 -0000 1.8 *************** *** 2,5 **** --- 2,6 ---- from ctypes import * + libc = None import os, sys if os.name == "nt": *************** *** 14,18 **** libc = cdll.LoadLibrary("/lib/libc.so") else: ! libc = cdll.LoadLibrary("/lib/libc.so.6") class StringPtrTestCase(unittest.TestCase): --- 15,22 ---- libc = cdll.LoadLibrary("/lib/libc.so") else: ! try: ! libc = cdll.LoadLibrary("/lib/libc.so.6") ! except OSError: ! libc = None class StringPtrTestCase(unittest.TestCase): *************** *** 52,84 **** ! def test_functions(self): ! strchr = libc.strchr ! strchr.restype = c_char_p ! # 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 ! # POINTER(c_char) and c_buffer() is compatible ! strchr.argtypes = POINTER(c_char), c_char ! 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 ! # to strchr is no longer valid after the function returns! ! # So we must keep a reference to buf separately ! strchr.restype = POINTER(c_char) ! buf = c_buffer("abcdef") ! r = strchr(buf, "c") ! x = r[0], r[1], r[2], r[3], r[4] ! self.failUnlessEqual(x, ("c", "d", "e", "f", "\000")) ! del buf ! # x1 will NOT be the same as x, usually: ! x1 = r[0], r[1], r[2], r[3], r[4] if __name__ == '__main__': --- 56,89 ---- ! if libc is not None: ! def test_functions(self): ! strchr = libc.strchr ! strchr.restype = c_char_p ! # 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 ! # POINTER(c_char) and c_buffer() is compatible ! strchr.argtypes = POINTER(c_char), c_char ! 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 ! # to strchr is no longer valid after the function returns! ! # So we must keep a reference to buf separately ! strchr.restype = POINTER(c_char) ! buf = c_buffer("abcdef") ! r = strchr(buf, "c") ! x = r[0], r[1], r[2], r[3], r[4] ! self.failUnlessEqual(x, ("c", "d", "e", "f", "\000")) ! del buf ! # x1 will NOT be the same as x, usually: ! x1 = r[0], r[1], r[2], r[3], r[4] if __name__ == '__main__': |
From: Thomas H. <th...@us...> - 2004-07-22 12:40:29
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2404 Modified Files: cfield.c Log Message: size and alignment was swapped in the ffi_type definitions. Index: cfield.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/cfield.c,v retrieving revision 1.35 retrieving revision 1.36 diff -C2 -d -r1.35 -r1.36 *** cfield.c 22 Jul 2004 12:11:09 -0000 1.35 --- cfield.c 22 Jul 2004 12:40:20 -0000 1.36 *************** *** 1013,1025 **** ffi_type ffi_type_sint32 = { 4, 4, FFI_TYPE_SINT32 }; ! ffi_type ffi_type_uint64 = { LONG_LONG_ALIGN, 8, FFI_TYPE_UINT64 }; ! ffi_type ffi_type_sint64 = { LONG_LONG_ALIGN, 8, FFI_TYPE_SINT64 }; ! ffi_type ffi_type_float = { FLOAT_ALIGN, sizeof(float), FFI_TYPE_FLOAT }; ! ffi_type ffi_type_double = { DOUBLE_ALIGN, sizeof(double), FFI_TYPE_DOUBLE }; /* ffi_type ffi_type_longdouble */ ! ffi_type ffi_type_pointer = { VOID_P_ALIGN, sizeof(void *), FFI_TYPE_POINTER }; /*---------------- EOF ----------------*/ --- 1013,1025 ---- ffi_type ffi_type_sint32 = { 4, 4, FFI_TYPE_SINT32 }; ! ffi_type ffi_type_uint64 = { 8, LONG_LONG_ALIGN, FFI_TYPE_UINT64 }; ! ffi_type ffi_type_sint64 = { 8, LONG_LONG_ALIGN, FFI_TYPE_SINT64 }; ! ffi_type ffi_type_float = { sizeof(float), FLOAT_ALIGN, FFI_TYPE_FLOAT }; ! ffi_type ffi_type_double = { sizeof(double), DOUBLE_ALIGN, FFI_TYPE_DOUBLE }; /* ffi_type ffi_type_longdouble */ ! ffi_type ffi_type_pointer = { sizeof(void *), VOID_P_ALIGN, FFI_TYPE_POINTER }; /*---------------- EOF ----------------*/ |
From: Thomas H. <th...@us...> - 2004-07-22 12:37:47
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2005 Modified Files: test_funcptr.py Log Message: Handle the cases where libc.so can not be loaded. Index: test_funcptr.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_funcptr.py,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** test_funcptr.py 11 Jun 2004 09:37:56 -0000 1.14 --- test_funcptr.py 22 Jul 2004 12:37:32 -0000 1.15 *************** *** 8,24 **** WINFUNCTYPE = CFUNCTYPE ! import os, sys ! if os.name == "nt": ! libc = cdll.msvcrt ! ! elif os.name == "posix": ! if sys.platform == "darwin": ! libc = cdll.LoadLibrary("/usr/lib/libc.dylib") ! elif sys.platform == "cygwin": ! libc = cdll.LoadLibrary("/bin/cygwin1.dll") ! elif sys.platform == "sunos5": ! libc = cdll.LoadLibrary("/lib/libc.so") ! else: ! libc = cdll.LoadLibrary("/lib/libc.so.6") class CFuncPtrTestCase(unittest.TestCase): --- 8,30 ---- WINFUNCTYPE = CFUNCTYPE ! ! def get_libc(): ! import os, sys ! if os.name == "nt": ! return cdll.msvcrt ! elif os.name == "posix": ! if sys.platform == "darwin": ! return cdll.LoadLibrary("/usr/lib/libc.dylib") ! elif sys.platform == "cygwin": ! return cdll.LoadLibrary("/bin/cygwin1.dll") ! elif sys.platform == "sunos5": ! return cdll.LoadLibrary("/lib/libc.so") ! else: ! try: ! return cdll.LoadLibrary("/lib/libc.so.6") ! except OSError: ! pass ! return None ! libc = get_libc() class CFuncPtrTestCase(unittest.TestCase): *************** *** 91,132 **** self.failUnlessEqual(f(10, 11, 12, 13), 46) ! def test_dllfunctions(self): ! ! def NoNullHandle(value): ! if not value: ! raise WinError() ! return value ! ## f = windll.kernel32.GetModuleHandleA ! ## f.argtypes = (c_char_p,) ! ## f.restype = NoNullHandle ! strchr = libc.strchr ! strchr.restype = c_char_p ! strchr.argtypes = (c_char_p, c_char) ! self.failUnlessEqual(strchr("abcdefghi", "b"), "bcdefghi") ! self.failUnlessEqual(strchr("abcdefghi", "x"), None) ! strtok = libc.strtok ! strtok.restype = c_char_p ! # Neither of this does work ! ## strtok.argtypes = (c_char_p, c_char_p) ! ## strtok.argtypes = (c_string, c_char_p) ! def c_string(init): ! size = len(init) + 1 ! return (c_char*size)(*init) ! s = "a\nb\nc" ! b = c_string(s) ! ## b = (c_char * (len(s)+1))() ! ## b.value = s ! ## b = c_string(s) ! self.failUnlessEqual(strtok(b, "\n"), "a") ! self.failUnlessEqual(strtok(None, "\n"), "b") ! self.failUnlessEqual(strtok(None, "\n"), "c") ! self.failUnlessEqual(strtok(None, "\n"), None) if __name__ == '__main__': --- 97,135 ---- self.failUnlessEqual(f(10, 11, 12, 13), 46) ! if libc is not None: ! def test_dllfunctions(self): ! def NoNullHandle(value): ! if not value: ! raise WinError() ! return value ! strchr = libc.strchr ! strchr.restype = c_char_p ! strchr.argtypes = (c_char_p, c_char) ! self.failUnlessEqual(strchr("abcdefghi", "b"), "bcdefghi") ! self.failUnlessEqual(strchr("abcdefghi", "x"), None) ! strtok = libc.strtok ! strtok.restype = c_char_p ! # Neither of this does work ! ## strtok.argtypes = (c_char_p, c_char_p) ! ## strtok.argtypes = (c_string, c_char_p) ! def c_string(init): ! size = len(init) + 1 ! return (c_char*size)(*init) ! s = "a\nb\nc" ! b = c_string(s) ! ## b = (c_char * (len(s)+1))() ! ## b.value = s ! ## b = c_string(s) ! self.failUnlessEqual(strtok(b, "\n"), "a") ! self.failUnlessEqual(strtok(None, "\n"), "b") ! self.failUnlessEqual(strtok(None, "\n"), "c") ! self.failUnlessEqual(strtok(None, "\n"), None) if __name__ == '__main__': |
From: Thomas H. <th...@us...> - 2004-07-22 12:36:41
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1871 Modified Files: run_remote_test.py Log Message: Handle the cases where importing a test module fails. Index: run_remote_test.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/run_remote_test.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** run_remote_test.py 21 Jul 2004 19:55:18 -0000 1.1 --- run_remote_test.py 22 Jul 2004 12:36:30 -0000 1.2 *************** *** 1,6 **** import os, sys, unittest if __name__ == "__main__": ! dirname, filename = os.path.split(sys.argv[1]) basename, ext = os.path.splitext(filename) --- 1,15 ---- + # Todo: handle import error the same way as test errors. import os, sys, unittest + class TestFile(object): + def __init__(self, path): + self.path = path + def shortDescription(self): + return self.path + failureException = AssertionError + if __name__ == "__main__": ! pathname = sys.argv[1] ! dirname, filename = os.path.split(pathname) basename, ext = os.path.splitext(filename) *************** *** 8,11 **** sys.path.append(dirname) ! runner = unittest.TextTestRunner(open("test.output", "w"), verbosity=2) ! unittest.main(module=__import__(basename), testRunner=runner) --- 17,38 ---- sys.path.append(dirname) ! ! if 0: ! stream = open("test.output", "w") ! runner = unittest.TextTestRunner(stream, verbosity=2) ! else: ! # Strange, this path crashes with Python 2.3.4, release build, ! # on Windows XP, unless we write to stdout. An empty string! ! # Doesn't crash with Python 2.4. ! sys.stdout.write("") ! runner = unittest.TextTestRunner(open("test.output", "w"), verbosity=2) ! try: ! unittest.main(module=__import__(basename), testRunner=runner) ! except SystemExit: ! pass ! except: ! result = runner._makeResult() ! err = sys.exc_info() ! result.addError(TestFile(pathname), err) ! result.printErrors() ! result.stream.write("%s (could not import) ... ERROR\n" % pathname) |
From: Thomas H. <th...@us...> - 2004-07-22 12:11:18
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30724 Modified Files: cfield.c Log Message: Another attempt to avoid libffi's types.c file, because of bugs on MacOS. Index: cfield.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/cfield.c,v retrieving revision 1.34 retrieving revision 1.35 diff -C2 -d -r1.34 -r1.35 *** cfield.c 9 Jun 2004 19:47:16 -0000 1.34 --- cfield.c 22 Jul 2004 12:11:09 -0000 1.35 *************** *** 956,958 **** --- 956,1025 ---- } + typedef struct { char c; char x; } s_char; + typedef struct { char c; short x; } s_short; + typedef struct { char c; int x; } s_int; + typedef struct { char c; long x; } s_long; + typedef struct { char c; float x; } s_float; + typedef struct { char c; double x; } s_double; + typedef struct { char c; char *x; } s_char_p; + typedef struct { char c; void *x; } s_void_p; + + /* + #define CHAR_ALIGN (sizeof(s_char) - sizeof(char)) + #define SHORT_ALIGN (sizeof(s_short) - sizeof(short)) + #define INT_ALIGN (sizeof(s_int) - sizeof(int)) + #define LONG_ALIGN (sizeof(s_long) - sizeof(long)) + */ + #define FLOAT_ALIGN (sizeof(s_float) - sizeof(float)) + #define DOUBLE_ALIGN (sizeof(s_double) - sizeof(double)) + /* #define CHAR_P_ALIGN (sizeof(s_char_p) - sizeof(char*)) */ + #define VOID_P_ALIGN (sizeof(s_void_p) - sizeof(void*)) + + /* + #ifdef HAVE_USABLE_WCHAR_T + typedef struct { char c; wchar_t x; } s_wchar; + typedef struct { char c; wchar_t *x; } s_wchar_p; + + #define WCHAR_ALIGN (sizeof(s_wchar) - sizeof(wchar_t)) + #define WCHAR_P_ALIGN (sizeof(s_wchar_p) - sizeof(wchar_t*)) + #endif + */ + + #ifdef HAVE_LONG_LONG + typedef struct { char c; PY_LONG_LONG x; } s_long_long; + #define LONG_LONG_ALIGN (sizeof(s_long_long) - sizeof(PY_LONG_LONG)) + #endif + + /* from ffi.h: + typedef struct _ffi_type + { + size_t size; + unsigned short alignment; + unsigned short type; + struct _ffi_type **elements; + } ffi_type; + */ + + /* align and size are bogus for void, but they must not be zero */ + ffi_type ffi_type_void = { 1, 1, FFI_TYPE_VOID }; + + ffi_type ffi_type_uint8 = { 1, 1, FFI_TYPE_UINT8 }; + ffi_type ffi_type_sint8 = { 1, 1, FFI_TYPE_SINT8 }; + + ffi_type ffi_type_uint16 = { 2, 2, FFI_TYPE_UINT16 }; + ffi_type ffi_type_sint16 = { 2, 2, FFI_TYPE_SINT16 }; + + ffi_type ffi_type_uint32 = { 4, 4, FFI_TYPE_UINT32 }; + ffi_type ffi_type_sint32 = { 4, 4, FFI_TYPE_SINT32 }; + + ffi_type ffi_type_uint64 = { LONG_LONG_ALIGN, 8, FFI_TYPE_UINT64 }; + ffi_type ffi_type_sint64 = { LONG_LONG_ALIGN, 8, FFI_TYPE_SINT64 }; + + ffi_type ffi_type_float = { FLOAT_ALIGN, sizeof(float), FFI_TYPE_FLOAT }; + ffi_type ffi_type_double = { DOUBLE_ALIGN, sizeof(double), FFI_TYPE_DOUBLE }; + + /* ffi_type ffi_type_longdouble */ + + ffi_type ffi_type_pointer = { VOID_P_ALIGN, sizeof(void *), FFI_TYPE_POINTER }; + /*---------------- EOF ----------------*/ |
From: Thomas H. <th...@us...> - 2004-07-22 10:45:22
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18539 Modified Files: test_numbers.py Log Message: Better errors. Index: test_numbers.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_numbers.py,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** test_numbers.py 24 Jun 2004 19:11:31 -0000 1.18 --- test_numbers.py 22 Jul 2004 10:45:13 -0000 1.19 *************** *** 126,132 **** # alignment of the type... ! self.failUnlessEqual(alignment(t), align) ! # and alingment of an instance ! self.failUnlessEqual(alignment(t()), align) def test_int_from_address(self): --- 126,134 ---- # alignment of the type... ! self.failUnlessEqual((code, alignment(t)), ! (code, align)) ! # and alignment of an instance ! self.failUnlessEqual((code, alignment(t())), ! (code, align)) def test_int_from_address(self): |
From: Thomas H. <th...@us...> - 2004-07-22 10:09:44
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14523 Modified Files: test_structures.py Log Message: Better errors if the test fails. Index: test_structures.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_structures.py,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** test_structures.py 22 Jul 2004 09:59:07 -0000 1.14 --- test_structures.py 22 Jul 2004 10:09:35 -0000 1.15 *************** *** 25,29 **** _fields_ = [("x", c_char), ("y", tp)] ! self.failUnlessEqual(sizeof(X), calcsize("c%c0%c" % (code, code))) def test_unions(self): --- 25,30 ---- _fields_ = [("x", c_char), ("y", tp)] ! self.failUnlessEqual((sizeof(X), code), ! (calcsize("c%c0%c" % (code, code)), code)) def test_unions(self): |
From: Thomas H. <th...@us...> - 2004-07-22 09:59:18
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13151 Modified Files: test_structures.py Log Message: failUnless(a == b) -> failUnlessEqual(a, b) for better error reporting. Index: test_structures.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_structures.py,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** test_structures.py 2 Jun 2004 11:21:53 -0000 1.13 --- test_structures.py 22 Jul 2004 09:59:07 -0000 1.14 *************** *** 25,29 **** _fields_ = [("x", c_char), ("y", tp)] ! self.failUnless(sizeof(X) == calcsize("c%c0%c" % (code, code))) def test_unions(self): --- 25,29 ---- _fields_ = [("x", c_char), ("y", tp)] ! self.failUnlessEqual(sizeof(X), calcsize("c%c0%c" % (code, code))) def test_unions(self): *************** *** 38,55 **** class X(Structure): _fields_ = [("x", c_char * 3)] ! self.failUnless(alignment(X) == calcsize("s")) ! self.failUnless(sizeof(X) == calcsize("3s")) class Y(Structure): _fields_ = [("x", c_char * 3), ("y", c_int)] ! self.failUnless(alignment(Y) == calcsize("i")) ! self.failUnless(sizeof(Y) == calcsize("3si")) class SI(Structure): _fields_ = [("a", X), ("b", Y)] ! self.failUnless(alignment(SI) == max(alignment(Y), alignment(X))) ! self.failUnless(sizeof(SI) == calcsize("3s0i 3si 0i")) class IS(Structure): --- 38,55 ---- class X(Structure): _fields_ = [("x", c_char * 3)] ! self.failUnlessEqual(alignment(X), calcsize("s")) ! self.failUnlessEqual(sizeof(X), calcsize("3s")) class Y(Structure): _fields_ = [("x", c_char * 3), ("y", c_int)] ! self.failUnlessEqual(alignment(Y), calcsize("i")) ! self.failUnlessEqual(sizeof(Y), calcsize("3si")) class SI(Structure): _fields_ = [("a", X), ("b", Y)] ! self.failUnlessEqual(alignment(SI), max(alignment(Y), alignment(X))) ! self.failUnlessEqual(sizeof(SI), calcsize("3s0i 3si 0i")) class IS(Structure): *************** *** 57,68 **** ("a", X)] ! self.failUnless(alignment(SI) == max(alignment(X), alignment(Y))) ! self.failUnless(sizeof(IS) == calcsize("3si 3s 0i")) class XX(Structure): _fields_ = [("a", X), ("b", X)] ! self.failUnless(alignment(XX) == alignment(X)) ! self.failUnless(sizeof(XX) == calcsize("3s 3s 0s")) def test_emtpy(self): --- 57,68 ---- ("a", X)] ! self.failUnlessEqual(alignment(SI), max(alignment(X), alignment(Y))) ! self.failUnlessEqual(sizeof(IS), calcsize("3si 3s 0i")) class XX(Structure): _fields_ = [("a", X), ("b", X)] ! self.failUnlessEqual(alignment(XX), alignment(X)) ! self.failUnlessEqual(sizeof(XX), calcsize("3s 3s 0s")) def test_emtpy(self): *************** *** 84,89 **** ("b", X)] ! self.failUnless(alignment(XX) == 1) ! self.failUnless(sizeof(XX) == 0) def test_fields(self): --- 84,89 ---- ("b", X)] ! self.failUnlessEqual(alignment(XX), 1) ! self.failUnlessEqual(sizeof(XX), 0) def test_fields(self): *************** *** 93,101 **** ("y", c_char)] ! self.failUnless(X.x.offset == 0) ! self.failUnless(X.x.size == sizeof(c_int)) ! self.failUnless(X.y.offset == sizeof(c_int)) ! self.failUnless(X.y.size == sizeof(c_char)) # readonly --- 93,101 ---- ("y", c_char)] ! self.failUnlessEqual(X.x.offset, 0) ! self.failUnlessEqual(X.x.size, sizeof(c_int)) ! self.failUnlessEqual(X.y.offset, sizeof(c_int)) ! self.failUnlessEqual(X.y.size, sizeof(c_char)) # readonly *************** *** 107,115 **** ("y", c_char)] ! self.failUnless(X.x.offset == 0) ! self.failUnless(X.x.size == sizeof(c_int)) ! self.failUnless(X.y.offset == 0) ! self.failUnless(X.y.size == sizeof(c_char)) # readonly --- 107,115 ---- ("y", c_char)] ! self.failUnlessEqual(X.x.offset, 0) ! self.failUnlessEqual(X.x.size, sizeof(c_int)) ! self.failUnlessEqual(X.y.offset, 0) ! self.failUnlessEqual(X.y.size, sizeof(c_char)) # readonly *************** *** 126,131 **** _pack_ = 1 ! self.failUnless(sizeof(X) == 9, sizeof(X)) ! self.failUnless(X.b.offset == 1, X.b.offset) class X(Structure): --- 126,131 ---- _pack_ = 1 ! self.failUnlessEqual(sizeof(X), 9) ! self.failUnlessEqual(X.b.offset, 1) class X(Structure): *************** *** 133,138 **** ("b", c_longlong)] _pack_ = 2 ! self.failUnless(sizeof(X) == 10, sizeof(X)) ! self.failUnless(X.b.offset == 2, X.b.offset) class X(Structure): --- 133,138 ---- ("b", c_longlong)] _pack_ = 2 ! self.failUnlessEqual(sizeof(X), 10) ! self.failUnlessEqual(X.b.offset, 2) class X(Structure): *************** *** 140,145 **** ("b", c_longlong)] _pack_ = 4 ! self.failUnless(sizeof(X) == 12) ! self.failUnless(X.b.offset == 4) import struct --- 140,145 ---- ("b", c_longlong)] _pack_ = 4 ! self.failUnlessEqual(sizeof(X), 12) ! self.failUnlessEqual(X.b.offset, 4) import struct *************** *** 152,157 **** _pack_ = 8 ! self.failUnless(sizeof(X) == longlong_align + longlong_size) ! self.failUnless(X.b.offset == min(8, longlong_align)) --- 152,157 ---- _pack_ = 8 ! self.failUnlessEqual(sizeof(X), longlong_align + longlong_size) ! self.failUnlessEqual(X.b.offset, min(8, longlong_align)) |
From: Thomas H. <th...@us...> - 2004-07-22 08:41:39
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2487 Modified Files: _ctypes.c Log Message: Add code for array slicing - it is working, but not yet complete, so not enabled. Index: _ctypes.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes.c,v retrieving revision 1.148 retrieving revision 1.149 diff -C2 -d -r1.148 -r1.149 *** _ctypes.c 23 Jun 2004 16:26:13 -0000 1.148 --- _ctypes.c 22 Jul 2004 08:41:30 -0000 1.149 *************** *** 2824,2827 **** --- 2824,2856 ---- } + #ifdef CAN_SLICE + static PyListObject * + Array_slice(CDataObject *self, int ilow, int ihigh) + { + PyListObject *np; + int i, len; + + if (ilow < 0) + ilow = 0; + else if (ilow > self->b_length) + ilow = self->b_length; + if (ihigh < ilow) + ihigh = ilow; + else if (ihigh > self->b_length) + ihigh = self->b_length; + len = ihigh - ilow; + + np = (PyListObject *) PyList_New(len); + if (np == NULL) + return NULL; + + for (i = 0; i < len; i++) { + PyObject *v = Array_item(self, i+ilow); + PyList_SET_ITEM(np, i, v); + } + return np; + } + #endif + static int Array_ass_item(CDataObject *self, int index, PyObject *value) *************** *** 2851,2854 **** --- 2880,2927 ---- } + #ifdef CAN_SLICE + static int + Array_ass_slice(CDataObject *self, int ilow, int ihigh, PyObject *value) + { + int i, len; + PyObject *item; + + if (value == NULL) { + PyErr_SetString(PyExc_TypeError, + "Array does not support item deletion"); + return -1; + } + + if (ilow < 0) + ilow = 0; + else if (ilow > self->b_length) + ilow = self->b_length; + if (ihigh < 0) + ihigh = 0; + if (ihigh < ilow) + ihigh = ilow; + else if (ihigh > self->b_length) + ihigh = self->b_length; + + len = PySequence_Length(value); + if (len != ihigh - ilow) { + PyErr_SetString(PyExc_ValueError, + "Can only assign sequence of same size"); + return -1; + } + for (i = 0; i < len; i++) { + PyObject *item = PySequence_GetItem(value, i); + int result; + if (item == NULL) + return -1; + result = Array_ass_item(self, i+ilow, item); + Py_DECREF(item); + if (result == -1) + return -1; + } + return 0; + } + #endif + static int Array_length(CDataObject *self) *************** *** 2862,2868 **** --- 2935,2949 ---- 0, /* sq_repeat; */ (intargfunc)Array_item, /* sq_item; */ + #ifdef CAN_SLICE + (intintargfunc)Array_slice, /* sq_slice; */ + #else 0, /* sq_slice; */ + #endif (intobjargproc)Array_ass_item, /* sq_ass_item; */ + #ifdef CAN_SLICE + (intintobjargproc)Array_ass_slice, /* sq_ass_slice; */ + #else 0, /* sq_ass_slice; */ + #endif 0, /* sq_contains; */ |
From: Thomas H. <th...@us...> - 2004-07-22 08:31:44
|
Update of /cvsroot/ctypes/ctypes/unittests/com In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1147 Modified Files: test_comobject.py Log Message: Move COM test into the com subdirectory. Index: test_comobject.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/com/test_comobject.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** test_comobject.py 22 Jul 2004 08:10:42 -0000 1.1 --- test_comobject.py 22 Jul 2004 08:31:34 -0000 1.2 *************** *** 8,98 **** return comptr.Release() - if sys.platform == "win32": - class ComTestCase(unittest.TestCase): - def __init__(self, *args): - unittest.TestCase.__init__(self, *args) - global COMObject, IUnknown, GUID, STDMETHOD, HRESULT - from ctypes.com import COMObject, IUnknown, GUID, STDMETHOD, HRESULT ! def setUp(self): ! class IObjectWithSite(IUnknown): ! _iid_ = GUID("{FC4801A3-2BA9-11CF-A229-00AA003D7352}") ! _methods_ = IUnknown._methods_ + [ ! (STDMETHOD(HRESULT, "SetSite", POINTER(IUnknown))), ! (STDMETHOD(HRESULT, "GetSite", POINTER(GUID), POINTER(c_void_p)))] ! class Factory(object): ! def LockServer(self, *args): ! pass ! class MyObject(COMObject): ! _factory = Factory() ! _com_interfaces_ = [IObjectWithSite] ! def IObjectWithSite_SetSite(self, this, pUnkSite): ! self.m_site = pUnkSite ! return 0 # S_OK ! self.impl = MyObject() ! def tearDown(self): ! self.impl = None ! import gc ! gc.collect() ! ################ ! def test_site(self): ! impl = self.impl ! p = pointer(impl._com_pointers_[0][1]) ! self.failUnlessEqual(impl._refcnt, 0) ! p.AddRef() ! self.failUnlessEqual(impl._refcnt, 1) ! p.SetSite(p) ! self.failUnlessEqual(impl._refcnt, 2) ! p.SetSite(None) ! self.failUnlessEqual(impl._refcnt, 1) ! del p ! self.failUnlessEqual(impl._refcnt, 0) ! 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) ! del p2 ! self.failUnlessEqual(get_refcnt(p), 1) ! 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) ################################################################ --- 8,126 ---- return comptr.Release() ! class Test_EmptyComPointer(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 ! self._orig_del = POINTER(IUnknown).__del__ ! # We replace the __del__ method (which calls self.Release(), ! # because it would crash. ! def __del__(self): ! pass ! 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") ! class ComTestCase(unittest.TestCase): ! def __init__(self, *args): ! unittest.TestCase.__init__(self, *args) ! global COMObject, IUnknown, GUID, STDMETHOD, HRESULT ! from ctypes.com import COMObject, IUnknown, GUID, STDMETHOD, HRESULT ! def setUp(self): ! class IObjectWithSite(IUnknown): ! _iid_ = GUID("{FC4801A3-2BA9-11CF-A229-00AA003D7352}") ! _methods_ = IUnknown._methods_ + [ ! (STDMETHOD(HRESULT, "SetSite", POINTER(IUnknown))), ! (STDMETHOD(HRESULT, "GetSite", POINTER(GUID), POINTER(c_void_p)))] ! class Factory(object): ! def LockServer(self, *args): ! pass ! class MyObject(COMObject): ! _factory = Factory() ! _com_interfaces_ = [IObjectWithSite] ! def IObjectWithSite_SetSite(self, this, pUnkSite): ! self.m_site = pUnkSite ! return 0 # S_OK ! self.impl = MyObject() ! def tearDown(self): ! self.impl = None ! import gc ! gc.collect() ! ################ ! def test_site(self): ! impl = self.impl ! p = pointer(impl._com_pointers_[0][1]) ! self.failUnlessEqual(impl._refcnt, 0) ! p.AddRef() ! self.failUnlessEqual(impl._refcnt, 1) ! p.SetSite(p) ! self.failUnlessEqual(impl._refcnt, 2) ! p.SetSite(None) ! self.failUnlessEqual(impl._refcnt, 1) ! del p ! self.failUnlessEqual(impl._refcnt, 0) ! 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) ! del p2 ! self.failUnlessEqual(get_refcnt(p), 1) ! ! 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) ################################################################ |
From: Thomas H. <th...@us...> - 2004-07-22 08:31:34
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv970 Modified Files: test_random_things.py Log Message: Move COM test into the com subdirectory. Index: test_random_things.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_random_things.py,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** test_random_things.py 7 May 2004 07:36:49 -0000 1.4 --- test_random_things.py 22 Jul 2004 08:31:24 -0000 1.5 *************** *** 48,81 **** "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 - 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() --- 48,51 ---- |
From: Thomas H. <th...@us...> - 2004-07-22 08:29:50
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv527 Modified Files: test_values.py Log Message: Convert docstrings to comments - the unittest module would take the docstring as the test name. Index: test_values.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_values.py,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** test_values.py 6 May 2004 20:01:52 -0000 1.10 --- test_values.py 22 Jul 2004 08:29:26 -0000 1.11 *************** *** 32,42 **** 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__: --- 32,42 ---- 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__: *************** *** 48,58 **** 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), --- 48,59 ---- 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), |
From: Thomas H. <th...@us...> - 2004-07-22 08:16:25
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30730 Removed Files: test_variant.py test_comobject.py Log Message: Moved these files from unittests to unittests/com. --- test_variant.py DELETED --- --- test_comobject.py DELETED --- |