ctypes-commit Mailing List for ctypes (Page 55)
Brought to you by:
theller
You can subscribe to this list here.
2004 |
Jan
|
Feb
|
Mar
|
Apr
(8) |
May
(90) |
Jun
(143) |
Jul
(106) |
Aug
(94) |
Sep
(84) |
Oct
(163) |
Nov
(60) |
Dec
(58) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2005 |
Jan
(128) |
Feb
(79) |
Mar
(227) |
Apr
(192) |
May
(179) |
Jun
(41) |
Jul
(53) |
Aug
(103) |
Sep
(28) |
Oct
(38) |
Nov
(81) |
Dec
(17) |
2006 |
Jan
(184) |
Feb
(111) |
Mar
(188) |
Apr
(67) |
May
(58) |
Jun
(123) |
Jul
(73) |
Aug
|
Sep
|
Oct
(1) |
Nov
|
Dec
|
From: Thomas H. <th...@us...> - 2005-04-29 19:04:51
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1770 Modified Files: Tag: branch_1_0 ChangeLog Log Message: Forgot to check this in. Index: ChangeLog =================================================================== RCS file: /cvsroot/ctypes/ctypes/ChangeLog,v retrieving revision 1.86.2.4 retrieving revision 1.86.2.5 diff -C2 -d -r1.86.2.4 -r1.86.2.5 *** ChangeLog 19 Apr 2005 08:58:36 -0000 1.86.2.4 --- ChangeLog 29 Apr 2005 19:04:37 -0000 1.86.2.5 *************** *** 1,2 **** --- 1,8 ---- + 2005-04-22 Thomas Heller <th...@py...> + + * Committed a patch from Andreas Degert which allows to call + vararg functions on x86_64b platforms (although not officially + supported by libffi). + 2005-04-19 Thomas Heller <th...@py...> |
From: Thomas H. <th...@us...> - 2005-04-29 11:58:05
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26477 Modified Files: Tag: branch_1_0 _ctypes.c Log Message: Prevent a crash in an exception when a parameter name is not known. We need better error messages for this anyway. Index: _ctypes.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes.c,v retrieving revision 1.226.2.4 retrieving revision 1.226.2.5 diff -C2 -d -r1.226.2.4 -r1.226.2.5 *** _ctypes.c 14 Apr 2005 18:47:36 -0000 1.226.2.4 --- _ctypes.c 29 Apr 2005 11:57:46 -0000 1.226.2.5 *************** *** 2597,2602 **** return defval; } ! PyErr_Format(PyExc_TypeError, ! "required argument '%s' missing", name); return NULL; } --- 2597,2607 ---- return defval; } ! /* we can't currently emit a better error message */ ! if (name) ! PyErr_Format(PyExc_TypeError, ! "required argument '%s' missing", name); ! else ! PyErr_Format(PyExc_TypeError, ! "not enough arguments"); return NULL; } |
From: Andreas D. <ad...@us...> - 2005-04-29 09:46:55
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18204 Modified Files: ChangeLog Log Message: Index: ChangeLog =================================================================== RCS file: /cvsroot/ctypes/ctypes/ChangeLog,v retrieving revision 1.95 retrieving revision 1.96 diff -C2 -d -r1.95 -r1.96 *** ChangeLog 28 Apr 2005 14:58:18 -0000 1.95 --- ChangeLog 29 Apr 2005 09:46:35 -0000 1.96 *************** *** 1,2 **** --- 1,15 ---- + 2005-04-29 Andreas Degert <ad...@pa...> + + * ctypes/__init__.py: no .dll added to the name for Windows, fixes + for OS X, find() was meant to return a value. + + * ctypes/wrap/xml2py.py: added OS X specifics, move some code + around, fixed some bugs. + + * setup.py, source/callproc.c: made sources compile on OS X + + * ctypes/wrap/codegenerator.py: removed unused import types + (slipped on with one of the previous changes). + 2005-04-28 Andreas Degert <ad...@pa...> |
From: Andreas D. <ad...@us...> - 2005-04-29 09:46:32
|
Update of /cvsroot/ctypes/ctypes/ctypes/wrap In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17942/ctypes/wrap Modified Files: xml2py.py Log Message: added OS X specifics, move some code around, fixed some bugs. Index: xml2py.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/wrap/xml2py.py,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** xml2py.py 28 Apr 2005 17:40:35 -0000 1.4 --- xml2py.py 29 Apr 2005 09:46:14 -0000 1.5 *************** *** 4,15 **** from ctypes import CDLL, cast, c_void_p - # Hm, is it better to catch ImportError here, or should we protect this by - # if os.name == *posix" ? - try: - from _ctypes import dlname, dladdr - except ImportError: - # dlname and dladdr not available, hopefully also unneeded. - pass - try: set --- 4,7 ---- *************** *** 17,52 **** from sets import Set as set ! ################################################################ ! windows_dll_names = """\ ! imagehlp ! user32 ! kernel32 ! gdi32 ! advapi32 ! oleaut32 ! ole32 ! imm32 ! comdlg32 ! shell32 ! version ! winmm ! mpr ! winscard ! winspool.drv ! urlmon ! crypt32 ! cryptnet ! ws2_32 ! opengl32 ! glu32 ! mswsock ! msimg32 ! netapi32 ! rpcrt4""".split() ! ! ##msvcrt ! ##rpcndr ! ##ntdll ! def fatalerror(msg): "Print an error message and exit the program" --- 9,23 ---- from sets import Set as set ! def remove_dups(seq): ! "remove duplicate entries from a sequence and return a list" ! s = set() ! l = [] ! for i in seq: ! if i in s: ! continue ! s.add(i) ! l.append(i) ! return l ! def fatalerror(msg): "Print an error message and exit the program" *************** *** 54,58 **** sys.exit(1) - class LibraryDescBase(object): """Provides symbol lookup and attributes of a shared library. --- 25,28 ---- *************** *** 97,102 **** --- 67,75 ---- which() + """ + dllclass = LibraryDescBase + def __init__(self, names, searchpaths, verbose=False): """Loads the libraries *************** *** 106,110 **** verbose: give a verbose message in case of error """ ! pass def which(self, func): --- 79,88 ---- verbose: give a verbose message in case of error """ ! if not names: ! self.dlls = [] ! else: ! names = remove_dups(names) ! paths = self.findLibraryPaths(names, searchpaths, verbose) ! self.dlls = [self.dllclass(path) for path in paths] def which(self, func): *************** *** 114,120 **** --- 92,104 ---- raise NotImplementedError + def findLibraryPaths(self, names, searchpaths, verbose): + return names + if os.name == "posix": + if not sys.platform == "darwin": + from _ctypes import dlname, dladdr + class LibraryDescPosix(LibraryDescBase): *************** *** 126,131 **** def get_soname(self, path): ! import re, os ! cmd = "objdump -p -j .dynamic " + path res = re.search(r'\sSONAME\s+([^\s]+)', os.popen(cmd).read()) if not res: --- 110,114 ---- def get_soname(self, path): ! cmd = "objdump -p -j .dynamic 2>/dev/null " + path res = re.search(r'\sSONAME\s+([^\s]+)', os.popen(cmd).read()) if not res: *************** *** 135,139 **** def get_name_version(self, path): soname = self.get_soname(path) ! m = re.match(r'lib(?P<name>[^.]+)\.so(\.(?P<version>.*))?', soname) if not m: raise ValueError( --- 118,122 ---- def get_name_version(self, path): soname = self.get_soname(path) ! m = re.match(r'lib(?P<name>.+)\.so(\.(?P<version>.*))?', soname) if not m: raise ValueError( *************** *** 148,157 **** class LibraryListPosix(LibraryListBase): def __init__(self, names, searchpaths, verbose=False): ! if not names: ! self.dlls = [] ! else: ! paths = self.findLibraryPaths(names, searchpaths, verbose) ! self.dlls = [LibraryDescPosix(path) for path in paths] self.lookup_dlls = dict([(d.path, d) for d in self.dlls]) --- 131,138 ---- class LibraryListPosix(LibraryListBase): + dllclass = LibraryDescPosix + def __init__(self, names, searchpaths, verbose=False): ! LibraryListBase.__init__(self, names, searchpaths, verbose) self.lookup_dlls = dict([(d.path, d) for d in self.dlls]) *************** *** 217,220 **** --- 198,244 ---- LibraryList = LibraryListPosix + if os.name == "posix" and sys.platform == "darwin": + + class LibraryDescDarwin(LibraryDescPosix): + + def __init__(self, path): + LibraryDescPosix.__init__(self, path) + + def get_soname(self, path): + cmd = "otool -D 2>/dev/null " + path + res = re.match(r'.*:\n(.*)', os.popen(cmd).read()) + if not res: + raise ValueError("no soname found for shared lib '%s'" % path) + return res.group(1) + + def get_name_version(self, path): + soname = self.get_soname(path) + m = re.match(r'.*/lib(?P<name>.+)\.dylib', soname) + if not m: + raise ValueError( + "soname of form .../lib<name>.dylib expected, got '%s'" % soname) + return m.group('name'), '' + + def normalize_path(self, path): + return path + + + class LibraryListDarwin(LibraryListPosix): + + dllclass = LibraryDescDarwin + + def __init__(self, names, searchpaths, verbose=False): + LibraryListPosix.__init__(self, names, searchpaths, verbose) + + def which(self, func): + name = func.name + for dll in self.dlls: + f = dll.lookup(name) + if f is not None: + return dll + return None + + LibraryList = LibraryListDarwin + if os.name == "nt": *************** *** 262,267 **** class LibraryListNT(LibraryListBase): ! def __init__(self, names, searchpaths, verbose=False): ! self.dlls = [LibraryDescNT(name) for name in names] def which(self, func): --- 286,293 ---- class LibraryListNT(LibraryListBase): ! dllclass = LibraryDescNT ! ! def __init__(self, names, searchpaths, verbose=False): ! LibraryListNT.__init__(self, names, searchpaths, verbose) def which(self, func): *************** *** 274,289 **** LibraryList = LibraryListNT - def remove_dups(seq): - "remove duplicate entries from a sequence and return a list" - s = set() - l = [] - for i in seq: - if i in s: - continue - s.add(i) - l.append(i) - return l - def main(args=None): --- 300,337 ---- LibraryList = LibraryListNT + windows_dll_names = """\ + imagehlp + user32 + kernel32 + gdi32 + advapi32 + oleaut32 + ole32 + imm32 + comdlg32 + shell32 + version + winmm + mpr + winscard + winspool.drv + urlmon + crypt32 + cryptnet + ws2_32 + opengl32 + glu32 + mswsock + msimg32 + netapi32 + rpcrt4""".split() + + ##msvcrt + ##rpcndr + ##ntdll + + def windows_dlls(option, opt, value, parser): + parser.values.dlls.extend(windows_dll_names) def main(args=None): *************** *** 291,297 **** args = sys.argv - def windows_dlls(option, opt, value, parser): - parser.values.dlls.extend(windows_dll_names) - parser = OptionParser("usage: %prog xmlfile [options]") parser.add_option("-d", --- 339,342 ---- *************** *** 356,363 **** default=False) ! parser.add_option("-w", ! action="callback", ! callback=windows_dlls, ! help="add all standard windows dlls to the searched dlls list") parser.add_option("-m", --- 401,409 ---- default=False) ! if os.name == "nt": ! parser.add_option("-w", ! action="callback", ! callback=windows_dlls, ! help="add all standard windows dlls to the searched dlls list") parser.add_option("-m", *************** *** 384,388 **** ################################################################ ! dlls = LibraryList(remove_dups(options.dlls), options.searchpaths) known_symbols = {} --- 430,434 ---- ################################################################ ! dlls = LibraryList(options.dlls, options.searchpaths) known_symbols = {} |
From: Andreas D. <ad...@us...> - 2005-04-29 09:45:59
|
Update of /cvsroot/ctypes/ctypes/ctypes/wrap In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17627/ctypes/wrap Modified Files: codegenerator.py Log Message: removed unused import types (slipped on with one of the previous changes). Index: codegenerator.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/wrap/codegenerator.py,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** codegenerator.py 28 Apr 2005 17:10:16 -0000 1.11 --- codegenerator.py 29 Apr 2005 09:45:48 -0000 1.12 *************** *** 3,6 **** --- 3,10 ---- # $Log$ + # Revision 1.12 2005/04/29 09:45:48 adegert + # removed unused import types + # (slipped on with one of the previous changes). + # # Revision 1.11 2005/04/28 17:10:16 theller # There are items which don't have a location attribute. *************** *** 58,62 **** # ! import typedesc, sys, types try: --- 62,66 ---- # ! import typedesc, sys try: |
From: Andreas D. <ad...@us...> - 2005-04-29 09:45:34
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17429 Modified Files: setup.py Log Message: made sources compile on OS X Index: setup.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/setup.py,v retrieving revision 1.126 retrieving revision 1.127 diff -C2 -d -r1.126 -r1.127 *** setup.py 15 Apr 2005 12:54:23 -0000 1.126 --- setup.py 29 Apr 2005 09:45:24 -0000 1.127 *************** *** 404,407 **** --- 404,408 ---- extra_link_args.extend(['-read_only_relocs', 'warning']) include_dirs.append("source/darwin") + kw["define_macros"].append(("DLFCN_SIMPLE","1")) extensions = [Extension("_ctypes", |
From: Andreas D. <ad...@us...> - 2005-04-29 09:45:33
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17429/source Modified Files: callproc.c Log Message: made sources compile on OS X Index: callproc.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/callproc.c,v retrieving revision 1.154 retrieving revision 1.155 diff -C2 -d -r1.154 -r1.155 *** callproc.c 27 Apr 2005 16:40:47 -0000 1.154 --- callproc.c 29 Apr 2005 09:45:24 -0000 1.155 *************** *** 62,67 **** --- 62,69 ---- #else #include <dlfcn.h> + #ifndef DLFCN_SIMPLE #include <link.h> #endif + #endif #ifdef MS_WIN32 *************** *** 290,294 **** if (self->pffi_type == &ffi_type_pointer) { ! sprintf(buffer, "<cparam 'P' (%p)>", (long)self->value.p); } else --- 292,296 ---- if (self->pffi_type == &ffi_type_pointer) { ! sprintf(buffer, "<cparam 'P' (%p)>", self->value.p); } else *************** *** 916,919 **** --- 918,922 ---- #else + #ifndef DLFCN_SIMPLE static PyObject *py_dl_name(PyObject *self, PyObject *args) { *************** *** 942,945 **** --- 945,949 ---- return PyString_FromString(info.dli_fname); } + #endif static PyObject *py_dl_open(PyObject *self, PyObject *args) *************** *** 1312,1318 **** {"_check_HRESULT", check_hresult, METH_VARARGS}, #else ! {"dlopen", py_dl_open, METH_VARARGS, "dlopen a library"}, {"dlname", py_dl_name, METH_VARARGS, "file name from a handle"}, {"dladdr", py_dl_addr, METH_VARARGS, "file name from an address"}, {"dlclose", py_dl_close, METH_VARARGS, "dlclose a library"}, {"dlsym", py_dl_sym, METH_VARARGS, "find symbol in shared library"}, --- 1316,1324 ---- {"_check_HRESULT", check_hresult, METH_VARARGS}, #else ! #ifndef DLFCN_SIMPLE {"dlname", py_dl_name, METH_VARARGS, "file name from a handle"}, {"dladdr", py_dl_addr, METH_VARARGS, "file name from an address"}, + #endif + {"dlopen", py_dl_open, METH_VARARGS, "dlopen a library"}, {"dlclose", py_dl_close, METH_VARARGS, "dlclose a library"}, {"dlsym", py_dl_sym, METH_VARARGS, "find symbol in shared library"}, |
From: Andreas D. <ad...@us...> - 2005-04-29 09:44:38
|
Update of /cvsroot/ctypes/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16790/ctypes Modified Files: __init__.py Log Message: no .dll added to the name for Windows, fixes for OS X, find() was meant to return a value. Index: __init__.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/__init__.py,v retrieving revision 1.73 retrieving revision 1.74 diff -C2 -d -r1.73 -r1.74 *** __init__.py 27 Apr 2005 17:21:05 -0000 1.73 --- __init__.py 29 Apr 2005 09:44:25 -0000 1.74 *************** *** 423,427 **** def findLib_ld(name): expr = '/[^\(\)\s]*lib%s\.[^\(\)\s]*' % name ! res = re.search(expr, _os.popen('/sbin/ldconfig -p').read()) if not res: return None --- 423,427 ---- def findLib_ld(name): expr = '/[^\(\)\s]*lib%s\.[^\(\)\s]*' % name ! res = re.search(expr, _os.popen('/sbin/ldconfig -p 2>/dev/null').read()) if not res: return None *************** *** 429,436 **** def get_soname(f): ! cmd = "objdump -p -j .dynamic " + f res = re.search(r'\sSONAME\s+([^\s]+)', _os.popen(cmd).read()) if not res: ! return '??' return res.group(1) --- 429,436 ---- def get_soname(f): ! cmd = "objdump -p -j .dynamic 2>/dev/null " + f res = re.search(r'\sSONAME\s+([^\s]+)', _os.popen(cmd).read()) if not res: ! return f return res.group(1) *************** *** 462,468 **** --- 462,470 ---- def find(self, name): + # should loop over different known naming styles name = self._findLibrary(name) dll = self._dlltype(name) print "ctypes.find: %s" % name + return dll if _os.name == "posix" and sys.platform == "darwin": *************** *** 471,477 **** def LoadLibraryVersion(self, name, version=''): ! if version: ! version = '.' + version ! dll = self._dlltype("lib%s%s.dylib" % (name, version)) setattr(self, name, dll) return dll --- 473,481 ---- def LoadLibraryVersion(self, name, version=''): ! path = "lib%s.dylib" % name ! try: ! dll = self._dlltype(path) ! except OSError: ! dll = self._dlltype("/usr/lib/"+path) setattr(self, name, dll) return dll *************** *** 490,494 **** else: def _findLibrary(self, name): ! return "%s.dll" % name def LoadLibraryVersion(self, name, version=''): --- 494,498 ---- else: def _findLibrary(self, name): ! return name def LoadLibraryVersion(self, name, version=''): |
From: Thomas H. <th...@us...> - 2005-04-28 17:40:54
|
Update of /cvsroot/ctypes/ctypes/ctypes/wrap In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3102 Modified Files: xml2py.py Log Message: Don't complain when dlname and dladdr cannot be imported. They are probably unneeded. Remove msvcrt from the windows-dlls list, normally we don't want to wrap stuff in it. 'Fix' the get_name_version() and get_soname() methods for Windows. Index: xml2py.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/wrap/xml2py.py,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** xml2py.py 27 Apr 2005 17:04:53 -0000 1.3 --- xml2py.py 28 Apr 2005 17:40:35 -0000 1.4 *************** *** 3,7 **** import typedesc from ctypes import CDLL, cast, c_void_p ! from _ctypes import dlname, dladdr try: --- 3,14 ---- import typedesc from ctypes import CDLL, cast, c_void_p ! ! # Hm, is it better to catch ImportError here, or should we protect this by ! # if os.name == *posix" ? ! try: ! from _ctypes import dlname, dladdr ! except ImportError: ! # dlname and dladdr not available, hopefully also unneeded. ! pass try: *************** *** 34,42 **** glu32 mswsock - msvcrt msimg32 netapi32 rpcrt4""".split() ##rpcndr ##ntdll --- 41,49 ---- glu32 mswsock msimg32 netapi32 rpcrt4""".split() + ##msvcrt ##rpcndr ##ntdll *************** *** 220,230 **** def get_name_version(self, path): dllname = self.get_soname(path) ! m = re.match(r'(?P<name>[^.]+)\.dll(?P<version>)', dllname) ! if not m: ! raise ValueError( ! "dll of form <name>.dll expected, got '%s'" % dllname) ! return m.group('name'), m.group('version') class LibraryListNT(LibraryListBase): --- 227,262 ---- def get_name_version(self, path): + # There are no consistent naming conventions for dll + # versions on windows. Which is the reason for dllhell. + # + # Some patterns are: + # + # Append a D for the debug version (MSVCR71.DLL - MSVR71D.DLL) + # Version number part of the filename: MFC42.DLL - MFC71.DLL + # But: MSVCRT.DLL MSVCR71.DLL + # U suffix for unicode? MFC42.DLL MFC42U.DLL + # locale suffix: MFC71DEU.DLL + # + # Here are some more MFC71 versions from my system: + # MFC71.DLL + # MFC71CHS.DLL + # MFC71CHT.DLL + # MFC71D.DLL + # MFC71DEU.DLL + # MFC71ENU.DLL + # MFC71ESP.DLL + # MFC71FRA.DLL + # MFC71ITA.DLL + # MFC71JPN.DLL + # MFC71KOR.DLL + # MFC71U.DLL + # MFC71UD.DLL dllname = self.get_soname(path) ! return dllname, "" + def get_soname(self, path): + # Should it strip the extension, if '.dll'? + # Should it strip the directory part? Probably... + return os.path.basename(path) class LibraryListNT(LibraryListBase): |
From: Thomas H. <th...@us...> - 2005-04-28 17:10:30
|
Update of /cvsroot/ctypes/ctypes/ctypes/wrap In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17815 Modified Files: codegenerator.py Log Message: There are items which don't have a location attribute. Index: codegenerator.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/wrap/codegenerator.py,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** codegenerator.py 28 Apr 2005 14:58:17 -0000 1.10 --- codegenerator.py 28 Apr 2005 17:10:16 -0000 1.11 *************** *** 3,6 **** --- 3,9 ---- # $Log$ + # Revision 1.11 2005/04/28 17:10:16 theller + # There are items which don't have a location attribute. + # # Revision 1.10 2005/04/28 14:58:17 adegert # created class Argument and changed the *************** *** 652,657 **** def cmpitems(a, b): ! a = a.location ! b = b.location if a is None: return -1 if b is None: return 1 --- 655,660 ---- def cmpitems(a, b): ! a = getattr(a, "location", None) ! b = getattr(b, "location", None) if a is None: return -1 if b is None: return 1 |
From: Andreas D. <ad...@us...> - 2005-04-28 14:58:33
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15421 Modified Files: ChangeLog Log Message: created class Argument and changed the argument list from a list of types to a list of Argument instances. Use it to transport parameter names if supplied. (plus cleanup of item sorting.) Index: ChangeLog =================================================================== RCS file: /cvsroot/ctypes/ctypes/ChangeLog,v retrieving revision 1.94 retrieving revision 1.95 diff -C2 -d -r1.94 -r1.95 *** ChangeLog 28 Apr 2005 13:11:55 -0000 1.94 --- ChangeLog 28 Apr 2005 14:58:18 -0000 1.95 *************** *** 1,2 **** --- 1,10 ---- + 2005-04-28 Andreas Degert <ad...@pa...> + + * ctypes/wrap/codegenerator.py, ctypes/wrap/gccxmlparser.py, + ctypes/wrap/typedesc.py: created class Argument and changed the + argument list from a list of types to a list of Argument + instances. Use it to transport parameter names if supplied. + (plus cleanup of item sorting.) + 2005-04-27 Andreas Degert <ad...@pa...> |
From: Andreas D. <ad...@us...> - 2005-04-28 14:58:29
|
Update of /cvsroot/ctypes/ctypes/ctypes/wrap In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15421/ctypes/wrap Modified Files: typedesc.py gccxmlparser.py codegenerator.py Log Message: created class Argument and changed the argument list from a list of types to a list of Argument instances. Use it to transport parameter names if supplied. (plus cleanup of item sorting.) Index: typedesc.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/wrap/typedesc.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** typedesc.py 4 Feb 2005 17:01:24 -0000 1.1 --- typedesc.py 28 Apr 2005 14:58:17 -0000 1.2 *************** *** 5,12 **** --- 5,36 ---- from sets import Set as set + class Argument(object): + "a Parameter in the argument list of a callable (Function, Method, ...)" + def __init__(self, atype, name): + self.atype = atype + self.name = name + class _HasArgs(object): + + def __init__(self): + self.arguments = [] + def add_argument(self, arg): + assert isinstance(arg, Argument) self.arguments.append(arg) + def iterArgTypes(self): + for a in self.arguments: + yield a.atype + + def iterArgNames(self): + for a in self.arguments: + yield a.name + + def fixup_argtypes(self, typemap): + for a in self.arguments: + a.atype = typemap[a.atype] + + ################ *************** *** 35,42 **** location = None def __init__(self, name, returns, attributes, extern): self.name = name self.returns = returns self.attributes = attributes # dllimport, __stdcall__, __cdecl__ - self.arguments = [] self.extern = extern --- 59,66 ---- location = None def __init__(self, name, returns, attributes, extern): + _HasArgs.__init__(self) self.name = name self.returns = returns self.attributes = attributes # dllimport, __stdcall__, __cdecl__ self.extern = extern *************** *** 44,70 **** location = None def __init__(self, name): self.name = name - self.arguments = [] class OperatorFunction(_HasArgs): location = None def __init__(self, name, returns): self.name = name self.returns = returns - self.arguments = [] class FunctionType(_HasArgs): location = None def __init__(self, returns, attributes): self.returns = returns self.attributes = attributes - self.arguments = [] class Method(_HasArgs): location = None def __init__(self, name, returns): self.name = name self.returns = returns - self.arguments = [] class FundamentalType(object): --- 68,94 ---- location = None def __init__(self, name): + _HasArgs.__init__(self) self.name = name class OperatorFunction(_HasArgs): location = None def __init__(self, name, returns): + _HasArgs.__init__(self) self.name = name self.returns = returns class FunctionType(_HasArgs): location = None def __init__(self, returns, attributes): + _HasArgs.__init__(self) self.returns = returns self.attributes = attributes class Method(_HasArgs): location = None def __init__(self, name, returns): + _HasArgs.__init__(self) self.name = name self.returns = returns class FundamentalType(object): Index: codegenerator.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/wrap/codegenerator.py,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** codegenerator.py 27 Apr 2005 17:04:53 -0000 1.9 --- codegenerator.py 28 Apr 2005 14:58:17 -0000 1.10 *************** *** 3,6 **** --- 3,12 ---- # $Log$ + # Revision 1.10 2005/04/28 14:58:17 adegert + # created class Argument and changed the + # argument list from a list of types to a list of Argument + # instances. Use it to transport parameter names if supplied. + # (plus cleanup of item sorting.) + # # Revision 1.9 2005/04/27 17:04:53 adegert # * ctypes/wrap/codegenerator.py: sort the generated definitions *************** *** 49,53 **** # ! import typedesc, sys try: --- 55,59 ---- # ! import typedesc, sys, types try: *************** *** 57,60 **** --- 63,74 ---- try: + sorted + except NameError: + def sorted(seq, cmp): + seq = list(seq) + seq.sort(cmp) + return seq + + try: import cStringIO as StringIO except ImportError: *************** *** 259,263 **** return "%s * %s" % (self.type_name(t.typ, generate), int(t.max)+1) elif isinstance(t, typedesc.FunctionType): ! args = [self.type_name(x, generate) for x in [t.returns] + t.arguments] if "__stdcall__" in t.attributes: return "WINFUNCTYPE(%s)" % ", ".join(args) --- 273,277 ---- return "%s * %s" % (self.type_name(t.typ, generate), int(t.max)+1) elif isinstance(t, typedesc.FunctionType): ! args = [self.type_name(x, generate) for x in [t.returns] + list(t.iterArgTypes())] if "__stdcall__" in t.attributes: return "WINFUNCTYPE(%s)" % ", ".join(args) *************** *** 379,383 **** self._functiontypes += 1 self.generate(tp.returns) ! self.generate_all(tp.arguments) _pointertypes = 0 --- 393,397 ---- self._functiontypes += 1 self.generate(tp.returns) ! self.generate_all(tp.iterArgTypes()) _pointertypes = 0 *************** *** 443,447 **** methods.append(m) self.generate(m.returns) ! self.generate_all(m.arguments) elif type(m) is typedesc.Constructor: pass --- 457,461 ---- methods.append(m) self.generate(m.returns) ! self.generate_all(m.iterArgTypes()) elif type(m) is typedesc.Constructor: pass *************** *** 506,510 **** for m in methods: self.type_name(m.returns) ! for a in m.arguments: self.type_name(a) if "COMMETHOD" in self.known_symbols: --- 520,524 ---- for m in methods: self.type_name(m.returns) ! for a in m.iterArgTypes(): self.type_name(a) if "COMMETHOD" in self.known_symbols: *************** *** 527,531 **** self.type_name(m.returns), m.name) ! for a in m.arguments: print >> self.stream, \ " ( [], %s, )," % self.type_name(a) --- 541,545 ---- self.type_name(m.returns), m.name) ! for a in m.iterArgTypes(): print >> self.stream, \ " ( [], %s, )," % self.type_name(a) *************** *** 533,537 **** else: for m in methods: ! args = [self.type_name(a) for a in m.arguments] print >> self.stream, " STDMETHOD(%s, '%s', [%s])," % ( self.type_name(m.returns), --- 547,551 ---- else: for m in methods: ! args = [self.type_name(a) for a in m.iterArgTypes()] print >> self.stream, " STDMETHOD(%s, '%s', [%s])," % ( self.type_name(m.returns), *************** *** 577,582 **** self.loaded_dlls.add(dll) self.generate(func.returns) ! self.generate_all(func.arguments) ! args = [self.type_name(a) for a in func.arguments] if "__stdcall__" in func.attributes: cc = "stdcall" --- 591,596 ---- self.loaded_dlls.add(dll) self.generate(func.returns) ! self.generate_all(func.iterArgTypes()) ! args = [self.type_name(a) for a in func.iterArgTypes()] if "__stdcall__" in func.attributes: cc = "stdcall" *************** *** 588,592 **** print >> self.stream, "@ %s(%s, %s, [%s])" % \ (cc, self.type_name(func.returns), libname, ", ".join(args)) ! argnames = ["p%d" % i for i in range(1, 1+len(args))] # function definition print >> self.stream, "def %s(%s):" % (func.name, ", ".join(argnames)) --- 602,606 ---- print >> self.stream, "@ %s(%s, %s, [%s])" % \ (cc, self.type_name(func.returns), libname, ", ".join(args)) ! argnames = [a or "p%d" % (i+1) for i, a in enumerate(func.iterArgNames())] # function definition print >> self.stream, "def %s(%s):" % (func.name, ", ".join(argnames)) *************** *** 633,636 **** --- 647,654 ---- mth(item) + def generate_all(self, items): + for item in items: + self.generate(item) + def cmpitems(a, b): a = a.location *************** *** 641,651 **** cmpitems = staticmethod(cmpitems) - def generate_all(self, items): - if not isinstance(items, list): - items = list(items) - items.sort(self.cmpitems) - for item in items: - self.generate(item) - def generate_module(self, items): print >> self.imports, "from ctypes import *" --- 659,662 ---- *************** *** 655,659 **** loops += 1 self.more = set() ! self.generate_all(items) items |= self.more --- 666,670 ---- loops += 1 self.more = set() ! self.generate_all(sorted(items, self.cmpitems)) items |= self.more Index: gccxmlparser.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/wrap/gccxmlparser.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** gccxmlparser.py 11 Mar 2005 10:23:44 -0000 1.2 --- gccxmlparser.py 28 Apr 2005 14:58:17 -0000 1.3 *************** *** 185,189 **** def _fixup_Function(self, func): func.returns = self.all[func.returns] ! func.arguments = [self.all[a] for a in func.arguments] def FunctionType(self, attrs): --- 185,189 ---- def _fixup_Function(self, func): func.returns = self.all[func.returns] ! func.fixup_argtypes(self.all) def FunctionType(self, attrs): *************** *** 195,199 **** def _fixup_FunctionType(self, func): func.returns = self.all[func.returns] ! func.arguments = [self.all[a] for a in func.arguments] def OperatorFunction(self, attrs): --- 195,199 ---- def _fixup_FunctionType(self, func): func.returns = self.all[func.returns] ! func.fixup_argtypes(self.all) def OperatorFunction(self, attrs): *************** *** 220,230 **** def _fixup_Method(self, m): m.returns = self.all[m.returns] ! m.arguments = [self.all[a] for a in m.arguments] def Argument(self, attrs): - typ = attrs["type"] parent = self.context[-1] if parent is not None: ! parent.add_argument(typ) # name? # enumerations --- 220,229 ---- def _fixup_Method(self, m): m.returns = self.all[m.returns] ! m.fixup_argtypes(self.all) def Argument(self, attrs): parent = self.context[-1] if parent is not None: ! parent.add_argument(typedesc.Argument(attrs["type"], attrs.get("name"))) # enumerations |
From: Thomas H. <th...@us...> - 2005-04-28 13:12:07
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25379 Modified Files: ChangeLog Log Message: Forgot to commit this. Index: ChangeLog =================================================================== RCS file: /cvsroot/ctypes/ctypes/ChangeLog,v retrieving revision 1.93 retrieving revision 1.94 diff -C2 -d -r1.93 -r1.94 *** ChangeLog 27 Apr 2005 17:21:05 -0000 1.93 --- ChangeLog 28 Apr 2005 13:11:55 -0000 1.94 *************** *** 29,32 **** --- 29,38 ---- * source/callproc.c: added dlname and dladdr (on Posix systems). + 2005-04-22 Thomas Heller <th...@py...> + + * Committed a patch from Andreas Degert which allows to call + vararg functions on x86_64b platforms (although not officially + supported by libffi). + 2005-04-19 Thomas Heller <th...@py...> |
From: Andreas D. <ad...@us...> - 2005-04-27 17:21:20
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28080 Modified Files: ChangeLog Log Message: * ctypes/decorators.py: changed both decorators now, not only one.. Index: ChangeLog =================================================================== RCS file: /cvsroot/ctypes/ctypes/ChangeLog,v retrieving revision 1.92 retrieving revision 1.93 diff -C2 -d -r1.92 -r1.93 *** ChangeLog 27 Apr 2005 17:04:54 -0000 1.92 --- ChangeLog 27 Apr 2005 17:21:05 -0000 1.93 *************** *** 1,4 **** --- 1,7 ---- 2005-04-27 Andreas Degert <ad...@pa...> + * ctypes/decorators.py: changed both decorators now, not only + one.. + * ctypes/wrap/codegenerator.py: sort the generated definitions according to location in the source code. |
From: Andreas D. <ad...@us...> - 2005-04-27 17:21:18
|
Update of /cvsroot/ctypes/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28080/ctypes Modified Files: decorators.py __init__.py Log Message: * ctypes/decorators.py: changed both decorators now, not only one.. Index: decorators.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/decorators.py,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** decorators.py 27 Apr 2005 16:40:55 -0000 1.8 --- decorators.py 27 Apr 2005 17:21:04 -0000 1.9 *************** *** 77,81 **** restype - result type ! dll - name or instance of a dll argtypes - list of argument types logging - if this is True, the result of each function call --- 77,81 ---- restype - result type ! dll - name or instance of a dll/shared library argtypes - list of argument types logging - if this is True, the result of each function call *************** *** 83,87 **** """ def decorate(func): ! library = _get_library(dllname) api = ctypes.WINFUNCTYPE(restype, *argtypes)(func.func_name, library) func._api_ = api --- 83,90 ---- """ def decorate(func): ! if isinstance(dllname, basestring): ! library = _get_library(dllname) ! else: ! library = dllname api = ctypes.WINFUNCTYPE(restype, *argtypes)(func.func_name, library) func._api_ = api Index: __init__.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/__init__.py,v retrieving revision 1.72 retrieving revision 1.73 diff -C2 -d -r1.72 -r1.73 *** __init__.py 27 Apr 2005 16:40:55 -0000 1.72 --- __init__.py 27 Apr 2005 17:21:05 -0000 1.73 *************** *** 496,500 **** setattr(self, name, dll) return dll ! cdll = _DLLS(CDLL) --- 496,500 ---- setattr(self, name, dll) return dll ! cdll = _DLLS(CDLL) |
From: Andreas D. <ad...@us...> - 2005-04-27 17:05:04
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20158 Modified Files: ChangeLog Log Message: * ctypes/wrap/codegenerator.py: sort the generated definitions according to location in the source code. * ctypes/wrap/codegenerator.py: find_dllname() and get_sharedlib() is not needed anymore (replaced by the changes in xml2py.py). In the generated code load dll's explicitly based on name and version of the dll. * ctypes/wrap/xml2py.py: added classes to load a list of libraries (given by the option -l), to find the library in which a function is defined and to supply the information needed to load that library in the generated code. Index: ChangeLog =================================================================== RCS file: /cvsroot/ctypes/ctypes/ChangeLog,v retrieving revision 1.91 retrieving revision 1.92 diff -C2 -d -r1.91 -r1.92 *** ChangeLog 27 Apr 2005 16:40:56 -0000 1.91 --- ChangeLog 27 Apr 2005 17:04:54 -0000 1.92 *************** *** 1,4 **** --- 1,17 ---- 2005-04-27 Andreas Degert <ad...@pa...> + * ctypes/wrap/codegenerator.py: sort the generated definitions + according to location in the source code. + + * ctypes/wrap/codegenerator.py: find_dllname() and get_sharedlib() + is not needed anymore (replaced by the changes in xml2py.py). In + the generated code load dll's explicitly based on name and + version of the dll. + + * ctypes/wrap/xml2py.py: added classes to load a list of libraries + (given by the option -l), to find the library in which a function + is defined and to supply the information needed to load that + library in the generated code. + * ctypes/decorators.py: changed the decorators to optionally accept a dll object instead of a dll name. |
From: Andreas D. <ad...@us...> - 2005-04-27 17:05:03
|
Update of /cvsroot/ctypes/ctypes/ctypes/wrap In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20158/ctypes/wrap Modified Files: xml2py.py codegenerator.py Log Message: * ctypes/wrap/codegenerator.py: sort the generated definitions according to location in the source code. * ctypes/wrap/codegenerator.py: find_dllname() and get_sharedlib() is not needed anymore (replaced by the changes in xml2py.py). In the generated code load dll's explicitly based on name and version of the dll. * ctypes/wrap/xml2py.py: added classes to load a list of libraries (given by the option -l), to find the library in which a function is defined and to supply the information needed to load that library in the generated code. Index: xml2py.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/wrap/xml2py.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** xml2py.py 22 Mar 2005 12:09:23 -0000 1.2 --- xml2py.py 27 Apr 2005 17:04:53 -0000 1.3 *************** *** 1,5 **** ! import sys, re from optparse import OptionParser import typedesc ################################################################ --- 1,12 ---- ! import sys, re, os, tempfile, errno from optparse import OptionParser import typedesc + from ctypes import CDLL, cast, c_void_p + from _ctypes import dlname, dladdr + + try: + set + except NameError: + from sets import Set as set ################################################################ *************** *** 35,38 **** --- 42,258 ---- ##ntdll + def fatalerror(msg): + "Print an error message and exit the program" + print >>sys.stderr, 'Error:', msg + sys.exit(1) + + + class LibraryDescBase(object): + """Provides symbol lookup and attributes of a shared library. + + The shared library is loaded from the supplied path. + + Public instance variables: + + name: name of the shared library (e.g. for the linker option -l) + version: major version of the shared library (e.g. the 2 in libA.so.2) + key: a unique key, created from name, which is a legal python identifier + path: file path as recorded by the runtime loader (this is only used + by LibraryList for Posix systems) + + public methods: + + lookup() + + """ + + def __init__(self, path): + self.lib = CDLL(path) + + def lookup(self, symbol): + "return a ctypes function or None" + try: + return getattr(self.lib, symbol) + except AttributeError: + return None + + def make_legal_identifier(self, name): + name = re.sub('[^a-zA-Z0-9_]','_', name) + if re.match('[0-9]', name): + name = 'lib' + name + return name + + + class LibraryListBase(object): + """List of shared libraries (instances of LibraryDescBase) + + Public methods: + + which() + """ + + def __init__(self, names, searchpaths, verbose=False): + """Loads the libraries + + names: list of shared library names (as in the linker option -l) + searchpaths: list of library search paths (linker option -L) + verbose: give a verbose message in case of error + """ + pass + + def which(self, func): + """return the dll (instance of LibraryDescBase) in which func is defined + If func is not defined in any dll, return None. + """ + raise NotImplementedError + + + if os.name == "posix": + + class LibraryDescPosix(LibraryDescBase): + + def __init__(self, path): + LibraryDescBase.__init__(self, path) + self.name, self.version = self.get_name_version(path) + self.key = self.make_legal_identifier(self.name) + self.path = self.normalize_path(path) + + def get_soname(self, path): + import re, os + cmd = "objdump -p -j .dynamic " + path + res = re.search(r'\sSONAME\s+([^\s]+)', os.popen(cmd).read()) + if not res: + raise ValueError("no soname found for shared lib '%s'" % path) + return res.group(1) + + def get_name_version(self, path): + soname = self.get_soname(path) + m = re.match(r'lib(?P<name>[^.]+)\.so(\.(?P<version>.*))?', soname) + if not m: + raise ValueError( + "soname of form lib<name>.so.<version> expected, got '%s'" % soname) + return m.group('name'), m.group('version') + + def normalize_path(self, path): + "return the file path of the shared library as recorded by the runtime loader" + return dlname(self.lib._handle) + + + class LibraryListPosix(LibraryListBase): + + def __init__(self, names, searchpaths, verbose=False): + if not names: + self.dlls = [] + else: + paths = self.findLibraryPaths(names, searchpaths, verbose) + self.dlls = [LibraryDescPosix(path) for path in paths] + self.lookup_dlls = dict([(d.path, d) for d in self.dlls]) + + def which(self, func): + name = func.name + for dll in self.dlls: + f = dll.lookup(name) + if f is None: + continue + address = cast(f, c_void_p).value + path = dladdr(address) + return self.lookup_dlls.get(path) + return None + + def findLibraryPaths(self, names, searchpaths, verbose): + stubneeded = True # sometimes needed on platforms like IRIX to + # find all libraries; not needed on Linux + exprlist = [(name, re.compile('[^\(\)\s]*lib%s\.[^\(\)\s]*' % name)) + for name in names] + cc=('cc','gcc')[os.system('gcc --version > /dev/null 2> /dev/null')==0] + if stubneeded: + stubfile = tempfile.NamedTemporaryFile(suffix='.c') + stubfile.write('int main(void) { return 0L; }\n') + stubfile.flush() + stub = stubfile.name + else: + stub = '' + try: + # outfile = /dev/null works, but if someone is stupid + # enough to start this as root he might be missing + # /dev/null later... + fdout, outfile = tempfile.mkstemp() + cmd = '%s %s -o %s -Wl,-t %s %s 2>&1' % ( + cc, stub, outfile, + ' '.join(['-L%s' % path for path in searchpaths]), + ' '.join(['-l%s' % name for name in names])) + fd = os.popen(cmd) + trace = fd.read() + err = fd.close() + finally: + try: + os.unlink(outfile) + except OSError, e: + if e.errno != errno.ENOENT: + raise + paths = [] + for name, expr in exprlist: + m = expr.search(trace) + if m: + names.remove(name) + paths.append(m.group(0)) + if err and verbose: + if err >= 256: + err /= 256 + s = 'error in command (exitcode %d):\n%s' % (res, cmd) + if trace: + s += '\noutput:\n' + trace + fatalerror(s) + if names: + fatalerror('shared library not found: %s' % names[0]) + return paths + + LibraryList = LibraryListPosix + + if os.name == "nt": + + class LibraryDescNT(LibraryDescBase): + + def __init__(self, path): + LibraryDescBase.__init__(self, path) + self.name, self.version = self.get_name_version(path) + self.key = self.make_legal_identifier(self.name) + + def get_name_version(self, path): + dllname = self.get_soname(path) + m = re.match(r'(?P<name>[^.]+)\.dll(?P<version>)', dllname) + if not m: + raise ValueError( + "dll of form <name>.dll expected, got '%s'" % dllname) + return m.group('name'), m.group('version') + + + class LibraryListNT(LibraryListBase): + + def __init__(self, names, searchpaths, verbose=False): + self.dlls = [LibraryDescNT(name) for name in names] + + def which(self, func): + name = func.name + for dll in self.dlls: + if dll.lookup(name) is not None: + return dll + return None + + LibraryList = LibraryListNT + + + def remove_dups(seq): + "remove duplicate entries from a sequence and return a list" + s = set() + l = [] + for i in seq: + if i in s: + continue + s.add(i) + l.append(i) + return l + + def main(args=None): if args is None: *************** *** 67,70 **** --- 287,298 ---- default=[]) + parser.add_option("-L", + dest="searchpaths", + metavar="DIR", + help="Add directory dir to the list of" + " directories to be searched for -l", + action="append", + default=[]) + parser.add_option("-o", dest="output", *************** *** 124,129 **** ################################################################ ! from ctypes import CDLL ! dlls = [CDLL(name) for name in options.dlls] known_symbols = {} --- 352,356 ---- ################################################################ ! dlls = LibraryList(remove_dups(options.dlls), options.searchpaths) known_symbols = {} Index: codegenerator.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/wrap/codegenerator.py,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** codegenerator.py 1 Apr 2005 19:34:10 -0000 1.8 --- codegenerator.py 27 Apr 2005 17:04:53 -0000 1.9 *************** *** 3,6 **** --- 3,20 ---- # $Log$ + # Revision 1.9 2005/04/27 17:04:53 adegert + # * ctypes/wrap/codegenerator.py: sort the generated definitions + # according to location in the source code. + # + # * ctypes/wrap/codegenerator.py: find_dllname() and get_sharedlib() + # is not needed anymore (replaced by the changes in xml2py.py). In + # the generated code load dll's explicitly based on name and + # version of the dll. + # + # * ctypes/wrap/xml2py.py: added classes to load a list of libraries + # (given by the option -l), to find the library in which a function + # is defined and to supply the information needed to load that + # library in the generated code. + # # Revision 1.8 2005/04/01 19:34:10 theller # Small fixes. *************** *** 163,166 **** --- 177,181 ---- "__si_class_type_info_pseudo", "__class_type_info_pseudo", + "__va_list_tag", # internal, no members but size == 192 ] ) *************** *** 179,184 **** self.use_decorators = use_decorators self.known_symbols = known_symbols or {} ! self.searched_dlls = searched_dlls or [] self.done = set() # type descriptions that have been generated self.names = set() # names that have been generated --- 194,200 ---- self.use_decorators = use_decorators self.known_symbols = known_symbols or {} ! self.searched_dlls = searched_dlls + self.loaded_dlls = set() # dll loads that have been generated self.done = set() # type descriptions that have been generated self.names = set() # names that have been generated *************** *** 524,559 **** print >> self.stream, "]" - def find_dllname(self, func): - if hasattr(func, "dllname"): - return func.dllname - name = func.name - for dll in self.searched_dlls: - try: - getattr(dll, name) - except AttributeError: - pass - else: - return dll._name - ## if self.verbose: - # warnings.warn, maybe? - ## print >> sys.stderr, "function %s not found in any dll" % name - return None - - _loadedlibs = None - def get_sharedlib(self, dllname): - if self._loadedlibs is None: - self._loadedlibs = {} - try: - return self._loadedlibs[dllname] - except KeyError: - pass - import os - basename = os.path.basename(dllname) - name, ext = os.path.splitext(basename) - self._loadedlibs[dllname] = name - # This should be handled in another way! - ## print >> self.stream, "%s = CDLL(%r)" % (name, dllname) - return name - _STDMETHOD_defined = False def need_STDMETHOD(self): --- 540,543 ---- *************** *** 582,587 **** _notfound_functiontypes = 0 def Function(self, func): ! dllname = self.find_dllname(func) ! if dllname: self.generate(func.returns) self.generate_all(func.arguments) --- 566,579 ---- _notfound_functiontypes = 0 def Function(self, func): ! if self.searched_dlls: ! dll = self.searched_dlls.which(func) ! else: ! dll = None ! if dll: ! if dll not in self.loaded_dlls: ! print >> self.stream, \ ! '\n%s = cdll.LoadLibraryVersion("%s","%s")\n' \ ! % (dll.key, dll.name, dll.version) ! self.loaded_dlls.add(dll) self.generate(func.returns) self.generate_all(func.arguments) *************** *** 591,598 **** else: cc = "cdecl" ! libname = self.get_sharedlib(dllname) print >> self.stream if self.use_decorators: ! print >> self.stream, "@ %s(%s, '%s', [%s])" % \ (cc, self.type_name(func.returns), libname, ", ".join(args)) argnames = ["p%d" % i for i in range(1, 1+len(args))] --- 583,590 ---- else: cc = "cdecl" ! libname = dll.key print >> self.stream if self.use_decorators: ! print >> self.stream, "@ %s(%s, %s, [%s])" % \ (cc, self.type_name(func.returns), libname, ", ".join(args)) argnames = ["p%d" % i for i in range(1, 1+len(args))] *************** *** 603,607 **** print >> self.stream, " return %s._api_(%s)" % (func.name, ", ".join(argnames)) if not self.use_decorators: ! print >> self.stream, "%s = %s(%s, '%s', [%s]) (%s)" % \ (func.name, cc, self.type_name(func.returns), libname, ", ".join(args), func.name) print >> self.stream --- 595,599 ---- print >> self.stream, " return %s._api_(%s)" % (func.name, ", ".join(argnames)) if not self.use_decorators: ! print >> self.stream, "%s = %s(%s, %s, [%s]) (%s)" % \ (func.name, cc, self.type_name(func.returns), libname, ", ".join(args), func.name) print >> self.stream *************** *** 641,645 **** --- 633,648 ---- mth(item) + def cmpitems(a, b): + a = a.location + b = b.location + if a is None: return -1 + if b is None: return 1 + return cmp(a[0],b[0]) or cmp(int(a[1]),int(b[1])) + cmpitems = staticmethod(cmpitems) + def generate_all(self, items): + if not isinstance(items, list): + items = list(items) + items.sort(self.cmpitems) for item in items: self.generate(item) |
From: Andreas D. <ad...@us...> - 2005-04-27 16:41:09
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9807 Modified Files: ChangeLog Log Message: * ctypes/decorators.py: changed the decorators to optionally accept a dll object instead of a dll name. * ctypes/__init__.py: added methods find() and LoadLibraryVersion() to _CDLL. * ctypes/__init__.py: added helper functions to find a library based on the name as given to the linker -l option (on Posix systems). * source/callproc.c: added dlname and dladdr (on Posix systems). Index: ChangeLog =================================================================== RCS file: /cvsroot/ctypes/ctypes/ChangeLog,v retrieving revision 1.90 retrieving revision 1.91 diff -C2 -d -r1.90 -r1.91 *** ChangeLog 19 Apr 2005 09:00:15 -0000 1.90 --- ChangeLog 27 Apr 2005 16:40:56 -0000 1.91 *************** *** 1,2 **** --- 1,16 ---- + 2005-04-27 Andreas Degert <ad...@pa...> + + * ctypes/decorators.py: changed the decorators to optionally + accept a dll object instead of a dll name. + + * ctypes/__init__.py: added methods find() and + LoadLibraryVersion() to _CDLL. + + * ctypes/__init__.py: added helper functions to find a library + based on the name as given to the linker -l option (on Posix + systems). + + * source/callproc.c: added dlname and dladdr (on Posix systems). + 2005-04-19 Thomas Heller <th...@py...> |
From: Andreas D. <ad...@us...> - 2005-04-27 16:41:09
|
Update of /cvsroot/ctypes/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9807/ctypes Modified Files: decorators.py __init__.py Log Message: * ctypes/decorators.py: changed the decorators to optionally accept a dll object instead of a dll name. * ctypes/__init__.py: added methods find() and LoadLibraryVersion() to _CDLL. * ctypes/__init__.py: added helper functions to find a library based on the name as given to the linker -l option (on Posix systems). * source/callproc.c: added dlname and dladdr (on Posix systems). Index: decorators.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/decorators.py,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** decorators.py 18 Apr 2005 08:52:58 -0000 1.7 --- decorators.py 27 Apr 2005 16:40:55 -0000 1.8 *************** *** 27,31 **** ! def _get_library(name): # load and return a library. The library is cached. soname = _library_map.get(name, name) --- 27,31 ---- ! def _get_library(name): # load and return a library. The library is cached. soname = _library_map.get(name, name) *************** *** 50,54 **** """ def decorate(func): ! library = _get_library(dllname) api = ctypes.CFUNCTYPE(restype, *argtypes)(func.func_name, library) func._api_ = api --- 50,57 ---- """ def decorate(func): ! if isinstance(dllname, basestring): ! library = _get_library(dllname) ! else: ! library = dllname api = ctypes.CFUNCTYPE(restype, *argtypes)(func.func_name, library) func._api_ = api Index: __init__.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/__init__.py,v retrieving revision 1.71 retrieving revision 1.72 diff -C2 -d -r1.71 -r1.72 *** __init__.py 15 Apr 2005 08:27:49 -0000 1.71 --- __init__.py 27 Apr 2005 16:40:55 -0000 1.72 *************** *** 3,7 **** # special developer support to use ctypes from the CVS sandbox, # without installing it ! import os as _os, sys _magicfile = _os.path.join(_os.path.dirname(__file__), ".CTYPES_DEVEL") if _os.path.isfile(_magicfile): --- 3,7 ---- # special developer support to use ctypes from the CVS sandbox, # without installing it ! import os as _os, sys, re, tempfile _magicfile = _os.path.join(_os.path.dirname(__file__), ".CTYPES_DEVEL") if _os.path.isfile(_magicfile): *************** *** 398,432 **** return func class _DLLS(object): def __init__(self, dlltype): self._dlltype = dlltype ! if _os.name == "posix" and sys.platform == "darwin": ! def __getattr__(self, name): ! if name[0] == '_': ! raise AttributeError, name ! dll = self._dlltype("lib%s.dylib" % name) setattr(self, name, dll) return dll elif _os.name == "posix": ! def __getattr__(self, name): ! if name[0] == '_': ! raise AttributeError, name ! dll = self._dlltype("lib%s.so" % name) setattr(self, name, dll) return dll else: ! def __getattr__(self, name): ! if name[0] == '_': ! raise AttributeError, name ! dll = self._dlltype(name) setattr(self, name, dll) return dll ! ! def __getitem__(self, name): ! return getattr(self, name) ! ! def LoadLibrary(self, name): ! return self._dlltype(name) cdll = _DLLS(CDLL) --- 398,500 ---- return func + + if _os.name == "posix": + + def findLib_gcc(name): + expr = '[^\(\)\s]*lib%s\.[^\(\)\s]*' % name + cmd = 'if type gcc &>/dev/null; then CC=gcc; else CC=cc; fi;' \ + '$CC -Wl,-t -o /dev/null 2>&1 -l' + name + try: + fdout, outfile = tempfile.mkstemp() + fd = _os.popen(cmd) + trace = fd.read() + err = fd.close() + finally: + try: + _os.unlink(outfile) + except OSError, e: + if e.errno != errno.ENOENT: + raise + res = re.search(expr, trace) + if not res: + return None + return res.group(0) + + def findLib_ld(name): + expr = '/[^\(\)\s]*lib%s\.[^\(\)\s]*' % name + res = re.search(expr, _os.popen('/sbin/ldconfig -p').read()) + if not res: + return None + return res.group(0) + + def get_soname(f): + cmd = "objdump -p -j .dynamic " + f + res = re.search(r'\sSONAME\s+([^\s]+)', _os.popen(cmd).read()) + if not res: + return '??' + return res.group(1) + + def findLib(name): + lib = findLib_ld(name) + if not lib: + lib = findLib_gcc(name) + if not lib: + return name + return get_soname(lib) + + class _DLLS(object): def __init__(self, dlltype): self._dlltype = dlltype ! ! def __getattr__(self, name): ! if name[0] == '_': ! raise AttributeError, name ! dll = self._dlltype(name) ! setattr(self, name, dll) ! return dll ! ! def __getitem__(self, name): ! return getattr(self, name) ! ! def LoadLibrary(self, name): ! return self._dlltype(name) ! ! def find(self, name): ! name = self._findLibrary(name) ! dll = self._dlltype(name) ! print "ctypes.find: %s" % name ! if _os.name == "posix" and sys.platform == "darwin": ! def _findLibrary(self, name): ! return findLib(name) ! ! def LoadLibraryVersion(self, name, version=''): ! if version: ! version = '.' + version ! dll = self._dlltype("lib%s%s.dylib" % (name, version)) setattr(self, name, dll) return dll + elif _os.name == "posix": ! def _findLibrary(self, name): ! return findLib(name) ! ! def LoadLibraryVersion(self, name, version=''): ! if version: ! version = '.' + version ! dll = self._dlltype("lib%s.so%s" % (name, version)) setattr(self, name, dll) return dll + else: ! def _findLibrary(self, name): ! return "%s.dll" % name ! ! def LoadLibraryVersion(self, name, version=''): ! dll = self._dlltype(self._findLibrary(name)) setattr(self, name, dll) return dll ! cdll = _DLLS(CDLL) |
From: Andreas D. <ad...@us...> - 2005-04-27 16:41:04
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9807/source Modified Files: callproc.c Log Message: * ctypes/decorators.py: changed the decorators to optionally accept a dll object instead of a dll name. * ctypes/__init__.py: added methods find() and LoadLibraryVersion() to _CDLL. * ctypes/__init__.py: added helper functions to find a library based on the name as given to the linker -l option (on Posix systems). * source/callproc.c: added dlname and dladdr (on Posix systems). Index: callproc.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/callproc.c,v retrieving revision 1.153 retrieving revision 1.154 diff -C2 -d -r1.153 -r1.154 *** callproc.c 22 Apr 2005 16:00:10 -0000 1.153 --- callproc.c 27 Apr 2005 16:40:47 -0000 1.154 *************** *** 62,65 **** --- 62,66 ---- #else #include <dlfcn.h> + #include <link.h> #endif *************** *** 915,918 **** --- 916,946 ---- #else + static PyObject *py_dl_name(PyObject *self, PyObject *args) + { + void *handle; + struct link_map *l; + if (!PyArg_ParseTuple(args, "l:dlname", &handle)) + return NULL; + if (dlinfo(handle, RTLD_DI_LINKMAP, &l) < 0) { + PyErr_SetString(PyExc_OSError, dlerror()); + return NULL; + } + return PyString_FromString(l->l_name); + } + + static PyObject *py_dl_addr(PyObject *self, PyObject *args) + { + void *address; + Dl_info info; + if (!PyArg_ParseTuple(args, "l:dladdr", &address)) + return NULL; + if (dladdr(address, &info) == 0) { + PyErr_SetString(PyExc_OSError, + "address not contained in any shared object's segments"); + return NULL; + } + return PyString_FromString(info.dli_fname); + } + static PyObject *py_dl_open(PyObject *self, PyObject *args) { *************** *** 1285,1288 **** --- 1313,1318 ---- #else {"dlopen", py_dl_open, METH_VARARGS, "dlopen a library"}, + {"dlname", py_dl_name, METH_VARARGS, "file name from a handle"}, + {"dladdr", py_dl_addr, METH_VARARGS, "file name from an address"}, {"dlclose", py_dl_close, METH_VARARGS, "dlclose a library"}, {"dlsym", py_dl_sym, METH_VARARGS, "find symbol in shared library"}, *************** *** 1303,1306 **** --- 1333,1337 ---- Local Variables: compile-command: "cd .. && python setup.py -q build -g && python setup.py -q build install --home ~" + c-file-style: "python" End: */ |
From: Thomas H. <th...@us...> - 2005-04-25 14:31:06
|
Update of /cvsroot/ctypes/ctypes/comtypes/samples In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25841 Modified Files: Tag: branch_1_0 mstask.py Log Message: Some more paramflags. Index: mstask.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/samples/mstask.py,v retrieving revision 1.2.2.1 retrieving revision 1.2.2.2 diff -C2 -d -r1.2.2.1 -r1.2.2.2 *** mstask.py 25 Apr 2005 14:26:07 -0000 1.2.2.1 --- mstask.py 25 Apr 2005 14:30:39 -0000 1.2.2.2 *************** *** 56,62 **** ('wMilliseconds', WORD), ] ! def dump(self): ! print "SystemTime(%s\%s\%s %s:%s:%s)" % (self.wYear, self.wMonth, self.wDay, ! self.wHour, self.wMinute, self.wSecond) LPSYSTEMTIME = POINTER(_SYSTEMTIME) SYSTEMTIME = _SYSTEMTIME --- 56,62 ---- ('wMilliseconds', WORD), ] ! def __repr__(self): ! return "SystemTime(%s/%s/%s %d:%02d:%02d)" % (self.wYear, self.wMonth, self.wDay, ! self.wHour, self.wMinute, self.wSecond) LPSYSTEMTIME = POINTER(_SYSTEMTIME) SYSTEMTIME = _SYSTEMTIME *************** *** 236,272 **** IScheduledWorkItem._methods_ = [ - # C:/PROGRA~1/MICROS~3.NET/Vc7/PLATFO~1/Include/mstask.h 373 - # C:/PROGRA~1/MICROS~3.NET/Vc7/PLATFO~1/Include/mstask.h 377 COMMETHOD([], HRESULT, 'CreateTrigger', ! ( [], POINTER(WORD) ), ! ( [], POINTER(POINTER(ITaskTrigger)) ), ! ), ! # C:/PROGRA~1/MICROS~3.NET/Vc7/PLATFO~1/Include/mstask.h 380 COMMETHOD([], HRESULT, 'DeleteTrigger', ! ( [], WORD ), ! ), ! # C:/PROGRA~1/MICROS~3.NET/Vc7/PLATFO~1/Include/mstask.h 383 COMMETHOD([], HRESULT, 'GetTriggerCount', ( ["out"], POINTER(WORD), "pwCount")), - # C:/PROGRA~1/MICROS~3.NET/Vc7/PLATFO~1/Include/mstask.h 387 COMMETHOD([], HRESULT, 'GetTrigger', ! ( [], WORD ), ! ( [], POINTER(POINTER(ITaskTrigger)) ), ! ), ! # C:/PROGRA~1/MICROS~3.NET/Vc7/PLATFO~1/Include/mstask.h 391 COMMETHOD([], HRESULT, 'GetTriggerString', ! ( [], WORD ), ! ( [], POINTER(LPWSTR) ), ! ), # C:/PROGRA~1/MICROS~3.NET/Vc7/PLATFO~1/Include/mstask.h 397 COMMETHOD([], HRESULT, 'GetRunTimes', ! ( [], LPSYSTEMTIME ), ! ( [], LPSYSTEMTIME ), ! ( [], POINTER(WORD) ), ! ( [], POINTER(LPSYSTEMTIME) ), ), # C:/PROGRA~1/MICROS~3.NET/Vc7/PLATFO~1/Include/mstask.h 400 COMMETHOD([], HRESULT, 'GetNextRunTime', ! ( [], POINTER(SYSTEMTIME) ), ), # C:/PROGRA~1/MICROS~3.NET/Vc7/PLATFO~1/Include/mstask.h 404 --- 236,264 ---- IScheduledWorkItem._methods_ = [ COMMETHOD([], HRESULT, 'CreateTrigger', ! ( ["out"], POINTER(WORD) ), ! ( ["out"], POINTER(POINTER(ITaskTrigger)) )), COMMETHOD([], HRESULT, 'DeleteTrigger', ! ( ["in"], WORD )), COMMETHOD([], HRESULT, 'GetTriggerCount', ( ["out"], POINTER(WORD), "pwCount")), COMMETHOD([], HRESULT, 'GetTrigger', ! ( ["in"], WORD ), ! ( ["out"], POINTER(POINTER(ITaskTrigger)) )), COMMETHOD([], HRESULT, 'GetTriggerString', ! ( ["in"], WORD ), ! ( ["out"], POINTER(LPWSTR) )), # C:/PROGRA~1/MICROS~3.NET/Vc7/PLATFO~1/Include/mstask.h 397 COMMETHOD([], HRESULT, 'GetRunTimes', ! ( ["in"], LPSYSTEMTIME ), ! ( ["in"], LPSYSTEMTIME ), ! ( ["out", "in"], POINTER(WORD) ), ! ## ( ["in"], POINTER(WORD) ), ! ( ["out"], POINTER(LPSYSTEMTIME) ), ), # C:/PROGRA~1/MICROS~3.NET/Vc7/PLATFO~1/Include/mstask.h 400 + # Hm. The docs say [out], but the include file says [in][out]. COMMETHOD([], HRESULT, 'GetNextRunTime', ! ( ["out"], POINTER(SYSTEMTIME) ), ), # C:/PROGRA~1/MICROS~3.NET/Vc7/PLATFO~1/Include/mstask.h 404 *************** *** 286,294 **** COMMETHOD([], HRESULT, 'Terminate', ), ! # C:/PROGRA~1/MICROS~3.NET/Vc7/PLATFO~1/Include/mstask.h 416 COMMETHOD([], HRESULT, 'EditWorkItem', ! ( [], HWND ), ! ( [], DWORD ), ! ), # C:/PROGRA~1/MICROS~3.NET/Vc7/PLATFO~1/Include/mstask.h 419 COMMETHOD([], HRESULT, 'GetMostRecentRunTime', --- 278,285 ---- COMMETHOD([], HRESULT, 'Terminate', ), ! COMMETHOD([], HRESULT, 'EditWorkItem', ! ( ["in", defaultvalue(None)], HWND, 'hParent' ), ! ( ["in", defaultvalue(0)], DWORD, 'dwReserved' )), # C:/PROGRA~1/MICROS~3.NET/Vc7/PLATFO~1/Include/mstask.h 419 COMMETHOD([], HRESULT, 'GetMostRecentRunTime', *************** *** 343,362 **** # C:/PROGRA~1/MICROS~3.NET/Vc7/PLATFO~1/Include/mstask.h 457 COMMETHOD([], HRESULT, 'GetErrorRetryInterval', ! ( [], POINTER(WORD) ), ! ), ! # C:/PROGRA~1/MICROS~3.NET/Vc7/PLATFO~1/Include/mstask.h 460 COMMETHOD([], HRESULT, 'SetFlags', ! ( [], DWORD ), ! ), ! # C:/PROGRA~1/MICROS~3.NET/Vc7/PLATFO~1/Include/mstask.h 463 COMMETHOD([], HRESULT, 'GetFlags', ! ( [], POINTER(DWORD) ), ! ), ! # C:/PROGRA~1/MICROS~3.NET/Vc7/PLATFO~1/Include/mstask.h 467 COMMETHOD([], HRESULT, 'SetAccountInformation', ! ( [], LPCWSTR ), ! ( [], LPCWSTR ), ! ), ! COMMETHOD([], HRESULT, 'GetAccountInformation', ( ["out"], POINTER(LPWSTR), "ppwszAccountName" )), --- 334,345 ---- # C:/PROGRA~1/MICROS~3.NET/Vc7/PLATFO~1/Include/mstask.h 457 COMMETHOD([], HRESULT, 'GetErrorRetryInterval', ! ( ["out"], POINTER(WORD) )), COMMETHOD([], HRESULT, 'SetFlags', ! ( ["in"], DWORD )), COMMETHOD([], HRESULT, 'GetFlags', ! ( ["out"], POINTER(DWORD) )), COMMETHOD([], HRESULT, 'SetAccountInformation', ! ( ["in"], LPCWSTR, 'pwszAccountName' ), ! ( ["in"], LPCWSTR, 'pwszPassword' )), COMMETHOD([], HRESULT, 'GetAccountInformation', ( ["out"], POINTER(LPWSTR), "ppwszAccountName" )), *************** *** 390,393 **** --- 373,385 ---- ( ["out"], POINTER(DWORD) )) ] + # create properties form Get/Set methods + ITask.ApplicationName = property(ITask.GetApplicationName, ITask.SetApplicationName) + ITask.Parameters = property(ITask.GetParameters, ITask.SetParameters) + ITask.WorkingDirectory = property(ITask.GetWorkingDirectory, ITask.SetWorkingDirectory) + ITask.Priority = property(ITask.GetPriority, ITask.SetPriority) + ITaskTaskFlags = property(ITask.GetTaskFlags, ITask.SetTaskFlags) + ITask.MaxRunTime = property(ITask.GetMaxRunTime, ITask.SetMaxRunTime) + + ################################################################ if __name__ == "__main__": *************** *** 395,410 **** scheduler = CoCreateInstance(CLSID_CTaskScheduler, ITaskScheduler) ! for taskname in scheduler.Enum(): print "%s:" % taskname, task = scheduler.Activate(taskname, byref(ITask._iid_)) task = task.QueryInterface(ITask) ! print task.GetTriggerCount(), task.GetMaxRunTime(), task.GetApplicationName() ! print scheduler.Enum() ! print scheduler.Enum().Clone() ! for i in range (50): ! for item in scheduler: ! pass # leaks 10 refs per loop ! print scheduler.AddRef(), scheduler.Release() --- 387,431 ---- scheduler = CoCreateInstance(CLSID_CTaskScheduler, ITaskScheduler) ! for taskname in scheduler: # calls Enum automatically print "%s:" % taskname, task = scheduler.Activate(taskname, byref(ITask._iid_)) task = task.QueryInterface(ITask) ! print (task.Parameters, task.MaxRunTime, task.ApplicationName) ! print "PRI", (task.Priority, task.WorkingDirectory) ! ## print task.GetErrorRetryInterval() ! try: ! print "Account Info", task.GetAccountInformation() ! except WindowsError: ! print "Nothing" ! ## print task.EditWorkItem(None, 0) ! print "XXX", task.GetNextRunTime() ! ## t = SYSTEMTIME() ! ## t.wYear = 2000 ! ## t.wMonth = 1 ! ## t.wDay = 1 ! ## t.wMinute = 1 ! ## t.wSecond = 1 ! ## t = byref(t) ! ## for i in range(20): ! ## idx, t = task.GetRunTimes(t, None, 2) ! ## print idx, t[1].dump() ! ## t = pointer(t[1]) ! for i in range(3): ! print task.CreateTrigger() ! for i in range(task.GetTriggerCount()): ! try: ! print i, task.GetTriggerString(i).encode("mbcs") ! except Exception: ! import traceback ! traceback.print_exc() ! print scheduler.NewWorkItem("blahblah") ! ! ## print scheduler.Enum() ! ## print scheduler.Enum().Clone() ! ! ## for i in range (50): ! ## for item in scheduler: ! ## pass # leaks 10 refs per loop |
From: Thomas H. <th...@us...> - 2005-04-25 14:26:32
|
Update of /cvsroot/ctypes/ctypes/comtypes/samples In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23435 Modified Files: Tag: branch_1_0 mstask.py Log Message: Move code around, remove some asserts. Index: mstask.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/samples/mstask.py,v retrieving revision 1.2 retrieving revision 1.2.2.1 diff -C2 -d -r1.2 -r1.2.2.1 *** mstask.py 11 Mar 2005 17:35:39 -0000 1.2 --- mstask.py 25 Apr 2005 14:26:07 -0000 1.2.2.1 *************** *** 45,48 **** --- 45,137 ---- ################################################################ + class _SYSTEMTIME(Structure): + _fields_ = [ + ('wYear', WORD), + ('wMonth', WORD), + ('wDayOfWeek', WORD), + ('wDay', WORD), + ('wHour', WORD), + ('wMinute', WORD), + ('wSecond', WORD), + ('wMilliseconds', WORD), + ] + def dump(self): + print "SystemTime(%s\%s\%s %s:%s:%s)" % (self.wYear, self.wMonth, self.wDay, + self.wHour, self.wMinute, self.wSecond) + LPSYSTEMTIME = POINTER(_SYSTEMTIME) + SYSTEMTIME = _SYSTEMTIME + + _TASK_TRIGGER_TYPE = c_int # enum + TASK_TIME_TRIGGER_ONCE = 0 + TASK_TIME_TRIGGER_DAILY = 1 + TASK_TIME_TRIGGER_WEEKLY = 2 + TASK_TIME_TRIGGER_MONTHLYDATE = 3 + TASK_TIME_TRIGGER_MONTHLYDOW = 4 + TASK_EVENT_TRIGGER_ON_IDLE = 5 + TASK_EVENT_TRIGGER_AT_SYSTEMSTART = 6 + TASK_EVENT_TRIGGER_AT_LOGON = 7 + TASK_TRIGGER_TYPE = _TASK_TRIGGER_TYPE + + class _TASK_TRIGGER(Structure): + pass + PTASK_TRIGGER = POINTER(_TASK_TRIGGER) + + class _DAILY(Structure): + _fields_ = [('DaysInterval', WORD)] + DAILY = _DAILY + + class _WEEKLY(Structure): + _fields_ = [ + ('WeeksInterval', WORD), + ('rgfDaysOfTheWeek', WORD), + ] + WEEKLY = _WEEKLY + + class _MONTHLYDATE(Structure): + _fields_ = [ + ('rgfDays', DWORD), + ('rgfMonths', WORD), + ] + MONTHLYDATE = _MONTHLYDATE + + class _MONTHLYDOW(Structure): + _fields_ = [ + ('wWhichWeek', WORD), + ('rgfDaysOfTheWeek', WORD), + ('rgfMonths', WORD), + ] + MONTHLYDOW = _MONTHLYDOW + + class _TRIGGER_TYPE_UNION(Union): + _fields_ = [ + ('Daily', DAILY), + ('Weekly', WEEKLY), + ('MonthlyDate', MONTHLYDATE), + ('MonthlyDOW', MONTHLYDOW), + ] + TRIGGER_TYPE_UNION = _TRIGGER_TYPE_UNION + + _TASK_TRIGGER._fields_ = [ + ('cbTriggerSize', WORD), + ('Reserved1', WORD), + ('wBeginYear', WORD), + ('wBeginMonth', WORD), + ('wBeginDay', WORD), + ('wEndYear', WORD), + ('wEndMonth', WORD), + ('wEndDay', WORD), + ('wStartHour', WORD), + ('wStartMinute', WORD), + ('MinutesDuration', DWORD), + ('MinutesInterval', DWORD), + ('rgFlags', DWORD), + ('TriggerType', TASK_TRIGGER_TYPE), + ('Type', TRIGGER_TYPE_UNION), + ('Reserved2', WORD), + ('wRandomMinutesInterval', WORD), + ] + + ################################################################ + CLSID_CTaskScheduler = GUID("{148BD52A-A2AB-11CE-B11F-00AA00530503}") class ITaskScheduler(IUnknown): *************** *** 117,124 **** ] - class _TASK_TRIGGER(Structure): - # C:/PROGRA~1/MICROS~3.NET/Vc7/PLATFO~1/Include/mstask.h 185 - pass - PTASK_TRIGGER = POINTER(_TASK_TRIGGER) ITaskTrigger._methods_ = [ # C:/PROGRA~1/MICROS~3.NET/Vc7/PLATFO~1/Include/mstask.h 228 --- 206,209 ---- *************** *** 137,230 **** ] - _TASK_TRIGGER_TYPE = c_int # enum - TASK_TIME_TRIGGER_ONCE = 0 - TASK_TIME_TRIGGER_DAILY = 1 - TASK_TIME_TRIGGER_WEEKLY = 2 - TASK_TIME_TRIGGER_MONTHLYDATE = 3 - TASK_TIME_TRIGGER_MONTHLYDOW = 4 - TASK_EVENT_TRIGGER_ON_IDLE = 5 - TASK_EVENT_TRIGGER_AT_SYSTEMSTART = 6 - TASK_EVENT_TRIGGER_AT_LOGON = 7 - TASK_TRIGGER_TYPE = _TASK_TRIGGER_TYPE - class _TRIGGER_TYPE_UNION(Union): - # C:/PROGRA~1/MICROS~3.NET/Vc7/PLATFO~1/Include/mstask.h 177 - pass - class _DAILY(Structure): - # C:/PROGRA~1/MICROS~3.NET/Vc7/PLATFO~1/Include/mstask.h 153 - pass - _DAILY._fields_ = [ - # C:/PROGRA~1/MICROS~3.NET/Vc7/PLATFO~1/Include/mstask.h 153 - ('DaysInterval', WORD), - ] - assert sizeof(_DAILY) == 2, sizeof(_DAILY) - assert alignment(_DAILY) == 2, alignment(_DAILY) - DAILY = _DAILY - class _WEEKLY(Structure): - # C:/PROGRA~1/MICROS~3.NET/Vc7/PLATFO~1/Include/mstask.h 158 - pass - _WEEKLY._fields_ = [ - # C:/PROGRA~1/MICROS~3.NET/Vc7/PLATFO~1/Include/mstask.h 158 - ('WeeksInterval', WORD), - ('rgfDaysOfTheWeek', WORD), - ] - assert sizeof(_WEEKLY) == 4, sizeof(_WEEKLY) - assert alignment(_WEEKLY) == 2, alignment(_WEEKLY) - WEEKLY = _WEEKLY - class _MONTHLYDATE(Structure): - # C:/PROGRA~1/MICROS~3.NET/Vc7/PLATFO~1/Include/mstask.h 164 - pass - _MONTHLYDATE._fields_ = [ - # C:/PROGRA~1/MICROS~3.NET/Vc7/PLATFO~1/Include/mstask.h 164 - ('rgfDays', DWORD), - ('rgfMonths', WORD), - ] - assert sizeof(_MONTHLYDATE) == 8, sizeof(_MONTHLYDATE) - assert alignment(_MONTHLYDATE) == 4, alignment(_MONTHLYDATE) - MONTHLYDATE = _MONTHLYDATE - class _MONTHLYDOW(Structure): - # C:/PROGRA~1/MICROS~3.NET/Vc7/PLATFO~1/Include/mstask.h 170 - pass - _MONTHLYDOW._fields_ = [ - # C:/PROGRA~1/MICROS~3.NET/Vc7/PLATFO~1/Include/mstask.h 170 - ('wWhichWeek', WORD), - ('rgfDaysOfTheWeek', WORD), - ('rgfMonths', WORD), - ] - assert sizeof(_MONTHLYDOW) == 6, sizeof(_MONTHLYDOW) - assert alignment(_MONTHLYDOW) == 2, alignment(_MONTHLYDOW) - MONTHLYDOW = _MONTHLYDOW - _TRIGGER_TYPE_UNION._fields_ = [ - # C:/PROGRA~1/MICROS~3.NET/Vc7/PLATFO~1/Include/mstask.h 177 - ('Daily', DAILY), - ('Weekly', WEEKLY), - ('MonthlyDate', MONTHLYDATE), - ('MonthlyDOW', MONTHLYDOW), - ] - assert sizeof(_TRIGGER_TYPE_UNION) == 8, sizeof(_TRIGGER_TYPE_UNION) - assert alignment(_TRIGGER_TYPE_UNION) == 4, alignment(_TRIGGER_TYPE_UNION) - TRIGGER_TYPE_UNION = _TRIGGER_TYPE_UNION - _TASK_TRIGGER._fields_ = [ - # C:/PROGRA~1/MICROS~3.NET/Vc7/PLATFO~1/Include/mstask.h 185 - ('cbTriggerSize', WORD), - ('Reserved1', WORD), - ('wBeginYear', WORD), - ('wBeginMonth', WORD), - ('wBeginDay', WORD), - ('wEndYear', WORD), - ('wEndMonth', WORD), - ('wEndDay', WORD), - ('wStartHour', WORD), - ('wStartMinute', WORD), - ('MinutesDuration', DWORD), - ('MinutesInterval', DWORD), - ('rgFlags', DWORD), - ('TriggerType', TASK_TRIGGER_TYPE), - ('Type', TRIGGER_TYPE_UNION), - ('Reserved2', WORD), - ('wRandomMinutesInterval', WORD), - ] - assert sizeof(_TASK_TRIGGER) == 48, sizeof(_TASK_TRIGGER) - assert alignment(_TASK_TRIGGER) == 4, alignment(_TASK_TRIGGER) - IEnumWorkItems._methods_ = [ COMMETHOD([], HRESULT, 'Next', --- 222,225 ---- *************** *** 239,258 **** ( ["out"], POINTER(POINTER(IEnumWorkItems)) )) ] - class _SYSTEMTIME(Structure): - # C:/PROGRA~1/MICROS~3.NET/Vc7/PLATFO~1/Include/winbase.h 270 - _fields_ = [ - ('wYear', WORD), - ('wMonth', WORD), - ('wDayOfWeek', WORD), - ('wDay', WORD), - ('wHour', WORD), - ('wMinute', WORD), - ('wSecond', WORD), - ('wMilliseconds', WORD), - ] - LPSYSTEMTIME = POINTER(_SYSTEMTIME) - SYSTEMTIME = _SYSTEMTIME - assert sizeof(_SYSTEMTIME) == 16, sizeof(_SYSTEMTIME) - assert alignment(_SYSTEMTIME) == 2, alignment(_SYSTEMTIME) IScheduledWorkItem._methods_ = [ --- 234,237 ---- |
From: Thomas H. <th...@us...> - 2005-04-22 16:00:19
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27412/unittests Modified Files: test_setfunc.py Log Message: repr of PyCArgObject changed, fixed test Index: test_setfunc.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_setfunc.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** test_setfunc.py 6 Apr 2005 18:40:31 -0000 1.2 --- test_setfunc.py 22 Apr 2005 16:00:11 -0000 1.3 *************** *** 22,26 **** def test_fromparam(self): ! for cls in s_types + u_types: for obj in [typ(42) for typ in s_types + u_types] + [42, 42L]: # from_param currently either returns the object itself, --- 22,27 ---- def test_fromparam(self): ! # This test checks the repr of what from_param returns. Which is in flux. ! for cls in s_types: for obj in [typ(42) for typ in s_types + u_types] + [42, 42L]: # from_param currently either returns the object itself, *************** *** 29,33 **** if obj == param: continue ! self.failUnlessEqual(repr(param), "<cparam '%s' (42)>" % cls._type_, (repr(param), obj, cls, cls._type_)) --- 30,34 ---- if obj == param: continue ! self.failUnlessEqual(repr(param), "<cparam 'i%d' (42)>" % sizeof(cls), (repr(param), obj, cls, cls._type_)) *************** *** 35,38 **** --- 36,48 ---- self.assertRaises(TypeError, lambda: cls.from_para,(obj)) + for cls in u_types: + for obj in [typ(42) for typ in s_types + u_types] + [42, 42L]: + # from_param currently either returns the object itself, + # or a PyCArgObject. + param = cls.from_param(obj) + if obj == param: + continue + self.failUnlessEqual(repr(param), "<cparam 'u%d' (42)>" % sizeof(cls), + (repr(param), obj, cls, cls._type_)) def test_setfield(self): for cls in s_types + u_types: |
From: Thomas H. <th...@us...> - 2005-04-22 16:00:19
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27412/source Modified Files: callproc.c Log Message: repr of PyCArgObject changed, fixed test Index: callproc.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/callproc.c,v retrieving revision 1.152 retrieving revision 1.153 diff -C2 -d -r1.152 -r1.153 *** callproc.c 19 Apr 2005 08:31:54 -0000 1.152 --- callproc.c 22 Apr 2005 16:00:10 -0000 1.153 *************** *** 289,313 **** if (self->pffi_type == &ffi_type_pointer) { ! sprintf(buffer, "<cparam 'P' (%08lx)>", (long)self->value.p); } else switch(self->pffi_type->type) { case FFI_TYPE_SINT8: ! sprintf(buffer, "<cparam 'b' (%d)>", self->value.b); break; case FFI_TYPE_UINT8: ! sprintf(buffer, "<cparam 'B' (%d)>", self->value.b); break; case FFI_TYPE_SINT16: ! sprintf(buffer, "<cparam 'h' (%d)>", self->value.h); break; case FFI_TYPE_UINT16: ! sprintf(buffer, "<cparam 'H' (%d)>", self->value.h); break; case FFI_TYPE_SINT32: ! sprintf(buffer, "<cparam 'l' (%d)>", self->value.i); break; case FFI_TYPE_UINT32: ! sprintf(buffer, "<cparam 'L' (%d)>", self->value.i); break; #ifdef HAVE_LONG_LONG --- 289,313 ---- if (self->pffi_type == &ffi_type_pointer) { ! sprintf(buffer, "<cparam 'P' (%p)>", (long)self->value.p); } else switch(self->pffi_type->type) { case FFI_TYPE_SINT8: ! sprintf(buffer, "<cparam 'i1' (%d)>", self->value.b); break; case FFI_TYPE_UINT8: ! sprintf(buffer, "<cparam 'u1' (%d)>", self->value.b); break; case FFI_TYPE_SINT16: ! sprintf(buffer, "<cparam 'i2' (%d)>", self->value.h); break; case FFI_TYPE_UINT16: ! sprintf(buffer, "<cparam 'u2' (%d)>", self->value.h); break; case FFI_TYPE_SINT32: ! sprintf(buffer, "<cparam 'i4' (%d)>", self->value.i); break; case FFI_TYPE_UINT32: ! sprintf(buffer, "<cparam 'u4' (%d)>", self->value.i); break; #ifdef HAVE_LONG_LONG *************** *** 315,321 **** sprintf(buffer, #ifdef MS_WIN32 ! "<cparam 'q' (%I64d)>", #else ! "<cparam 'q' (%qd)>", #endif self->value.q); --- 315,321 ---- sprintf(buffer, #ifdef MS_WIN32 ! "<cparam 'i8' (%I64d)>", #else ! "<cparam 'i8' (%qd)>", #endif self->value.q); *************** *** 324,330 **** sprintf(buffer, #ifdef MS_WIN32 ! "<cparam 'Q' (%I64d)>", #else ! "<cparam 'Q' (%qd)>", #endif self->value.q); --- 324,330 ---- sprintf(buffer, #ifdef MS_WIN32 ! "<cparam 'u8' (%I64d)>", #else ! "<cparam 'u8' (%qd)>", #endif self->value.q); |
From: Thomas H. <th...@us...> - 2005-04-22 15:42:47
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18463 Modified Files: test_returnfuncptrs.py Log Message: Explain the code. Index: test_returnfuncptrs.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_returnfuncptrs.py,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** test_returnfuncptrs.py 18 Apr 2005 11:11:49 -0000 1.9 --- test_returnfuncptrs.py 22 Apr 2005 15:42:38 -0000 1.10 *************** *** 23,26 **** --- 23,27 ---- dll = CDLL(find_test_dll()) get_strchr = dll.get_strchr + # the default 'c_int' would not work on systems where sizeof(int) != sizeof(void *) get_strchr.restype = c_void_p addr = get_strchr() |