ctypes-commit Mailing List for ctypes (Page 23)
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...> - 2006-02-14 18:34:32
|
Update of /cvsroot/ctypes/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4712 Modified Files: Tag: branch_1_0 __init__.py Log Message: Make it work on Windows CE. Index: __init__.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/__init__.py,v retrieving revision 1.61.2.32 retrieving revision 1.61.2.33 diff -C2 -d -r1.61.2.32 -r1.61.2.33 *** __init__.py 10 Feb 2006 19:05:41 -0000 1.61.2.32 --- __init__.py 14 Feb 2006 18:34:24 -0000 1.61.2.33 *************** *** 103,110 **** FUNCFLAG_STDCALL as _FUNCFLAG_STDCALL if _os.name == "ce": _FUNCFLAG_STDCALL = _FUNCFLAG_CDECL - if _os.name == "nt": - # 'ce' doesn't have the stdcall calling convention _win_functype_cache = {} def WINFUNCTYPE(restype, *argtypes): --- 103,109 ---- FUNCFLAG_STDCALL as _FUNCFLAG_STDCALL if _os.name == "ce": + # 'ce' doesn't have the stdcall calling convention _FUNCFLAG_STDCALL = _FUNCFLAG_CDECL _win_functype_cache = {} def WINFUNCTYPE(restype, *argtypes): |
From: Thomas H. <th...@us...> - 2006-02-14 17:47:36
|
Update of /cvsroot/ctypes/ctypes/ctypes/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16492/ctypes/test Modified Files: Tag: branch_1_0 test_loading.py Log Message: Make the test work on x86-solaris. Index: test_loading.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/test/Attic/test_loading.py,v retrieving revision 1.1.2.7 retrieving revision 1.1.2.8 diff -C2 -d -r1.1.2.7 -r1.1.2.8 *** test_loading.py 14 Feb 2006 17:24:59 -0000 1.1.2.7 --- test_loading.py 14 Feb 2006 17:47:25 -0000 1.1.2.8 *************** *** 18,21 **** --- 18,23 ---- elif sys.platform.startswith("freebsd"): name = "libc.so" + elif sys.platform == "sunos5": + name = "libc.so" else: name = "libc.so.6" |
From: Thomas H. <th...@us...> - 2006-02-14 17:25:12
|
Update of /cvsroot/ctypes/ctypes/ctypes/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10043 Modified Files: Tag: branch_1_0 test_loading.py Log Message: Debug the test. Index: test_loading.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/test/Attic/test_loading.py,v retrieving revision 1.1.2.6 retrieving revision 1.1.2.7 diff -C2 -d -r1.1.2.6 -r1.1.2.7 *** test_loading.py 2 Feb 2006 16:45:29 -0000 1.1.2.6 --- test_loading.py 14 Feb 2006 17:24:59 -0000 1.1.2.7 *************** *** 8,11 **** --- 8,13 ---- def test_load(self): + print (os.name, sys.platform) + if os.name == "nt": name = "msvcrt" |
From: Thomas H. <th...@us...> - 2006-02-14 17:22:55
|
Update of /cvsroot/ctypes/ctypes/ctypes/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9440/ctypes/test Modified Files: Tag: branch_1_0 test_funcptr.py Log Message: Export strtok function from _ctypes_test to avoid the hassle finding the correct libraries on all platforms that we support. Index: test_funcptr.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/test/Attic/test_funcptr.py,v retrieving revision 1.1.2.4 retrieving revision 1.1.2.5 diff -C2 -d -r1.1.2.4 -r1.1.2.5 *** test_funcptr.py 14 Feb 2006 17:16:18 -0000 1.1.2.4 --- test_funcptr.py 14 Feb 2006 17:22:45 -0000 1.1.2.5 *************** *** 102,108 **** ! ## strtok = lib.strtok ! ## strtok.restype = c_char_p ! ## # Neither of this does work: strtok changes the buffer it is passed ## strtok.argtypes = (c_char_p, c_char_p) ## strtok.argtypes = (c_string, c_char_p) --- 102,108 ---- ! strtok = lib.my_strtok ! strtok.restype = c_char_p ! # Neither of this does work: strtok changes the buffer it is passed ## strtok.argtypes = (c_char_p, c_char_p) ## strtok.argtypes = (c_string, c_char_p) |
From: Thomas H. <th...@us...> - 2006-02-14 17:22:55
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9440/source Modified Files: Tag: branch_1_0 _ctypes_test.c Log Message: Export strtok function from _ctypes_test to avoid the hassle finding the correct libraries on all platforms that we support. Index: _ctypes_test.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes_test.c,v retrieving revision 1.46.2.9 retrieving revision 1.46.2.10 diff -C2 -d -r1.46.2.9 -r1.46.2.10 *** _ctypes_test.c 14 Feb 2006 17:13:20 -0000 1.46.2.9 --- _ctypes_test.c 14 Feb 2006 17:22:45 -0000 1.46.2.10 *************** *** 21,24 **** --- 21,29 ---- /* some functions handy for testing */ + EXPORT(char *)my_strtok(char *token, const char *delim) + { + return strtok(token, delim); + } + EXPORT(char *)my_strchr(const char *s, int c) { |
From: Thomas H. <th...@us...> - 2006-02-14 17:16:31
|
Update of /cvsroot/ctypes/ctypes/ctypes/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7230/ctypes/test Modified Files: Tag: branch_1_0 test_funcptr.py Log Message: Export strchr function from _ctypes_test to avoid the hassle finding the correct libraries on all platforms that we support. Index: test_funcptr.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/test/Attic/test_funcptr.py,v retrieving revision 1.1.2.3 retrieving revision 1.1.2.4 diff -C2 -d -r1.1.2.3 -r1.1.2.4 *** test_funcptr.py 27 Jan 2006 18:43:16 -0000 1.1.2.3 --- test_funcptr.py 14 Feb 2006 17:16:18 -0000 1.1.2.4 *************** *** 1,4 **** import unittest ! from ctypes import * # bad style, generally try: --- 1,4 ---- import unittest ! from ctypes import * try: *************** *** 8,17 **** WINFUNCTYPE = CFUNCTYPE ! ! import os, sys ! if os.name == "nt": ! libc = cdll.msvcrt ! else: ! libc = cdll.find("c") class CFuncPtrTestCase(unittest.TestCase): --- 8,13 ---- WINFUNCTYPE = CFUNCTYPE ! import _ctypes_test ! lib = cdll.load(_ctypes_test.__file__) class CFuncPtrTestCase(unittest.TestCase): *************** *** 99,103 **** return value ! strchr = libc.strchr strchr.restype = c_char_p strchr.argtypes = (c_char_p, c_char) --- 95,99 ---- return value ! strchr = lib.strchr strchr.restype = c_char_p strchr.argtypes = (c_char_p, c_char) *************** *** 105,111 **** 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) --- 101,108 ---- self.failUnlessEqual(strchr("abcdefghi", "x"), None) ! ! ## strtok = lib.strtok ! ## strtok.restype = c_char_p ! ## # Neither of this does work: strtok changes the buffer it is passed ## strtok.argtypes = (c_char_p, c_char_p) ## strtok.argtypes = (c_string, c_char_p) |
From: Thomas H. <th...@us...> - 2006-02-14 17:13:28
|
Update of /cvsroot/ctypes/ctypes/ctypes/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5538/ctypes/test Modified Files: Tag: branch_1_0 test_stringptr.py Log Message: Export strchr function from _ctypes_test to avoid the hassle finding the correct libraries on all platforms that we support. Index: test_stringptr.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/test/Attic/test_stringptr.py,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -C2 -d -r1.1.2.2 -r1.1.2.3 *** test_stringptr.py 26 Jan 2006 21:15:25 -0000 1.1.2.2 --- test_stringptr.py 14 Feb 2006 17:13:20 -0000 1.1.2.3 *************** *** 2,23 **** from ctypes import * ! libc = None ! import os, sys ! if os.name == "nt": ! libc = cdll.msvcrt ! ! elif os.name == "posix": ! libc = cdll.find("c") ! ## 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: ! ## try: ! ## libc = cdll.LoadLibrary("/lib/libc.so.6") ! ## except OSError: ! ## libc = None class StringPtrTestCase(unittest.TestCase): --- 2,8 ---- from ctypes import * ! import _ctypes_test ! ! lib = cdll.load(_ctypes_test.__file__) class StringPtrTestCase(unittest.TestCase): *************** *** 57,90 **** ! 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__': --- 42,74 ---- ! def test_functions(self): ! strchr = lib.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...> - 2006-02-14 17:13:28
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5538/source Modified Files: Tag: branch_1_0 _ctypes_test.c Log Message: Export strchr function from _ctypes_test to avoid the hassle finding the correct libraries on all platforms that we support. Index: _ctypes_test.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes_test.c,v retrieving revision 1.46.2.8 retrieving revision 1.46.2.9 diff -C2 -d -r1.46.2.8 -r1.46.2.9 *** _ctypes_test.c 14 Feb 2006 17:05:33 -0000 1.46.2.8 --- _ctypes_test.c 14 Feb 2006 17:13:20 -0000 1.46.2.9 *************** *** 21,24 **** --- 21,30 ---- /* some functions handy for testing */ + EXPORT(char *)my_strchr(const char *s, int c) + { + return strchr(s, c); + } + + EXPORT(double) my_sqrt(double a) { |
From: Thomas H. <th...@us...> - 2006-02-14 17:05:48
|
Update of /cvsroot/ctypes/ctypes/ctypes/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1092/ctypes/test Modified Files: Tag: branch_1_0 test_libc.py Log Message: Export sqrt and qsort functions from _ctypes_test to avoid the hassle finding the correct libraries on all platforms that we support. Index: test_libc.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/test/Attic/test_libc.py,v retrieving revision 1.1.2.4 retrieving revision 1.1.2.5 diff -C2 -d -r1.1.2.4 -r1.1.2.5 *** test_libc.py 26 Jan 2006 19:56:18 -0000 1.1.2.4 --- test_libc.py 14 Feb 2006 17:05:32 -0000 1.1.2.5 *************** *** 3,35 **** from ctypes import * ! if os.name == "nt": ! # somewhat dangerous, should use the msvcr version that Python ! # itself uses! ! libm = libc = cdll.find('msvcrt') ! else: ! libm = cdll.find("m") ! libc = cdll.find("c") class LibTest(unittest.TestCase): def test_sqrt(self): ! libm.sqrt.argtypes = c_double, ! libm.sqrt.restype = c_double ! self.failUnlessEqual(libm.sqrt(4.0), 2.0) import math ! self.failUnlessEqual(libm.sqrt(2.0), math.sqrt(2.0)) ! ! ## def test_cdecl_decorator(self): ! ## # @ cdecl(c_double, "libm", [c_double]) ! ## def sqrt(value): ! ## return sqrt._api_(value) ! ## # Oh well, compatibility with Python 2.3 ! ## sqrt = cdecl(c_double, libm, [c_double]) (sqrt) ! ## self.failUnlessEqual(sqrt(4.0), 2.0) def test_qsort(self): comparefunc = CFUNCTYPE(c_int, POINTER(c_char), POINTER(c_char)) ! libc.qsort.argtypes = c_void_p, c_int, c_int, comparefunc ! libc.qsort.restype = None def sort(a, b): --- 3,22 ---- from ctypes import * + import _ctypes_test ! lib = cdll.load(_ctypes_test.__file__) class LibTest(unittest.TestCase): def test_sqrt(self): ! lib.my_sqrt.argtypes = c_double, ! lib.my_sqrt.restype = c_double ! self.failUnlessEqual(lib.my_sqrt(4.0), 2.0) import math ! self.failUnlessEqual(lib.my_sqrt(2.0), math.sqrt(2.0)) def test_qsort(self): comparefunc = CFUNCTYPE(c_int, POINTER(c_char), POINTER(c_char)) ! lib.my_qsort.argtypes = c_void_p, c_size_t, c_size_t, comparefunc ! lib.my_qsort.restype = None def sort(a, b): *************** *** 37,59 **** chars = create_string_buffer("spam, spam, and spam") ! libc.qsort(chars, len(chars)-1, sizeof(c_char), comparefunc(sort)) self.failUnlessEqual(chars.raw, " ,,aaaadmmmnpppsss\x00") - ## def test_qsort_decorator(self): - ## from ctypes.decorators import cdecl - ## CMPFUNC = CFUNCTYPE(c_int, c_void_p, c_void_p) - ## #@ cdecl(None, "libc", [c_void_p, c_int, c_int, CMPFUNC]) - ## def qsort(sequence, cmp_func): - ## itemsize = sizeof(sequence) / len(sequence) - ## qsort._api_(sequence, len(sequence), itemsize, CMPFUNC(cmp_func)) - ## qsort = cdecl(None, "c", [c_void_p, c_int, c_int, CMPFUNC])(qsort) - ## def sortfunc(a, b): - ## a = cast(a, POINTER(c_int)) - ## b = cast(b, POINTER(c_int)) - ## return cmp(a[0], b[0]) - ## ints = (c_int * 9)(1, 3, 5, 7, 9, 8, 6, 4, 2) - ## qsort(ints, sortfunc) - ## self.failUnlessEqual(ints[:], [1, 2, 3, 4, 5, 6, 7, 8, 9]) - if __name__ == "__main__": unittest.main() --- 24,30 ---- chars = create_string_buffer("spam, spam, and spam") ! lib.my_qsort(chars, len(chars)-1, sizeof(c_char), comparefunc(sort)) self.failUnlessEqual(chars.raw, " ,,aaaadmmmnpppsss\x00") if __name__ == "__main__": unittest.main() |
From: Thomas H. <th...@us...> - 2006-02-14 17:05:44
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1092/source Modified Files: Tag: branch_1_0 _ctypes_test.c Log Message: Export sqrt and qsort functions from _ctypes_test to avoid the hassle finding the correct libraries on all platforms that we support. Index: _ctypes_test.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes_test.c,v retrieving revision 1.46.2.7 retrieving revision 1.46.2.8 diff -C2 -d -r1.46.2.7 -r1.46.2.8 *** _ctypes_test.c 3 Nov 2005 19:48:32 -0000 1.46.2.7 --- _ctypes_test.c 14 Feb 2006 17:05:33 -0000 1.46.2.8 *************** *** 21,24 **** --- 21,34 ---- /* some functions handy for testing */ + EXPORT(double) my_sqrt(double a) + { + return sqrt(a); + } + + EXPORT(void) my_qsort(void *base, size_t num, size_t width, int(*compare)(const void*, const void*)) + { + return qsort(base, num, width, compare); + } + EXPORT(int *) _testfunc_ai8(int a[8]) { |
From: Thomas H. <th...@us...> - 2006-02-14 17:04:34
|
Update of /cvsroot/ctypes/ctypes/ctypes/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv608/ctypes/test Modified Files: Tag: branch_1_0 test_leaks.py Log Message: Raise the margin for leaks (the test is broken, imo, anyway). Index: test_leaks.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/test/Attic/test_leaks.py,v retrieving revision 1.1.2.3 retrieving revision 1.1.2.4 diff -C2 -d -r1.1.2.3 -r1.1.2.4 *** test_leaks.py 27 Jan 2006 18:18:54 -0000 1.1.2.3 --- test_leaks.py 14 Feb 2006 17:04:15 -0000 1.1.2.4 *************** *** 75,79 **** # sys.getobjects(), but this is only available in debug build. last_objcount = 0 ! for x in xrange(5): self.make_cyclic_structures(1000) while gc.collect(): --- 75,79 ---- # sys.getobjects(), but this is only available in debug build. last_objcount = 0 ! for x in xrange(8): self.make_cyclic_structures(1000) while gc.collect(): *************** *** 85,97 **** self.fail("leaking objects") - ## def test_dll_leak_1(self): - ## dll = cdll.LoadLibrary("msvcrt.dll") - #### dll = cdll.load("msvcrt.dll") - #### dll = cdll.msvcrt - ## dll._inp.restype = c_byte - ## del dll - ## gc.collect() - ## print gc.garbage - if __name__ == "__main__": unittest.main() --- 85,88 ---- |
From: Thomas H. <th...@us...> - 2006-02-14 16:42:25
|
Update of /cvsroot/ctypes/ctypes/ctypes/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25272 Removed Files: Tag: branch_1_0 test_paramflags.py Log Message: Remove that that depends on comtypes. --- test_paramflags.py DELETED --- |
From: Thomas H. <th...@us...> - 2006-02-13 22:09:21
|
Update of /cvsroot/ctypes/ctypes/docs/manual In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15804 Modified Files: Tag: branch_1_0 manual.txt manual.html Added Files: Tag: branch_1_0 struct_union.txt Log Message: Work in progress. Index: manual.txt =================================================================== RCS file: /cvsroot/ctypes/ctypes/docs/manual/Attic/manual.txt,v retrieving revision 1.1.2.6 retrieving revision 1.1.2.7 diff -C2 -d -r1.1.2.6 -r1.1.2.7 *** manual.txt 3 Feb 2006 08:32:06 -0000 1.1.2.6 --- manual.txt 13 Feb 2006 22:09:12 -0000 1.1.2.7 *************** *** 11,13 **** --- 11,14 ---- .. include:: callbacks.txt .. include:: simple_types.txt + .. include:: struct_union.txt .. include:: utilities.txt Index: manual.html =================================================================== RCS file: /cvsroot/ctypes/ctypes/docs/manual/Attic/manual.html,v retrieving revision 1.1.2.6 retrieving revision 1.1.2.7 diff -C2 -d -r1.1.2.6 -r1.1.2.7 *** manual.html 13 Feb 2006 21:39:24 -0000 1.1.2.6 --- manual.html 13 Feb 2006 22:09:12 -0000 1.1.2.7 *************** *** 319,324 **** </ul> </li> ! <li><a class="reference" href="#builtin-functions" id="id17" name="id17">Builtin functions</a><ul> ! <li><a class="reference" href="#deprecated-functions" id="id18" name="id18">Deprecated functions</a></li> </ul> </li> --- 319,332 ---- </ul> </li> ! <li><a class="reference" href="#structure-and-union-types" id="id17" name="id17">Structure and union types</a><ul> ! <li><a class="reference" href="#defining-field-names-and-types" id="id18" name="id18">Defining field names and types</a></li> ! <li><a class="reference" href="#packing-fields" id="id19" name="id19">Packing fields</a></li> ! <li><a class="reference" href="#bit-fields" id="id20" name="id20">Bit fields</a></li> ! <li><a class="reference" href="#recursive-data-types" id="id21" name="id21">Recursive data types</a></li> ! <li><a class="reference" href="#byte-order" id="id22" name="id22">Byte order</a></li> ! </ul> ! </li> ! <li><a class="reference" href="#builtin-functions" id="id23" name="id23">Builtin functions</a><ul> ! <li><a class="reference" href="#deprecated-functions" id="id24" name="id24">Deprecated functions</a></li> </ul> </li> *************** *** 714,718 **** </div> <div class="section"> ! <h1><a class="toc-backref" href="#id17" id="builtin-functions" name="builtin-functions">Builtin functions</a></h1> <p><tt class="docutils literal"><span class="pre">CFUNCTYPE(restype,</span> <span class="pre">*argtypes)</span></tt></p> <blockquote> --- 722,783 ---- </div> <div class="section"> ! <h1><a class="toc-backref" href="#id17" id="structure-and-union-types" name="structure-and-union-types">Structure and union types</a></h1> ! <p>ctypes provides the abstract base classes <tt class="docutils literal"><span class="pre">Structure</span></tt> and <tt class="docutils literal"><span class="pre">Union</span></tt> ! to define structure and union types. Subclasses must at least define ! a <tt class="docutils literal"><span class="pre">_fields_</span></tt> attribute.</p> ! <div class="section"> ! <h2><a class="toc-backref" href="#id18" id="defining-field-names-and-types" name="defining-field-names-and-types">Defining field names and types</a></h2> ! <p><tt class="docutils literal"><span class="pre">_fields_</span></tt> must be a sequence of tuples. The first item of each ! tuple is a string specifying the name of the structure/union field. ! The second item must by a ctypes type.</p> ! <p>A descriptor will be created for each field, it allows to access the ! fields contents from instances. Accessed from the class, the fields ! expose <cite>readonly `</cite>.offset`` and <tt class="docutils literal"><span class="pre">.size</span></tt> attributes. <tt class="docutils literal"><span class="pre">offset</span></tt> is ! the byte-offset of the field from the beginning of the ! structure/union, <tt class="docutils literal"><span class="pre">size</span></tt> is the number of bytes the field contains.</p> ! <p>A simple example is a POINT structure containing integer fields named ! <tt class="docutils literal"><span class="pre">x</span></tt> and <tt class="docutils literal"><span class="pre">y</span></tt>:</p> ! <pre class="literal-block"> ! class Point(Structure): ! _fields_ = [("x", c_int), ! ("y", c_int)] ! </pre> ! </div> ! <div class="section"> ! <h2><a class="toc-backref" href="#id19" id="packing-fields" name="packing-fields">Packing fields</a></h2> ! <p>Normally fields are aligned in the same way as the hosts C compiler. ! The native alignment can be overridden by setting a <tt class="docutils literal"><span class="pre">_pack_</span></tt> ! attribute in the type. This must be a small positive integer which is ! the maximum field alignment.</p> ! </div> ! <div class="section"> ! <h2><a class="toc-backref" href="#id20" id="bit-fields" name="bit-fields">Bit fields</a></h2> ! <p>Integer fields support bit sizes. The bit-size must be specified as ! the third item of the <tt class="docutils literal"><span class="pre">_fields_</span></tt> tuple. Bit fields are constructed ! in the same way the hosts C compiler does it.</p> ! </div> ! <div class="section"> ! <h2><a class="toc-backref" href="#id21" id="recursive-data-types" name="recursive-data-types">Recursive data types</a></h2> ! <p>To support recursive type definitions, it is possible to assign the ! <tt class="docutils literal"><span class="pre">_fields_</span></tt> value after the class statement. Here is an example of a ! linked list, which contains pointers to itself:</p> ! <pre class="literal-block"> ! class Node(Structure): ! pass ! Node._fields_ = [("next", POINTER(Node)), ! ("value", ...)] ! </pre> ! </div> ! <div class="section"> ! <h2><a class="toc-backref" href="#id22" id="byte-order" name="byte-order">Byte order</a></h2> ! <p>It is possible to create Structure and Union types using non-native ! byte order by using the <tt class="docutils literal"><span class="pre">BugEndianStructure</span></tt>, ! <tt class="docutils literal"><span class="pre">LittleEndianStructure</span></tt>, <tt class="docutils literal"><span class="pre">BigEndianUnion</span></tt>, and ! <tt class="docutils literal"><span class="pre">LittleEndianUnion</span></tt> base classes. Structures and Unions with ! non-native byte order do <em>not</em> support pointer fields.</p> ! </div> ! </div> ! <div class="section"> ! <h1><a class="toc-backref" href="#id23" id="builtin-functions" name="builtin-functions">Builtin functions</a></h1> <p><tt class="docutils literal"><span class="pre">CFUNCTYPE(restype,</span> <span class="pre">*argtypes)</span></tt></p> <blockquote> *************** *** 810,820 **** Return the last error code set by Windows.</blockquote> <div class="section"> ! <h2><a class="toc-backref" href="#id18" id="deprecated-functions" name="deprecated-functions">Deprecated functions</a></h2> <p><tt class="docutils literal"><span class="pre">c_buffer(init,</span> <span class="pre">size=None)</span></tt></p> <blockquote> ! Deprecated.</blockquote> <p><tt class="docutils literal"><span class="pre">ARRAY(cls,</span> <span class="pre">len)</span></tt></p> <blockquote> ! Deprecated.</blockquote> <p><tt class="docutils literal"><span class="pre">SetPointerType(pointer_class,</span> <span class="pre">cls)</span></tt></p> <blockquote> --- 875,885 ---- Return the last error code set by Windows.</blockquote> <div class="section"> ! <h2><a class="toc-backref" href="#id24" id="deprecated-functions" name="deprecated-functions">Deprecated functions</a></h2> <p><tt class="docutils literal"><span class="pre">c_buffer(init,</span> <span class="pre">size=None)</span></tt></p> <blockquote> ! Deprecated. Use <tt class="docutils literal"><span class="pre">create_string_buffer</span></tt> instead.</blockquote> <p><tt class="docutils literal"><span class="pre">ARRAY(cls,</span> <span class="pre">len)</span></tt></p> <blockquote> ! Deprecated. Use <tt class="docutils literal"><span class="pre">cls</span> <span class="pre">*</span> <span class="pre">len</span></tt> instead.</blockquote> <p><tt class="docutils literal"><span class="pre">SetPointerType(pointer_class,</span> <span class="pre">cls)</span></tt></p> <blockquote> --- NEW FILE: struct_union.txt --- Structure and union types ------------------------- ctypes provides the abstract base classes ``Structure`` and ``Union`` to define structure and union types. Subclasses must at least define a ``_fields_`` attribute. Defining field names and types ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ``_fields_`` must be a sequence of tuples. The first item of each tuple is a string specifying the name of the structure/union field. The second item must by a ctypes type. A descriptor will be created for each field, it allows to access the fields contents from instances. Accessed from the class, the fields expose readonly ``.offset`` and ``.size`` attributes. ``offset`` is the byte-offset of the field from the beginning of the structure/union, ``size`` is the number of bytes the field contains. A simple example is a POINT structure containing integer fields named ``x`` and ``y``:: class Point(Structure): _fields_ = [("x", c_int), ("y", c_int)] Packing fields ~~~~~~~~~~~~~~ Normally fields are aligned in the same way as the hosts C compiler. The native alignment can be overridden by setting a ``_pack_`` attribute in the type. This must be a small positive integer which is the maximum field alignment. Bit fields ~~~~~~~~~~ Integer fields support bit sizes. The bit-size must be specified as the third item of the ``_fields_`` tuple. Bit fields are constructed in the same way the hosts C compiler does it. For bit fields, the field descriptors ``.size`` attribute contains the number of bits in the high word, the bit offset from the beginning of the structure in the low word. XXX is that correct? Recursive data types ~~~~~~~~~~~~~~~~~~~~ To support recursive type definitions, it is possible to assign the ``_fields_`` value after the class statement. Here is an example of a linked list, which contains pointers to itself:: class Node(Structure): pass Node._fields_ = [("next", POINTER(Node)), ("value", ...)] ``_fields_`` must be set, and cannot be changed, after the type is used for the first time. Byte order ~~~~~~~~~~ It is possible to create Structure and Union types using non-native byte order by using the ``BugEndianStructure``, ``LittleEndianStructure``, ``BigEndianUnion``, and ``LittleEndianUnion`` base classes. Structures and Unions with non-native byte order do *not* support pointer fields. |
From: Thomas H. <th...@us...> - 2006-02-13 21:39:33
|
Update of /cvsroot/ctypes/ctypes/docs/manual In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6029 Modified Files: Tag: branch_1_0 utilities.txt simple_types.txt manual.html libraries.txt functions.txt Log Message: Work in progress. Index: functions.txt =================================================================== RCS file: /cvsroot/ctypes/ctypes/docs/manual/Attic/functions.txt,v retrieving revision 1.1.2.3 retrieving revision 1.1.2.4 diff -C2 -d -r1.1.2.3 -r1.1.2.4 *** functions.txt 3 Feb 2006 08:32:06 -0000 1.1.2.3 --- functions.txt 13 Feb 2006 21:39:24 -0000 1.1.2.4 *************** *** 1,9 **** ! Function objects ! ---------------- ! Functions exported from loaded shared libraries can be accessed in two ! ways. The easiest way is to access them as attributes of library ! obects by name:: libc = cdll.find("c") # posix --- 1,9 ---- ! Foreign functions ! ----------------- ! Functions exported from loaded shared libraries (foreign functions) ! can be accessed in two ways. The easiest way is to retrieve them as ! attributes of library objects by name:: libc = cdll.find("c") # posix *************** *** 11,28 **** atoi = libc.atoi ! This creates an instance of a forein function object, using the calling convention specified by the library object ``cdll``, bound to ! the standard C library ``atoi`` function. The C function is assumed ! to return an integer (which is correct for ``atoi``), and the argument ! types are not specified (``atoi`` expects a single ``char *`` ! argument). If the library function returns a type different from ``int``, the ! ``restype`` attribute can be set to a ctypes type that describes to return type, or to ```None`` meaning no return value (``void``). The optional ``argtypes`` attribute can be set to a sequence of ctypes ! types that the function expects. The function can (as in C) be called ! with more arguments than the length of the argtypes sequence. The optional ``errcheck`` attribute can be set to a Python callable, --- 11,29 ---- atoi = libc.atoi ! This creates an instance of a foreign function object, using the calling convention specified by the library object ``cdll``, bound to ! the C library ``atoi`` function. The C function is assumed to return ! an integer (which is correct for ``atoi``), and the argument types are ! not specified (``atoi`` expects a single ``char *`` argument). If the library function returns a type different from ``int``, the ! ``restype`` attribute can be set to a ctypes type that describes the return type, or to ```None`` meaning no return value (``void``). The optional ``argtypes`` attribute can be set to a sequence of ctypes ! types that the function expects. ! ! If needed, the function can (as in C) be called with more arguments ! than the length of the argtypes sequence. The optional ``errcheck`` attribute can be set to a Python callable, *************** *** 33,37 **** errcheck(retval, function, arguments) ! ``retval`` is the value that the library function returned, comverted according to ``restype``. ``function`` is the ctypes function object (libc.atoi in this case), and ``arguments`` is a tuple containing the --- 34,38 ---- errcheck(retval, function, arguments) ! ``retval`` is the value that the library function returned, converted according to ``restype``. ``function`` is the ctypes function object (libc.atoi in this case), and ``arguments`` is a tuple containing the *************** *** 62,70 **** An instance of this function prototype, bound to a foreign library function, can be created by calling the prototype with the name of the ! function, and a library object:: proto = CFUNCTYPE(c_int, c_char_p) atoi = proto("atoi", libc) It is possible to specify a third argument ``paramflags`` when calling the prototype. This is used to specify additional information for --- 63,74 ---- An instance of this function prototype, bound to a foreign library function, can be created by calling the prototype with the name of the ! function as string, and a loaded library:: proto = CFUNCTYPE(c_int, c_char_p) atoi = proto("atoi", libc) + Parameter flags + ~~~~~~~~~~~~~~~ + It is possible to specify a third argument ``paramflags`` when calling the prototype. This is used to specify additional information for Index: libraries.txt =================================================================== RCS file: /cvsroot/ctypes/ctypes/docs/manual/Attic/libraries.txt,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -C2 -d -r1.1.2.2 -r1.1.2.3 *** libraries.txt 3 Feb 2006 08:32:06 -0000 1.1.2.2 --- libraries.txt 13 Feb 2006 21:39:24 -0000 1.1.2.3 *************** *** 18,22 **** ~~~~~~~~~~~~~~~~~~~ ! Instances of this ``LibraryLoader`` are used to load shared libraries. They have the following methods: --- 18,22 ---- ~~~~~~~~~~~~~~~~~~~ ! Instances of ``LibraryLoader`` are used to load shared libraries. They have the following methods: Index: utilities.txt =================================================================== RCS file: /cvsroot/ctypes/ctypes/docs/manual/Attic/utilities.txt,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -C2 -d -r1.1.2.1 -r1.1.2.2 *** utilities.txt 3 Feb 2006 08:32:06 -0000 1.1.2.1 --- utilities.txt 13 Feb 2006 21:39:24 -0000 1.1.2.2 *************** *** 4,54 **** ``CFUNCTYPE(restype, *argtypes)`` ! ``WINFUNCTYPE(restype, *argtypes)`` (Windows only) ``addressof(object)`` ! ``alignment(object)`` ! ``sizeof(object)`` ``byref(object)`` ``cast(object, typ)`` ``POINTER(cls)`` ``pointer(object)`` ``string_at(addr[, size])`` ``wstring_at(addr[, size])`` ``create_string_buffer(init, size=None)`` ``create_unicode_buffer(init, size=None)`` ``memmove(dst, src, count)`` ``memset(dst, c, count)`` ``set_conversion_mode(encoding, errors)`` ``DllCanUnloadNow()``, ``DllGetClassObject(rclsid, riid, ppv)`` (Windows only) ``WinError(code=None, descr=None)`` ! ``FormatError([integer])`` (Windows only) ``GetLastError()`` (Windows only) Deprecated functions --- 4,122 ---- ``CFUNCTYPE(restype, *argtypes)`` ! Create a function prototype using the C calling convention. + ``WINFUNCTYPE(restype, *argtypes)`` (Windows only) + Create a function prototype using the __stdcall calling convention + (on Windows), or using the C calling convention (on Windows CE). ``addressof(object)`` ! Returns the address of a ctypes instance as integer. ! ``alignment(type_or_object)`` ! ! Returns the alignment requirements in bytes of a ctypes type or ! instance. + ``sizeof(type_or_object)`` + + Returns the size in bytes for a ctypes type or instance. Same as + the C sizeof() function. ``byref(object)`` + Returns a light-weight pointer to a ctypes instance. The returned + object can only be used as function call parameter. Behaves the + same as calling ``pointer(object)``, but is a lot faster. Same as + ``&object`` in C. + ``cast(object, typ)`` + Somewhat similar to the cast operator in C. Interpret and return + ``object`` as if it was an instance of type ``typ``. ``typ`` must + be a pointer type. + + XXX more needed. + ``POINTER(cls)`` + This factory function creates and returns a new ctypes type. + Pointer types are cashed, so calling this function is cheap. + + To create a ``NULL`` pointer instance, use this recipe:: + + null_ptr = POINTER(c_int)() + ``pointer(object)`` + This function creates a new pointer instance, pointing to the + supplied argument. The return pointer is of type + ``POINTER(type(object))``. If you have a ctypes instance, and you + want to pass the address of it to a function call, you should use + ``byref(object)`` which is much faster. + ``string_at(addr[, size])`` + This function does the same as the Python PyString_FromString / + PyString_FromStringAndSize C api functions. + ``wstring_at(addr[, size])`` + This function does the same as the Python PyUnicode_FromWideString + C api function. If ``size`` is not specified, ``wcslen`` is used + to determine the string length. ``create_string_buffer(init, size=None)`` + Convenience function to create a mutable character buffer. + + ``create_unicode_buffer(init, size=None)`` + Convenience function to create a mutable unicode buffer. + ``memmove(dst, src, count)`` + Same as the standard C ``memmove`` library function: copies + ``count`` bytes from ``src`` to ``dst``. ``dst`` and ``src`` must + be integers or anything that can be converted into a pointer. + ``memset(dst, c, count)`` + Same as the standard C ``memset`` function. Fill the memory block + at address ``dst`` with ``count`` bytes of value ``c``. + ``set_conversion_mode(encoding, errors)`` + This function sets the encoding/decoding rules when ctypes has to + convert between unicode and byte strings. It returns the previous + encoding, errors tuple. ``DllCanUnloadNow()``, ``DllGetClassObject(rclsid, riid, ppv)`` (Windows only) + Functions used in COM servers. + ``WinError(code=None, descr=None)`` ! XXX This is probably the worst named thing in ctypes! ! ! This function creates a WindowsError instance. If ``code`` is not ! specified, GetLastError() is called to determine the error code. ! If ``descr`` is not specified, ``FormatError`` is called to get a ! textual description of the error. ! ! ``FormatError([code])`` (Windows only) ! ! Return a textual description of the error code, or the last error ! code set by Windows. ``GetLastError()`` (Windows only) + Return the last error code set by Windows. Deprecated functions *************** *** 57,65 **** ``c_buffer(init, size=None)`` ! Deprecated. ``ARRAY(cls, len)`` ! Deprecated. ``SetPointerType(pointer_class, cls)`` --- 125,133 ---- ``c_buffer(init, size=None)`` ! Deprecated. Use ``create_string_buffer`` instead. ``ARRAY(cls, len)`` ! Deprecated. Use ``cls * len`` instead. ``SetPointerType(pointer_class, cls)`` Index: manual.html =================================================================== RCS file: /cvsroot/ctypes/ctypes/docs/manual/Attic/manual.html,v retrieving revision 1.1.2.5 retrieving revision 1.1.2.6 diff -C2 -d -r1.1.2.5 -r1.1.2.6 *** manual.html 3 Feb 2006 08:32:06 -0000 1.1.2.5 --- manual.html 13 Feb 2006 21:39:24 -0000 1.1.2.6 *************** *** 302,323 **** </ul> </li> ! <li><a class="reference" href="#function-objects" id="id4" name="id4">Function objects</a><ul> <li><a class="reference" href="#function-prototypes" id="id5" name="id5">Function prototypes</a></li> ! <li><a class="reference" href="#com-methods-windows-only" id="id6" name="id6">COM methods (Windows only)</a></li> ! <li><a class="reference" href="#callback-functions" id="id7" name="id7">Callback functions</a></li> </ul> </li> ! <li><a class="reference" href="#simple-types" id="id8" name="id8">Simple types</a><ul> ! <li><a class="reference" href="#class-attributes-of-simple-types" id="id9" name="id9">Class attributes of simple types</a></li> ! <li><a class="reference" href="#class-methods-of-simple-types" id="id10" name="id10">Class methods of simple types</a></li> ! <li><a class="reference" href="#instance-attributes-of-simple-types" id="id11" name="id11">Instance attributes of simple types</a></li> ! <li><a class="reference" href="#numeric-types" id="id12" name="id12">Numeric types</a></li> ! <li><a class="reference" href="#character-types" id="id13" name="id13">Character types</a></li> ! <li><a class="reference" href="#pointer-types" id="id14" name="id14">Pointer types</a></li> ! <li><a class="reference" href="#string-types" id="id15" name="id15">String types</a></li> </ul> </li> ! <li><a class="reference" href="#builtin-functions" id="id16" name="id16">Builtin functions</a><ul> ! <li><a class="reference" href="#deprecated-functions" id="id17" name="id17">Deprecated functions</a></li> </ul> </li> --- 302,324 ---- </ul> </li> ! <li><a class="reference" href="#foreign-functions" id="id4" name="id4">Foreign functions</a><ul> <li><a class="reference" href="#function-prototypes" id="id5" name="id5">Function prototypes</a></li> ! <li><a class="reference" href="#parameter-flags" id="id6" name="id6">Parameter flags</a></li> ! <li><a class="reference" href="#com-methods-windows-only" id="id7" name="id7">COM methods (Windows only)</a></li> ! <li><a class="reference" href="#callback-functions" id="id8" name="id8">Callback functions</a></li> </ul> </li> ! <li><a class="reference" href="#simple-types" id="id9" name="id9">Simple types</a><ul> ! <li><a class="reference" href="#class-attributes-of-simple-types" id="id10" name="id10">Class attributes of simple types</a></li> ! <li><a class="reference" href="#class-methods-of-simple-types" id="id11" name="id11">Class methods of simple types</a></li> ! <li><a class="reference" href="#instance-attributes-of-simple-types" id="id12" name="id12">Instance attributes of simple types</a></li> ! <li><a class="reference" href="#numeric-types" id="id13" name="id13">Numeric types</a></li> ! <li><a class="reference" href="#character-types" id="id14" name="id14">Character types</a></li> ! <li><a class="reference" href="#pointer-types" id="id15" name="id15">Pointer types</a></li> ! <li><a class="reference" href="#string-types" id="id16" name="id16">String types</a></li> </ul> </li> ! <li><a class="reference" href="#builtin-functions" id="id17" name="id17">Builtin functions</a><ul> ! <li><a class="reference" href="#deprecated-functions" id="id18" name="id18">Deprecated functions</a></li> </ul> </li> *************** *** 338,342 **** <div class="section"> <h2><a class="toc-backref" href="#id2" id="class-libraryloader" name="class-libraryloader">class LibraryLoader</a></h2> ! <p>Instances of this <tt class="docutils literal"><span class="pre">LibraryLoader</span></tt> are used to load shared libraries. They have the following methods:</p> <p><tt class="docutils literal"><span class="pre">load(libname,</span> <span class="pre">mode=None)</span></tt></p> --- 339,343 ---- <div class="section"> <h2><a class="toc-backref" href="#id2" id="class-libraryloader" name="class-libraryloader">class LibraryLoader</a></h2> ! <p>Instances of <tt class="docutils literal"><span class="pre">LibraryLoader</span></tt> are used to load shared libraries. They have the following methods:</p> <p><tt class="docutils literal"><span class="pre">load(libname,</span> <span class="pre">mode=None)</span></tt></p> *************** *** 438,445 **** </div> <div class="section"> ! <h1><a class="toc-backref" href="#id4" id="function-objects" name="function-objects">Function objects</a></h1> ! <p>Functions exported from loaded shared libraries can be accessed in two ! ways. The easiest way is to access them as attributes of library ! obects by name:</p> <pre class="literal-block"> libc = cdll.find("c") # posix --- 439,446 ---- </div> <div class="section"> ! <h1><a class="toc-backref" href="#id4" id="foreign-functions" name="foreign-functions">Foreign functions</a></h1> ! <p>Functions exported from loaded shared libraries (foreign functions) ! can be accessed in two ways. The easiest way is to retrieve them as ! attributes of library objects by name:</p> <pre class="literal-block"> libc = cdll.find("c") # posix *************** *** 447,462 **** atoi = libc.atoi </pre> ! <p>This creates an instance of a forein function object, using the calling convention specified by the library object <tt class="docutils literal"><span class="pre">cdll</span></tt>, bound to ! the standard C library <tt class="docutils literal"><span class="pre">atoi</span></tt> function. The C function is assumed ! to return an integer (which is correct for <tt class="docutils literal"><span class="pre">atoi</span></tt>), and the argument ! types are not specified (<tt class="docutils literal"><span class="pre">atoi</span></tt> expects a single <tt class="docutils literal"><span class="pre">char</span> <span class="pre">*</span></tt> ! argument).</p> <p>If the library function returns a type different from <tt class="docutils literal"><span class="pre">int</span></tt>, the ! <tt class="docutils literal"><span class="pre">restype</span></tt> attribute can be set to a ctypes type that describes to return type, or to <tt class="docutils literal"><span class="pre">`None</span></tt> meaning no return value (<tt class="docutils literal"><span class="pre">void</span></tt>).</p> <p>The optional <tt class="docutils literal"><span class="pre">argtypes</span></tt> attribute can be set to a sequence of ctypes ! types that the function expects. The function can (as in C) be called ! with more arguments than the length of the argtypes sequence.</p> <p>The optional <tt class="docutils literal"><span class="pre">errcheck</span></tt> attribute can be set to a Python callable, it can be used to validate and/or process the library functions return --- 448,463 ---- atoi = libc.atoi </pre> ! <p>This creates an instance of a foreign function object, using the calling convention specified by the library object <tt class="docutils literal"><span class="pre">cdll</span></tt>, bound to ! the C library <tt class="docutils literal"><span class="pre">atoi</span></tt> function. The C function is assumed to return ! an integer (which is correct for <tt class="docutils literal"><span class="pre">atoi</span></tt>), and the argument types are ! not specified (<tt class="docutils literal"><span class="pre">atoi</span></tt> expects a single <tt class="docutils literal"><span class="pre">char</span> <span class="pre">*</span></tt> argument).</p> <p>If the library function returns a type different from <tt class="docutils literal"><span class="pre">int</span></tt>, the ! <tt class="docutils literal"><span class="pre">restype</span></tt> attribute can be set to a ctypes type that describes the return type, or to <tt class="docutils literal"><span class="pre">`None</span></tt> meaning no return value (<tt class="docutils literal"><span class="pre">void</span></tt>).</p> <p>The optional <tt class="docutils literal"><span class="pre">argtypes</span></tt> attribute can be set to a sequence of ctypes ! types that the function expects.</p> ! <p>If needed, the function can (as in C) be called with more arguments ! than the length of the argtypes sequence.</p> <p>The optional <tt class="docutils literal"><span class="pre">errcheck</span></tt> attribute can be set to a Python callable, it can be used to validate and/or process the library functions return *************** *** 466,470 **** errcheck(retval, function, arguments) </pre> ! <p><tt class="docutils literal"><span class="pre">retval</span></tt> is the value that the library function returned, comverted according to <tt class="docutils literal"><span class="pre">restype</span></tt>. <tt class="docutils literal"><span class="pre">function</span></tt> is the ctypes function object (libc.atoi in this case), and <tt class="docutils literal"><span class="pre">arguments</span></tt> is a tuple containing the --- 467,471 ---- errcheck(retval, function, arguments) </pre> ! <p><tt class="docutils literal"><span class="pre">retval</span></tt> is the value that the library function returned, converted according to <tt class="docutils literal"><span class="pre">restype</span></tt>. <tt class="docutils literal"><span class="pre">function</span></tt> is the ctypes function object (libc.atoi in this case), and <tt class="docutils literal"><span class="pre">arguments</span></tt> is a tuple containing the *************** *** 490,498 **** <p>An instance of this function prototype, bound to a foreign library function, can be created by calling the prototype with the name of the ! function, and a library object:</p> <pre class="literal-block"> proto = CFUNCTYPE(c_int, c_char_p) atoi = proto("atoi", libc) </pre> <p>It is possible to specify a third argument <tt class="docutils literal"><span class="pre">paramflags</span></tt> when calling the prototype. This is used to specify additional information for --- 491,502 ---- <p>An instance of this function prototype, bound to a foreign library function, can be created by calling the prototype with the name of the ! function as string, and a loaded library:</p> <pre class="literal-block"> proto = CFUNCTYPE(c_int, c_char_p) atoi = proto("atoi", libc) </pre> + </div> + <div class="section"> + <h2><a class="toc-backref" href="#id6" id="parameter-flags" name="parameter-flags">Parameter flags</a></h2> <p>It is possible to specify a third argument <tt class="docutils literal"><span class="pre">paramflags</span></tt> when calling the prototype. This is used to specify additional information for *************** *** 531,535 **** </div> <div class="section"> ! <h2><a class="toc-backref" href="#id6" id="com-methods-windows-only" name="com-methods-windows-only">COM methods (Windows only)</a></h2> <p>XXX Should this be left undocumented? Mentioned for completeness.</p> <p>The prototypes created by <tt class="docutils literal"><span class="pre">WINFUNCTYPE</span></tt> can be called with a --- 535,539 ---- </div> <div class="section"> ! <h2><a class="toc-backref" href="#id7" id="com-methods-windows-only" name="com-methods-windows-only">COM methods (Windows only)</a></h2> <p>XXX Should this be left undocumented? Mentioned for completeness.</p> <p>The prototypes created by <tt class="docutils literal"><span class="pre">WINFUNCTYPE</span></tt> can be called with a *************** *** 548,552 **** </div> <div class="section"> ! <h2><a class="toc-backref" href="#id7" id="callback-functions" name="callback-functions">Callback functions</a></h2> <p>ctypes is able to create C callable functions from Python callables. This is useful because sometimes library functions need a callback --- 552,556 ---- </div> <div class="section"> ! <h2><a class="toc-backref" href="#id8" id="callback-functions" name="callback-functions">Callback functions</a></h2> <p>ctypes is able to create C callable functions from Python callables. This is useful because sometimes library functions need a callback *************** *** 576,580 **** </div> <div class="section"> ! <h1><a class="toc-backref" href="#id8" id="simple-types" name="simple-types">Simple types</a></h1> <p>Simple types have some special behaviour: When they are accessed as structure or union fields, items of array instances, or as foreign --- 580,584 ---- </div> <div class="section"> ! <h1><a class="toc-backref" href="#id9" id="simple-types" name="simple-types">Simple types</a></h1> <p>Simple types have some special behaviour: When they are accessed as structure or union fields, items of array instances, or as foreign *************** *** 586,590 **** allows to almost completely define new behaviour.</p> <div class="section"> ! <h2><a class="toc-backref" href="#id9" id="class-attributes-of-simple-types" name="class-attributes-of-simple-types">Class attributes of simple types</a></h2> <p><tt class="docutils literal"><span class="pre">__ctype__be__</span></tt>, <tt class="docutils literal"><span class="pre">__ctype_le__</span></tt></p> <blockquote> --- 590,594 ---- allows to almost completely define new behaviour.</p> <div class="section"> ! <h2><a class="toc-backref" href="#id10" id="class-attributes-of-simple-types" name="class-attributes-of-simple-types">Class attributes of simple types</a></h2> <p><tt class="docutils literal"><span class="pre">__ctype__be__</span></tt>, <tt class="docutils literal"><span class="pre">__ctype_le__</span></tt></p> <blockquote> *************** *** 596,600 **** </div> <div class="section"> ! <h2><a class="toc-backref" href="#id10" id="class-methods-of-simple-types" name="class-methods-of-simple-types">Class methods of simple types</a></h2> <p>(To be exact, these are not class methods, instead these are methods of the metaclass. The most prominent difference to classmethods is --- 600,604 ---- </div> <div class="section"> ! <h2><a class="toc-backref" href="#id11" id="class-methods-of-simple-types" name="class-methods-of-simple-types">Class methods of simple types</a></h2> <p>(To be exact, these are not class methods, instead these are methods of the metaclass. The most prominent difference to classmethods is *************** *** 630,634 **** </div> <div class="section"> ! <h2><a class="toc-backref" href="#id11" id="instance-attributes-of-simple-types" name="instance-attributes-of-simple-types">Instance attributes of simple types</a></h2> <p><tt class="docutils literal"><span class="pre">_type_</span></tt></p> <blockquote> --- 634,638 ---- </div> <div class="section"> ! <h2><a class="toc-backref" href="#id12" id="instance-attributes-of-simple-types" name="instance-attributes-of-simple-types">Instance attributes of simple types</a></h2> <p><tt class="docutils literal"><span class="pre">_type_</span></tt></p> <blockquote> *************** *** 661,667 **** </div> <div class="section"> ! <h2><a class="toc-backref" href="#id12" id="numeric-types" name="numeric-types">Numeric types</a></h2> <p>Integer types are <tt class="docutils literal"><span class="pre">c_byte</span></tt>, <tt class="docutils literal"><span class="pre">c_short</span></tt>, <tt class="docutils literal"><span class="pre">c_int</span></tt>, <tt class="docutils literal"><span class="pre">c_long</span></tt>, ! <tt class="docutils literal"><span class="pre">c_longlong</span></tt> and there unsigned variants <tt class="docutils literal"><span class="pre">c_ubyte</span></tt>, <tt class="docutils literal"><span class="pre">c_ushort</span></tt>, <tt class="docutils literal"><span class="pre">c_uint</span></tt>, <tt class="docutils literal"><span class="pre">c_ulong</span></tt> and <tt class="docutils literal"><span class="pre">c_longlong</span></tt>, floating point types are <tt class="docutils literal"><span class="pre">c_float</span></tt> and <tt class="docutils literal"><span class="pre">c_double</span></tt>.</p> --- 665,671 ---- </div> <div class="section"> ! <h2><a class="toc-backref" href="#id13" id="numeric-types" name="numeric-types">Numeric types</a></h2> <p>Integer types are <tt class="docutils literal"><span class="pre">c_byte</span></tt>, <tt class="docutils literal"><span class="pre">c_short</span></tt>, <tt class="docutils literal"><span class="pre">c_int</span></tt>, <tt class="docutils literal"><span class="pre">c_long</span></tt>, ! <tt class="docutils literal"><span class="pre">c_longlong</span></tt> and their unsigned variants <tt class="docutils literal"><span class="pre">c_ubyte</span></tt>, <tt class="docutils literal"><span class="pre">c_ushort</span></tt>, <tt class="docutils literal"><span class="pre">c_uint</span></tt>, <tt class="docutils literal"><span class="pre">c_ulong</span></tt> and <tt class="docutils literal"><span class="pre">c_longlong</span></tt>, floating point types are <tt class="docutils literal"><span class="pre">c_float</span></tt> and <tt class="docutils literal"><span class="pre">c_double</span></tt>.</p> *************** *** 673,677 **** </div> <div class="section"> ! <h2><a class="toc-backref" href="#id13" id="character-types" name="character-types">Character types</a></h2> <p>Character types are <tt class="docutils literal"><span class="pre">c_char</span></tt> and <tt class="docutils literal"><span class="pre">c_wchar</span></tt>, representing the C <tt class="docutils literal"><span class="pre">char</span></tt> and <tt class="docutils literal"><span class="pre">wchar_t</span></tt> types.</p> --- 677,681 ---- </div> <div class="section"> ! <h2><a class="toc-backref" href="#id14" id="character-types" name="character-types">Character types</a></h2> <p>Character types are <tt class="docutils literal"><span class="pre">c_char</span></tt> and <tt class="docutils literal"><span class="pre">c_wchar</span></tt>, representing the C <tt class="docutils literal"><span class="pre">char</span></tt> and <tt class="docutils literal"><span class="pre">wchar_t</span></tt> types.</p> *************** *** 682,698 **** </div> <div class="section"> ! <h2><a class="toc-backref" href="#id14" id="pointer-types" name="pointer-types">Pointer types</a></h2> <p>The only simple pointer type is <tt class="docutils literal"><span class="pre">c_void_p</span></tt>, which represents the C <tt class="docutils literal"><span class="pre">void</span> <span class="pre">*</span></tt> datra type. <tt class="docutils literal"><span class="pre">c_void_p</span></tt> can also be written as <tt class="docutils literal"><span class="pre">POINTER(None)</span></tt>.</p> <p>The constructor accepts one optional argument, which must be an ! integer, or <tt class="docutils literal"><span class="pre">None</span></tt>.</p> ! <p>The <tt class="docutils literal"><span class="pre">from_param</span></tt> class method accepts Python strings or unicode ! strings, as well as <tt class="docutils literal"><span class="pre">None</span></tt>.</p> <p>The <tt class="docutils literal"><span class="pre">value</span></tt> attribute accepts and returns None or integer.</p> ! <p>XXX Why does from_param accept an integer, and the constructor doesn't?</p> </div> <div class="section"> ! <h2><a class="toc-backref" href="#id15" id="string-types" name="string-types">String types</a></h2> <p>ctypes has the <tt class="docutils literal"><span class="pre">c_char_p</span></tt> and <tt class="docutils literal"><span class="pre">c_wchar_p</span></tt> types which represent const pointers to zero terminated strings in C: <tt class="docutils literal"><span class="pre">const</span> <span class="pre">char</span> <span class="pre">*</span></tt> and --- 686,703 ---- </div> <div class="section"> ! <h2><a class="toc-backref" href="#id15" id="pointer-types" name="pointer-types">Pointer types</a></h2> <p>The only simple pointer type is <tt class="docutils literal"><span class="pre">c_void_p</span></tt>, which represents the C <tt class="docutils literal"><span class="pre">void</span> <span class="pre">*</span></tt> datra type. <tt class="docutils literal"><span class="pre">c_void_p</span></tt> can also be written as <tt class="docutils literal"><span class="pre">POINTER(None)</span></tt>.</p> <p>The constructor accepts one optional argument, which must be an ! integer or long interpreted as address, or <tt class="docutils literal"><span class="pre">None</span></tt>.</p> ! <p>The <tt class="docutils literal"><span class="pre">from_param</span></tt> class method accepts everything that could be used ! as a pointer. XXX Should accept objects using the buffer interface as ! well.</p> <p>The <tt class="docutils literal"><span class="pre">value</span></tt> attribute accepts and returns None or integer.</p> ! <p>XXX Shouldn't the constructor accept the same types than from_param?</p> </div> <div class="section"> ! <h2><a class="toc-backref" href="#id16" id="string-types" name="string-types">String types</a></h2> <p>ctypes has the <tt class="docutils literal"><span class="pre">c_char_p</span></tt> and <tt class="docutils literal"><span class="pre">c_wchar_p</span></tt> types which represent const pointers to zero terminated strings in C: <tt class="docutils literal"><span class="pre">const</span> <span class="pre">char</span> <span class="pre">*</span></tt> and *************** *** 709,735 **** </div> <div class="section"> ! <h1><a class="toc-backref" href="#id16" id="builtin-functions" name="builtin-functions">Builtin functions</a></h1> <p><tt class="docutils literal"><span class="pre">CFUNCTYPE(restype,</span> <span class="pre">*argtypes)</span></tt></p> <p><tt class="docutils literal"><span class="pre">WINFUNCTYPE(restype,</span> <span class="pre">*argtypes)</span></tt> (Windows only)</p> <p><tt class="docutils literal"><span class="pre">addressof(object)</span></tt></p> ! <p><tt class="docutils literal"><span class="pre">alignment(object)</span></tt></p> ! <p><tt class="docutils literal"><span class="pre">sizeof(object)</span></tt></p> <p><tt class="docutils literal"><span class="pre">byref(object)</span></tt></p> <p><tt class="docutils literal"><span class="pre">cast(object,</span> <span class="pre">typ)</span></tt></p> <p><tt class="docutils literal"><span class="pre">POINTER(cls)</span></tt></p> <p><tt class="docutils literal"><span class="pre">pointer(object)</span></tt></p> <p><tt class="docutils literal"><span class="pre">string_at(addr[,</span> <span class="pre">size])</span></tt></p> <p><tt class="docutils literal"><span class="pre">wstring_at(addr[,</span> <span class="pre">size])</span></tt></p> <p><tt class="docutils literal"><span class="pre">create_string_buffer(init,</span> <span class="pre">size=None)</span></tt></p> <p><tt class="docutils literal"><span class="pre">create_unicode_buffer(init,</span> <span class="pre">size=None)</span></tt></p> <p><tt class="docutils literal"><span class="pre">memmove(dst,</span> <span class="pre">src,</span> <span class="pre">count)</span></tt></p> <p><tt class="docutils literal"><span class="pre">memset(dst,</span> <span class="pre">c,</span> <span class="pre">count)</span></tt></p> <p><tt class="docutils literal"><span class="pre">set_conversion_mode(encoding,</span> <span class="pre">errors)</span></tt></p> <p><tt class="docutils literal"><span class="pre">DllCanUnloadNow()</span></tt>, <tt class="docutils literal"><span class="pre">DllGetClassObject(rclsid,</span> <span class="pre">riid,</span> <span class="pre">ppv)</span></tt> (Windows only)</p> <p><tt class="docutils literal"><span class="pre">WinError(code=None,</span> <span class="pre">descr=None)</span></tt></p> ! <p><tt class="docutils literal"><span class="pre">FormatError([integer])</span></tt> (Windows only)</p> <p><tt class="docutils literal"><span class="pre">GetLastError()</span></tt> (Windows only)</p> <div class="section"> ! <h2><a class="toc-backref" href="#id17" id="deprecated-functions" name="deprecated-functions">Deprecated functions</a></h2> <p><tt class="docutils literal"><span class="pre">c_buffer(init,</span> <span class="pre">size=None)</span></tt></p> <blockquote> --- 714,814 ---- </div> <div class="section"> ! <h1><a class="toc-backref" href="#id17" id="builtin-functions" name="builtin-functions">Builtin functions</a></h1> <p><tt class="docutils literal"><span class="pre">CFUNCTYPE(restype,</span> <span class="pre">*argtypes)</span></tt></p> + <blockquote> + Create a function prototype using the C calling convention.</blockquote> <p><tt class="docutils literal"><span class="pre">WINFUNCTYPE(restype,</span> <span class="pre">*argtypes)</span></tt> (Windows only)</p> + <blockquote> + Create a function prototype using the __stdcall calling convention + (on Windows), or using the C calling convention (on Windows CE).</blockquote> <p><tt class="docutils literal"><span class="pre">addressof(object)</span></tt></p> ! <blockquote> ! Returns the address of a ctypes instance as integer.</blockquote> ! <p><tt class="docutils literal"><span class="pre">alignment(type_or_object)</span></tt></p> ! <blockquote> ! Returns the alignment requirements in bytes of a ctypes type or ! instance.</blockquote> ! <p><tt class="docutils literal"><span class="pre">sizeof(type_or_object)</span></tt></p> ! <blockquote> ! Returns the size in bytes for a ctypes type or instance. Same as ! the C sizeof() function.</blockquote> <p><tt class="docutils literal"><span class="pre">byref(object)</span></tt></p> + <blockquote> + Returns a light-weight pointer to a ctypes instance. The returned + object can only be used as function call parameter. Behaves the + same as calling <tt class="docutils literal"><span class="pre">pointer(object)</span></tt>, but is a lot faster. Same as + <tt class="docutils literal"><span class="pre">&object</span></tt> in C.</blockquote> <p><tt class="docutils literal"><span class="pre">cast(object,</span> <span class="pre">typ)</span></tt></p> + <blockquote> + <p>Somewhat similar to the cast operator in C. Interpret and return + <tt class="docutils literal"><span class="pre">object</span></tt> as if it was an instance of type <tt class="docutils literal"><span class="pre">typ</span></tt>. <tt class="docutils literal"><span class="pre">typ</span></tt> must + be a pointer type.</p> + <p>XXX more needed.</p> + </blockquote> <p><tt class="docutils literal"><span class="pre">POINTER(cls)</span></tt></p> + <blockquote> + <p>This factory function creates and returns a new ctypes type. + Pointer types are cashed, so calling this function is cheap.</p> + <p>To create a <tt class="docutils literal"><span class="pre">NULL</span></tt> pointer instance, use this recipe:</p> + <pre class="literal-block"> + null_ptr = POINTER(c_int)() + </pre> + </blockquote> <p><tt class="docutils literal"><span class="pre">pointer(object)</span></tt></p> + <blockquote> + This function creates a new pointer instance, pointing to the + supplied argument. The return pointer is of type + <tt class="docutils literal"><span class="pre">POINTER(type(object))</span></tt>. If you have a ctypes instance, and you + want to pass the address of it to a function call, you should use + <tt class="docutils literal"><span class="pre">byref(object)</span></tt> which is much faster.</blockquote> <p><tt class="docutils literal"><span class="pre">string_at(addr[,</span> <span class="pre">size])</span></tt></p> + <blockquote> + This function does the same as the Python PyString_FromString / + PyString_FromStringAndSize C api functions.</blockquote> <p><tt class="docutils literal"><span class="pre">wstring_at(addr[,</span> <span class="pre">size])</span></tt></p> + <blockquote> + This function does the same as the Python PyUnicode_FromWideString + C api function. If <tt class="docutils literal"><span class="pre">size</span></tt> is not specified, <tt class="docutils literal"><span class="pre">wcslen</span></tt> is used + to determine the string length.</blockquote> <p><tt class="docutils literal"><span class="pre">create_string_buffer(init,</span> <span class="pre">size=None)</span></tt></p> + <blockquote> + Convenience function to create a mutable character buffer.</blockquote> <p><tt class="docutils literal"><span class="pre">create_unicode_buffer(init,</span> <span class="pre">size=None)</span></tt></p> + <blockquote> + Convenience function to create a mutable unicode buffer.</blockquote> <p><tt class="docutils literal"><span class="pre">memmove(dst,</span> <span class="pre">src,</span> <span class="pre">count)</span></tt></p> + <blockquote> + Same as the standard C <tt class="docutils literal"><span class="pre">memmove</span></tt> library function: copies + <tt class="docutils literal"><span class="pre">count</span></tt> bytes from <tt class="docutils literal"><span class="pre">src</span></tt> to <tt class="docutils literal"><span class="pre">dst</span></tt>. <tt class="docutils literal"><span class="pre">dst</span></tt> and <tt class="docutils literal"><span class="pre">src</span></tt> must + be integers or anything that can be converted into a pointer.</blockquote> <p><tt class="docutils literal"><span class="pre">memset(dst,</span> <span class="pre">c,</span> <span class="pre">count)</span></tt></p> + <blockquote> + Same as the standard C <tt class="docutils literal"><span class="pre">memset</span></tt> function. Fill the memory block + at address <tt class="docutils literal"><span class="pre">dst</span></tt> with <tt class="docutils literal"><span class="pre">count</span></tt> bytes of value <tt class="docutils literal"><span class="pre">c</span></tt>.</blockquote> <p><tt class="docutils literal"><span class="pre">set_conversion_mode(encoding,</span> <span class="pre">errors)</span></tt></p> + <blockquote> + This function sets the encoding/decoding rules when ctypes has to + convert between unicode and byte strings. It returns the previous + encoding, errors tuple.</blockquote> <p><tt class="docutils literal"><span class="pre">DllCanUnloadNow()</span></tt>, <tt class="docutils literal"><span class="pre">DllGetClassObject(rclsid,</span> <span class="pre">riid,</span> <span class="pre">ppv)</span></tt> (Windows only)</p> + <blockquote> + Functions used in COM servers.</blockquote> <p><tt class="docutils literal"><span class="pre">WinError(code=None,</span> <span class="pre">descr=None)</span></tt></p> ! <blockquote> ! <p>XXX This is probably the worst named thing in ctypes!</p> ! <p>This function creates a WindowsError instance. If <tt class="docutils literal"><span class="pre">code</span></tt> is not ! specified, GetLastError() is called to determine the error code. ! If <tt class="docutils literal"><span class="pre">descr</span></tt> is not specified, <tt class="docutils literal"><span class="pre">FormatError</span></tt> is called to get a ! textual description of the error.</p> ! </blockquote> ! <p><tt class="docutils literal"><span class="pre">FormatError([code])</span></tt> (Windows only)</p> ! <blockquote> ! Return a textual description of the error code, or the last error ! code set by Windows.</blockquote> <p><tt class="docutils literal"><span class="pre">GetLastError()</span></tt> (Windows only)</p> + <blockquote> + Return the last error code set by Windows.</blockquote> <div class="section"> ! <h2><a class="toc-backref" href="#id18" id="deprecated-functions" name="deprecated-functions">Deprecated functions</a></h2> <p><tt class="docutils literal"><span class="pre">c_buffer(init,</span> <span class="pre">size=None)</span></tt></p> <blockquote> Index: simple_types.txt =================================================================== RCS file: /cvsroot/ctypes/ctypes/docs/manual/Attic/simple_types.txt,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -C2 -d -r1.1.2.2 -r1.1.2.3 *** simple_types.txt 9 Feb 2006 20:26:34 -0000 1.1.2.2 --- simple_types.txt 13 Feb 2006 21:39:24 -0000 1.1.2.3 *************** *** 106,110 **** Integer types are ``c_byte``, ``c_short``, ``c_int``, ``c_long``, ! ``c_longlong`` and there unsigned variants ``c_ubyte``, ``c_ushort``, ``c_uint``, ``c_ulong`` and ``c_longlong``, floating point types are ``c_float`` and ``c_double``. --- 106,110 ---- Integer types are ``c_byte``, ``c_short``, ``c_int``, ``c_long``, ! ``c_longlong`` and their unsigned variants ``c_ubyte``, ``c_ushort``, ``c_uint``, ``c_ulong`` and ``c_longlong``, floating point types are ``c_float`` and ``c_double``. |
From: Thomas H. <th...@us...> - 2006-02-13 17:40:45
|
Update of /cvsroot/ctypes/ctypes/comtypes/client In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16548 Modified Files: Tag: branch_1_0 dynamic.py __init__.py Log Message: Fixes for windows ce. Index: dynamic.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/client/Attic/dynamic.py,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -C2 -d -r1.1.2.2 -r1.1.2.3 *** dynamic.py 11 Feb 2006 11:23:25 -0000 1.1.2.2 --- dynamic.py 13 Feb 2006 17:40:36 -0000 1.1.2.3 *************** *** 32,35 **** --- 32,39 ---- return item + def QueryInterface(self, *args): + "QueryInterface is forwarded to the real com object." + return self._comobj.QueryInterface(*args) + def __getattr__(self, name): ## tc = self._comobj.GetTypeInfo(0).QueryInterface(comtypes.typeinfo.ITypeComp) Index: __init__.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/client/Attic/__init__.py,v retrieving revision 1.1.2.12 retrieving revision 1.1.2.13 diff -C2 -d -r1.1.2.12 -r1.1.2.13 *** __init__.py 11 Feb 2006 11:23:25 -0000 1.1.2.12 --- __init__.py 13 Feb 2006 17:40:36 -0000 1.1.2.13 *************** *** 217,220 **** --- 217,226 ---- return mod + def wrap_outparam(punk): + logger.info("wrap_outparam(%s)", punk) + if punk.__com_interface__ == comtypes.automation.IDispatch: + return wrap(punk) + return punk + # XXX rename this! def wrap(punk): *************** *** 253,285 **** try: pdisp = punk.QueryInterface(comtypes.automation.IDispatch) ! if pdisp.GetTypeInfoCount() == 0: ! # no further chance to find typeinfo, and IDispatch is ! # more useful than IUnknown. ! logger.info("IDispatch without typeinfo, using dynamic") ! return comtypes.client.dynamic.Dispatch(pdisp) ! logger.info("IDispatch with typeinfo") tinfo = pdisp.GetTypeInfo(0) except comtypes.COMError: ! logger.info("Without typeinfo, using dynamic") ! return comtypes.client.dynamic.Dispatch(punk) try: punk.QueryInterface(comtypes.IUnknown, tinfo.GetTypeAttr().guid) except comtypes.COMError: logger.info("Does not seem to implement default interface from typeinfo, using dynamic") - ## itf_name = tinfo.GetDocumentation(-1)[0] # interface name - ## print - ## print tinfo.GetTypeAttr() - ## tlib = tinfo.GetContainingTypeLib()[0] - ## ta = tinfo.GetTypeAttr() - ## for i in range(ta.cFuncs): - ## fd = tinfo.GetFuncDesc(i) - ## print fd, tinfo.GetDocumentation(fd.memid) - ## for i in range(ta.cVars): - ## vd = tinfo.GetVarDesc(i) - ## print vd, tinfo.GetDocumentation(vd.memid) - ## for i in range(ta.cImplTypes): - ## vd = tinfo.GetImplTypeFlags(i) - ## print vd#, tinfo.GetDocumentation(vd.memid) - ## print return comtypes.client.dynamic.Dispatch(punk) --- 259,275 ---- try: pdisp = punk.QueryInterface(comtypes.automation.IDispatch) ! except comtypes.COMError: ! logger.info("No Dispatch interface: %s", punk) ! return punk ! try: tinfo = pdisp.GetTypeInfo(0) except comtypes.COMError: ! pdisp = comtypes.client.dynamic.Dispatch(pdisp) ! logger.info("IDispatch.GetTypeInfo(0) failed: %s" % pdisp) ! return pdisp try: punk.QueryInterface(comtypes.IUnknown, tinfo.GetTypeAttr().guid) except comtypes.COMError: logger.info("Does not seem to implement default interface from typeinfo, using dynamic") return comtypes.client.dynamic.Dispatch(punk) *************** *** 309,313 **** # Should we do this for POINTER(IUnknown) also? ! ctypes.POINTER(comtypes.automation.IDispatch).__ctypes_from_outparam__ = wrap # XXX move into comtypes --- 299,303 ---- # Should we do this for POINTER(IUnknown) also? ! ctypes.POINTER(comtypes.automation.IDispatch).__ctypes_from_outparam__ = wrap_outparam # XXX move into comtypes *************** *** 474,477 **** --- 464,469 ---- sourceinterface=None): # the event interface we want clsid = comtypes.GUID.from_progid(progid) + if interface is None: + interface = getattr(progid, "_com_interfaces_", [None])[0] obj = comtypes.GetActiveObject(clsid, interface=interface) return _manage(obj, clsid, *************** *** 515,518 **** --- 507,512 ---- clsid = comtypes.GUID.from_progid(progid) logger.debug("%s -> %s", progid, clsid) + if interface is None: + interface = getattr(progid, "_com_interfaces_", [None])[0] if machine is None: logger.debug("CoCreateInstance(%s, clsctx=%s, interface=%s)", |
From: Thomas H. <th...@us...> - 2006-02-11 11:25:39
|
Update of /cvsroot/ctypes/ctypes/comtypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15787 Modified Files: Tag: branch_1_0 ChangeLog Log Message: Merge in changes from the upstream version. Index: ChangeLog =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/Attic/ChangeLog,v retrieving revision 1.1.2.5 retrieving revision 1.1.2.6 diff -C2 -d -r1.1.2.5 -r1.1.2.6 *** ChangeLog 20 Oct 2005 17:27:42 -0000 1.1.2.5 --- ChangeLog 11 Feb 2006 11:25:23 -0000 1.1.2.6 *************** *** 1,2 **** --- 1,7 ---- + 2006-02-11 Thomas Heller <th...@py...> + + * Merged in lots of changes from the upstream version. Started + localserver support. + 2005-10-20 Thomas Heller <th...@py...> |
From: Thomas H. <th...@us...> - 2006-02-11 11:24:15
|
Update of /cvsroot/ctypes/ctypes/comtypes/server In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15351 Added Files: Tag: branch_1_0 localserver.py Log Message: Merge in changes from the upstream version. --- NEW FILE: localserver.py --- from ctypes import * import comtypes from comtypes.hresult import * from comtypes.server import IClassFactory import logging import Queue logger = logging.getLogger(__name__) _debug = logger.debug _critical = logger.critical REGCLS_SINGLEUSE = 0 # class object only generates one instance REGCLS_MULTIPLEUSE = 1 # same class object genereates multiple inst. REGCLS_MULTI_SEPARATE = 2 # multiple use, but separate control over each REGCLS_SUSPENDED = 4 # register it as suspended, will be activated REGCLS_SURROGATE = 8 # must be used when a surrogate process def run(classes): assert len(classes) == 1 cls = classes[0] factory = ClassFactory(cls) factory._run() g_cLocks = 0 # XXX We should use Interlocked access class ClassFactory(comtypes.COMObject): _com_interfaces_ = [IClassFactory] _locks = 0 _queue = None regcls = REGCLS_SINGLEUSE def __init__(self, cls): super(ClassFactory, self).__init__() cls._factory = self self._cls = cls self._register_class() def _register_class(self): cookie = c_ulong() ptr = self._com_pointers_[comtypes.IUnknown._iid_] oledll.ole32.CoRegisterClassObject(byref(comtypes.GUID(self._cls._reg_clsid_)), ptr, comtypes.CLSCTX_LOCAL_SERVER, self.regcls, byref(cookie)) self.cookie = cookie def CreateInstance(self, this, punkOuter, riid, ppv): _debug("ClassFactory.CreateInstance(%s)", riid[0]) self.LockServer(None, True) obj = self._cls() result = obj.IUnknown_QueryInterface(None, riid, ppv) _debug("CreateInstance() -> %s", result) return result def LockServer(self, this, fLock): global g_cLocks if fLock: g_cLocks += 1 else: g_cLocks -= 1 _debug("LockServer -> %d", g_cLocks) if g_cLocks == 0: if self._queue is not None: self._queue.put(42) else: windll.user32.PostQuitMessage(0) return S_OK def _run(self): result = windll.ole32.CoInitialize(None) if RPC_E_CHANGED_MODE == result: # we're running in MTA: no message pump needed _debug("Server running in MTA") self.run_mta() else: # we're running in STA: need a message pump _debug("Server running in STA") if result >= 0: # we need a matching CoUninitialize() call for a successful CoInitialize(). windll.ole32.CoUninitialize() self.run_sta() def run_sta(self): "Can be overridden in subclasses, to install a custom message pump." pump_messages() def run_mta(self): "Can be overridden in subclasses." self._queue = Queue.Queue() self._queue.get() def pump_messages(): from ctypes.wintypes import MSG user32 = windll.user32 msg = MSG() while user32.GetMessageA(byref(msg), 0, 0, 0): user32.TranslateMessage(byref(msg)) user32.DispatchMessageA(byref(msg)) |
From: Thomas H. <th...@us...> - 2006-02-11 11:23:54
|
Update of /cvsroot/ctypes/ctypes/comtypes/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15153 Modified Files: Tag: branch_1_0 test_safearray.py test_dyndispatch.py Log Message: Merge in changes from the upstream version. Index: test_dyndispatch.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/test/Attic/test_dyndispatch.py,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -C2 -d -r1.1.2.1 -r1.1.2.2 *** test_dyndispatch.py 2 Jan 2006 19:11:43 -0000 1.1.2.1 --- test_dyndispatch.py 11 Feb 2006 11:23:38 -0000 1.1.2.2 *************** *** 3,7 **** from comtypes.client import CreateObject from comtypes.client.dynamic import _Dispatch - import logging class Test(unittest.TestCase): --- 3,6 ---- Index: test_safearray.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/test/Attic/test_safearray.py,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -C2 -d -r1.1.2.2 -r1.1.2.3 *** test_safearray.py 8 Feb 2006 07:11:02 -0000 1.1.2.2 --- test_safearray.py 11 Feb 2006 11:23:38 -0000 1.1.2.3 *************** *** 24,26 **** if __name__ == "__main__": ! ut.main() --- 24,26 ---- if __name__ == "__main__": ! unittest.main() |
From: Thomas H. <th...@us...> - 2006-02-11 11:23:48
|
Update of /cvsroot/ctypes/ctypes/comtypes/server In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15124 Modified Files: Tag: branch_1_0 register.py Log Message: Merge in changes from the upstream version. Index: register.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/server/Attic/register.py,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -C2 -d -r1.1.2.1 -r1.1.2.2 *** register.py 2 Jan 2006 19:11:37 -0000 1.1.2.1 --- register.py 11 Feb 2006 11:23:32 -0000 1.1.2.2 *************** *** 285,290 **** usage = """Usage: %s [-regserver] [-unregserver] [-nodebug] [-f logformat] [-l loggername=level]""" % sys.argv[0] opts, args = w_getopt.w_getopt(sys.argv[1:], ! ## "regserver unregserver embedding l: f: nodebug") ! "regserver unregserver l: f: nodebug") if not opts: sys.stderr.write(usage) --- 285,289 ---- usage = """Usage: %s [-regserver] [-unregserver] [-nodebug] [-f logformat] [-l loggername=level]""" % sys.argv[0] opts, args = w_getopt.w_getopt(sys.argv[1:], ! "regserver unregserver embedding l: f: nodebug") if not opts: sys.stderr.write(usage) *************** *** 294,298 **** format = None nodebug = False ! for option, value in opts: if option == "regserver": --- 293,297 ---- format = None nodebug = False ! runit = False for option, value in opts: if option == "regserver": *************** *** 302,310 **** for cls in classes: unregister(cls) ! ## elif option == "embedding": ! ## if len(classes) == 1: ! ## localserver(classes[0]) ! ## else: ! ## raise ValueError, "more than one class not yet supported" elif option == "f": format = value --- 301,306 ---- for cls in classes: unregister(cls) ! elif option == "embedding": ! runit = True elif option == "f": format = value *************** *** 320,324 **** for cls in classes: Registrar().nodebug(cls) ! return 1 # we have done something --- 316,323 ---- for cls in classes: Registrar().nodebug(cls) ! ! if runit: ! import comtypes.server.localserver ! comtypes.server.localserver.run(classes) return 1 # we have done something |
From: Thomas H. <th...@us...> - 2006-02-11 11:23:37
|
Update of /cvsroot/ctypes/ctypes/comtypes/client In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15102 Modified Files: Tag: branch_1_0 dynamic.py __init__.py Log Message: Merge in changes from the upstream version. Index: dynamic.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/client/Attic/dynamic.py,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -C2 -d -r1.1.2.1 -r1.1.2.2 *** dynamic.py 2 Jan 2006 19:11:32 -0000 1.1.2.1 --- dynamic.py 11 Feb 2006 11:23:25 -0000 1.1.2.2 *************** *** 1,4 **** --- 1,5 ---- import ctypes import comtypes.automation + import comtypes.typeinfo import comtypes.client *************** *** 18,22 **** def __enum(self): ! e = self._comobj.Invoke(-4) return e.QueryInterface(comtypes.automation.IEnumVARIANT) --- 19,23 ---- def __enum(self): ! e = self._comobj.Invoke(-4) # DISPID_NEWENUM return e.QueryInterface(comtypes.automation.IEnumVARIANT) *************** *** 31,34 **** --- 32,43 ---- return item + def __getattr__(self, name): + ## tc = self._comobj.GetTypeInfo(0).QueryInterface(comtypes.typeinfo.ITypeComp) + ## dispid = tc.Bind(name)[1].memid + dispid = self._comobj.GetIDsOfNames(name)[0] + flags = comtypes.automation.DISPATCH_PROPERTYGET + return self._comobj.Invoke(dispid, + _invkind=flags) + def __iter__(self): return _Collection(self.__enum()) Index: __init__.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/client/Attic/__init__.py,v retrieving revision 1.1.2.11 retrieving revision 1.1.2.12 diff -C2 -d -r1.1.2.11 -r1.1.2.12 *** __init__.py 2 Jan 2006 19:11:32 -0000 1.1.2.11 --- __init__.py 11 Feb 2006 11:23:25 -0000 1.1.2.12 *************** *** 267,270 **** --- 267,285 ---- except comtypes.COMError: logger.info("Does not seem to implement default interface from typeinfo, using dynamic") + ## itf_name = tinfo.GetDocumentation(-1)[0] # interface name + ## print + ## print tinfo.GetTypeAttr() + ## tlib = tinfo.GetContainingTypeLib()[0] + ## ta = tinfo.GetTypeAttr() + ## for i in range(ta.cFuncs): + ## fd = tinfo.GetFuncDesc(i) + ## print fd, tinfo.GetDocumentation(fd.memid) + ## for i in range(ta.cVars): + ## vd = tinfo.GetVarDesc(i) + ## print vd, tinfo.GetDocumentation(vd.memid) + ## for i in range(ta.cImplTypes): + ## vd = tinfo.GetImplTypeFlags(i) + ## print vd#, tinfo.GetDocumentation(vd.memid) + ## print return comtypes.client.dynamic.Dispatch(punk) |
From: Thomas H. <th...@us...> - 2006-02-11 11:23:27
|
Update of /cvsroot/ctypes/ctypes/comtypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15072 Modified Files: Tag: branch_1_0 typeinfo.py safearray.py hresult.py errorinfo.py Log Message: Merge in changes from the upstream version. Index: typeinfo.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/typeinfo.py,v retrieving revision 1.3.2.13 retrieving revision 1.3.2.14 diff -C2 -d -r1.3.2.13 -r1.3.2.14 *** typeinfo.py 13 Jan 2006 09:20:08 -0000 1.3.2.13 --- typeinfo.py 11 Feb 2006 11:23:18 -0000 1.3.2.14 *************** *** 380,404 **** return tlib ! if hasattr(_oleaut32, "LoadTypeLibEx"): ! def LoadTypeLibEx(szFile, regkind=REGKIND_NONE): ! "Load, and optionally register a type library file" ! ptl = POINTER(ITypeLib)() ! _oleaut32.LoadTypeLibEx(c_wchar_p(szFile), regkind, byref(ptl)) ! return ptl ! else: ! def LoadTypeLibEx(szFile, regkind=REGKIND_NONE): ! # Win CE: emulate ! if regkind == REGKIND_NONE: ! if not "\\" in szFile and not "/" in szFile: ! szFile = ".\\" + szFile ! return LoadTypeLib(szFile) ! elif regkind == REGKIND_REGISTER: ! result = LoadTypeLib(szFile) ! RegisterTypeLib(szFile) ! return result ! elif regkind == REGKIND_DEFAULT: ! return LoadTypeLib(szFile) ! else: ! raise ValueError("unknown regkind %s" % regkind) def LoadTypeLib(szFile): --- 380,388 ---- return tlib ! def LoadTypeLibEx(szFile, regkind=REGKIND_NONE): ! "Load, and optionally register a type library file" ! ptl = POINTER(ITypeLib)() ! _oleaut32.LoadTypeLibEx(c_wchar_p(szFile), regkind, byref(ptl)) ! return ptl def LoadTypeLib(szFile): Index: hresult.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/Attic/hresult.py,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -C2 -d -r1.1.2.2 -r1.1.2.3 *** hresult.py 2 Jan 2006 19:11:25 -0000 1.1.2.2 --- hresult.py 11 Feb 2006 11:23:18 -0000 1.1.2.3 *************** *** 49,50 **** --- 49,52 ---- DISP_E_MEMBERNOTFOUND = -2147352573 DISP_E_UNKNOWNINTERFACE = -2147352575 + + RPC_E_CHANGED_MODE = -2147417850 # 0x80010106 Index: errorinfo.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/Attic/errorinfo.py,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -C2 -d -r1.1.2.1 -r1.1.2.2 *** errorinfo.py 2 Jan 2006 19:11:25 -0000 1.1.2.1 --- errorinfo.py 11 Feb 2006 11:23:18 -0000 1.1.2.2 *************** *** 87,91 **** def ReportException(hresult, iid, clsid=None, helpfile=None, helpcontext=None): """Report a COM exception. Returns the passed in hresult value.""" ! text = u"%s: %s" % sys.exc_info()[:2] return ReportError(text, iid, clsid=clsid, helpfile=helpfile, helpcontext=helpcontext) --- 87,91 ---- def ReportException(hresult, iid, clsid=None, helpfile=None, helpcontext=None): """Report a COM exception. Returns the passed in hresult value.""" ! text = "%s: %s" % sys.exc_info()[:2] return ReportError(text, iid, clsid=clsid, helpfile=helpfile, helpcontext=helpcontext) Index: safearray.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/Attic/safearray.py,v retrieving revision 1.1.2.5 retrieving revision 1.1.2.6 diff -C2 -d -r1.1.2.5 -r1.1.2.6 *** safearray.py 2 Jan 2006 19:11:25 -0000 1.1.2.5 --- safearray.py 11 Feb 2006 11:23:18 -0000 1.1.2.6 *************** *** 38,41 **** --- 38,50 ---- ix.value += 1 + # XXX + # Seems to work, but not tested enough. + ##@ classmethod + ##def from_param(cls, arg): + ## if not isinstance(arg, cls._type_): + ## arg = SafeArray_FromSequence(arg) + ## return byref(arg) + ##POINTER(POINTER(SAFEARRAY)).from_param = from_param + # XXX For whatever reason, oleaut32.SafeArrayCreateVector does not seem to work correctly # on the Win2k system I have. The result cannot be passed successfully to SafeArrayGetVartype, |
From: Thomas H. <th...@us...> - 2006-02-10 19:35:27
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2644 Modified Files: Tag: branch_1_0 test-cf.py Log Message: Index: test-cf.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/Attic/test-cf.py,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -C2 -d -r1.1.2.2 -r1.1.2.3 *** test-cf.py 8 Feb 2006 20:43:39 -0000 1.1.2.2 --- test-cf.py 10 Feb 2006 19:35:16 -0000 1.1.2.3 *************** *** 11,15 **** ("x86-linux1", "/usr/bin/python -u"), - # Permission denied ("x86-linux2", "/usr/bin/python -u"), --- 11,14 ---- *************** *** 46,52 **** print "*" * 20, hostname, "*" * 20 if len(sys.argv) > 1: ! cmd = "cd ~/ctypes-0.9.9.1; %s setup.py %s" % (python, " ".join(sys.argv[1:])) else: ! cmd = "cd ~/ctypes-0.9.9.1; %s setup.py -q build_ext -f test -v " % python print cmd ret = os.system('ssh -l theller cf-shell.sf.net "ssh %s \'%s\'"' % (hostname, cmd)) --- 45,51 ---- print "*" * 20, hostname, "*" * 20 if len(sys.argv) > 1: ! cmd = "cd ~/ctypes; %s setup.py %s" % (python, " ".join(sys.argv[1:])) else: ! cmd = "cd ~/ctypes; %s setup.py -q build_ext -f test -v " % python print cmd ret = os.system('ssh -l theller cf-shell.sf.net "ssh %s \'%s\'"' % (hostname, cmd)) |
From: Thomas H. <th...@us...> - 2006-02-10 19:32:22
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1449 Modified Files: Tag: branch_1_0 ChangeLog Log Message: *** empty log message *** Index: ChangeLog =================================================================== RCS file: /cvsroot/ctypes/ctypes/ChangeLog,v retrieving revision 1.86.2.38 retrieving revision 1.86.2.39 diff -C2 -d -r1.86.2.38 -r1.86.2.39 *** ChangeLog 9 Feb 2006 21:03:50 -0000 1.86.2.38 --- ChangeLog 10 Feb 2006 19:32:09 -0000 1.86.2.39 *************** *** 1,2 **** --- 1,9 ---- + 2006-02-10 Thomas Heller <th...@py...> + + * string_at and wstring_at are now implemented in the same way as + memmove and memset. + + * Fixed the wrong return type of memmove. + 2006-02-09 Thomas Heller <th...@py...> |
From: Thomas H. <th...@us...> - 2006-02-10 19:05:52
|
Update of /cvsroot/ctypes/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20854 Modified Files: Tag: branch_1_0 __init__.py Log Message: OOPS: memmove return void *, not size_t. Index: __init__.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/__init__.py,v retrieving revision 1.61.2.31 retrieving revision 1.61.2.32 diff -C2 -d -r1.61.2.31 -r1.61.2.32 *** __init__.py 10 Feb 2006 18:35:24 -0000 1.61.2.31 --- __init__.py 10 Feb 2006 19:05:41 -0000 1.61.2.32 *************** *** 408,412 **** ## void *memmove(void *, const void *, size_t); ! memmove = CFUNCTYPE(c_size_t, c_void_p, c_void_p, c_size_t)(_memmove_addr) ## void *memset(void *, int, size_t) --- 408,412 ---- ## void *memmove(void *, const void *, size_t); ! memmove = CFUNCTYPE(c_void_p, c_void_p, c_void_p, c_size_t)(_memmove_addr) ## void *memset(void *, int, size_t) |
From: Thomas H. <th...@us...> - 2006-02-10 18:35:40
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7089 Modified Files: Tag: branch_1_0 callproc.c _ctypes.c Log Message: wstring_at is now also a foreign function, exported from the _ctypes extension. Index: callproc.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/callproc.c,v retrieving revision 1.127.2.25 retrieving revision 1.127.2.26 diff -C2 -d -r1.127.2.25 -r1.127.2.26 *** callproc.c 10 Feb 2006 18:27:30 -0000 1.127.2.25 --- callproc.c 10 Feb 2006 18:35:32 -0000 1.127.2.26 *************** *** 1479,1515 **** } - #ifdef CTYPES_UNICODE - static char wstring_at_doc[] = - "wstring_at(addr[, size]) -> unicode string\n\ - \n\ - Return the wide string at addr.\n"; - - static PyObject * - wstring_at(PyObject *self, PyObject *args) - { - PyObject *result = NULL; - PyObject *src; - struct argument a_arg; - int size; - - if (!PyArg_ParseTuple(args, "O|i:wstring_at", &src, &size)) - return NULL; - memset(&a_arg, 0, sizeof(struct argument)); - if (-1 == ConvParam(src, 1, &a_arg)) - return NULL; - if (PyTuple_GET_SIZE(args) == 1) - result = PyUnicode_FromWideChar(a_arg.value.p, wcslen(a_arg.value.p)); - else - result = PyUnicode_FromWideChar(a_arg.value.p, size); - Py_XDECREF(a_arg.keep); - return result; - } - #endif - PyMethodDef module_methods[] = { {"cast", cast, METH_VARARGS, cast_doc}, #ifdef CTYPES_UNICODE - {"wstring_at", wstring_at, METH_VARARGS, wstring_at_doc}, {"set_conversion_mode", set_conversion_mode, METH_VARARGS, set_conversion_mode_doc}, #endif --- 1479,1486 ---- Index: _ctypes.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes.c,v retrieving revision 1.226.2.49 retrieving revision 1.226.2.50 diff -C2 -d -r1.226.2.49 -r1.226.2.50 *** _ctypes.c 10 Feb 2006 18:27:30 -0000 1.226.2.49 --- _ctypes.c 10 Feb 2006 18:35:32 -0000 1.226.2.50 *************** *** 4334,4337 **** --- 4334,4348 ---- } + + #ifdef CTYPES_UNICODE + static PyObject * + wstring_at(const wchar_t *ptr, int size) + { + if (size == 0) + size = wcslen(ptr); + return PyUnicode_FromWideChar(ptr, size); + } + #endif + DL_EXPORT(void) init_ctypes(void) *************** *** 4458,4461 **** --- 4469,4475 ---- PyModule_AddObject(m, "_memset_addr", PyLong_FromVoidPtr(memset)); PyModule_AddObject(m, "_string_at_addr", PyLong_FromVoidPtr(string_at)); + #ifdef CTYPES_UNICODE + PyModule_AddObject(m, "_wstring_at_addr", PyLong_FromVoidPtr(wstring_at)); + #endif #ifdef RTLD_LOCAL |