ctypes-commit Mailing List for ctypes (Page 79)
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-01-12 08:11:36
|
Update of /cvsroot/ctypes/ctypes/sandbox/tools/codegen In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24583 Modified Files: typedesc.py Log Message: EnumValues are now exposed at the top level. Index: typedesc.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/sandbox/tools/codegen/typedesc.py,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** typedesc.py 22 Dec 2004 08:39:39 -0000 1.3 --- typedesc.py 12 Jan 2005 08:11:26 -0000 1.4 *************** *** 129,134 **** self.values = [] ! def add_value(self, name, value): ! self.values.append((name, value)) ################################################################ --- 129,140 ---- self.values = [] ! def add_value(self, v): ! self.values.append(v) ! ! class EnumValue(object): ! def __init__(self, name, value, enumeration): ! self.name = name ! self.value = value ! self.enumeration = enumeration ################################################################ |
From: Thomas H. <th...@us...> - 2005-01-12 08:06:38
|
Update of /cvsroot/ctypes/ctypes/sandbox/tools/codegen In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23596 Modified Files: gccxmlparser.py Log Message: EnumValues are now exposed at the top level. Index: gccxmlparser.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/sandbox/tools/codegen/gccxmlparser.py,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** gccxmlparser.py 7 Jan 2005 18:58:32 -0000 1.9 --- gccxmlparser.py 12 Jan 2005 08:06:28 -0000 1.10 *************** *** 32,37 **** --- 32,43 ---- # record the result _id = attrs.get("id", None) + # The '_id' attribute is used to link together all the + # nodes, in the _fixup_ methods. if _id is not None: self.all[_id] = result + else: + # EnumValue, for example, has no "_id" attribute. + # Invent our own... + self.all[id(result)] = result # if this element has children, push onto the context if name in self.has_values: *************** *** 192,196 **** name = self.demangle(attrs["name"]) value = attrs["init"] ! self.context[-1].add_value(name, value) def _fixup_EnumValue(self, e): pass --- 198,204 ---- name = self.demangle(attrs["name"]) value = attrs["init"] ! v = typedesc.EnumValue(name, value, self.context[-1]) ! self.context[-1].add_value(v) ! return v def _fixup_EnumValue(self, e): pass *************** *** 251,259 **** def get_result(self): ! interesting = (typedesc.Typedef, typedesc.Enumeration, typedesc.Function, typedesc.Structure, typedesc.Union) result = [] remove = [] for n, i in self.all.items(): mth = getattr(self, "_fixup_" + type(i).__name__) try: --- 259,268 ---- def get_result(self): ! interesting = (typedesc.Typedef, typedesc.Enumeration, typedesc.EnumValue, typedesc.Function, typedesc.Structure, typedesc.Union) result = [] remove = [] for n, i in self.all.items(): + # link together all the nodes (the XML that gccxml generates uses this). mth = getattr(self, "_fixup_" + type(i).__name__) try: |
From: Thomas H. <th...@us...> - 2005-01-12 08:04:42
|
Update of /cvsroot/ctypes/ctypes/sandbox/tools/codegen In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23199 Modified Files: codegenerator.py Log Message: EnumValues are now exposed at the top level. Index: codegenerator.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/sandbox/tools/codegen/codegenerator.py,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** codegenerator.py 10 Jan 2005 16:20:00 -0000 1.18 --- codegenerator.py 12 Jan 2005 08:04:33 -0000 1.19 *************** *** 252,269 **** self.done.add(tp) _enumtypes = 0 def Enumeration(self, tp): if tp in self.done: return self._enumtypes += 1 if tp.name: print >> self.stream print >> self.stream, "%s = c_int # enum" % tp.name ! for n, v in tp.values: ! print >> self.stream, "%s = %s # enum %s" % (n, v, tp.name) ! else: ! for n, v in tp.values: ! print >> self.stream, "%s = %s # enum" % (n, v) ! self.done.add(tp) def StructureBody(self, body): --- 252,273 ---- self.done.add(tp) + def EnumValue(self, tp): + if tp in self.done: + return + print >> self.stream, \ + "%s = %s # enum %s" % (tp.name, tp.value, tp.enumeration.name or "") + self.done.add(tp) + _enumtypes = 0 def Enumeration(self, tp): if tp in self.done: return + self.done.add(tp) self._enumtypes += 1 if tp.name: print >> self.stream print >> self.stream, "%s = c_int # enum" % tp.name ! for item in tp.values: ! self.EnumValue(item) def StructureBody(self, body): |
From: Thomas H. <th...@us...> - 2005-01-10 16:24:38
|
Update of /cvsroot/ctypes/ctypes/sandbox/tools/codegen In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24338 Modified Files: h2xml.py Log Message: Isolate windows specific code. Index: h2xml.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/sandbox/tools/codegen/h2xml.py,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** h2xml.py 10 Jan 2005 16:16:52 -0000 1.4 --- h2xml.py 10 Jan 2005 16:24:29 -0000 1.5 *************** *** 1,20 **** """h2xml - convert C include file(s) into an xml file by running gccxml.""" import sys, os, tempfile - import _winreg ! def _locate_gccxml(): ! for subkey in (r"Software\gccxml", r"Software\Kitware\GCC_XML"): ! for root in (_winreg.HKEY_CURRENT_USER, _winreg.HKEY_LOCAL_MACHINE): ! try: ! hkey = _winreg.OpenKey(root, subkey, 0, _winreg.KEY_READ) ! except WindowsError, detail: ! if detail.errno != 2: ! raise ! else: ! return _winreg.QueryValueEx(hkey, "loc")[0] + r"\bin" ! loc = _locate_gccxml() ! if loc: ! os.environ["PATH"] = loc ################################################################ --- 1,22 ---- """h2xml - convert C include file(s) into an xml file by running gccxml.""" import sys, os, tempfile ! if sys.platform == "win32": ! def _locate_gccxml(): ! import _winreg ! for subkey in (r"Software\gccxml", r"Software\Kitware\GCC_XML"): ! for root in (_winreg.HKEY_CURRENT_USER, _winreg.HKEY_LOCAL_MACHINE): ! try: ! hkey = _winreg.OpenKey(root, subkey, 0, _winreg.KEY_READ) ! except WindowsError, detail: ! if detail.errno != 2: ! raise ! else: ! return _winreg.QueryValueEx(hkey, "loc")[0] + r"\bin" ! ! loc = _locate_gccxml() ! if loc: ! os.environ["PATH"] = loc ################################################################ |
From: Thomas H. <th...@us...> - 2005-01-10 16:21:46
|
Update of /cvsroot/ctypes/ctypes/sandbox/tools/codegen In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23628 Modified Files: xml2py.py Log Message: Change some option names, don't assume ctypes.com or comtypes. Index: xml2py.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/sandbox/tools/codegen/xml2py.py,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** xml2py.py 7 Jan 2005 16:08:09 -0000 1.7 --- xml2py.py 10 Jan 2005 16:21:15 -0000 1.8 *************** *** 46,57 **** parser = OptionParser("usage: %prog [options] xmlfile") ! parser.add_option("--windows-dlls", action="callback", callback=windows_dlls, help="add all standard windows dlls to the searched dlls list") ! parser.add_option("--dll", dest="dlls", ! help="dlls to search for exported functions", action="append", default=[]) --- 46,57 ---- parser = OptionParser("usage: %prog [options] xmlfile") ! parser.add_option("-w", action="callback", callback=windows_dlls, help="add all standard windows dlls to the searched dlls list") ! parser.add_option("-l", dest="dlls", ! help="libraries to search for exported functions", action="append", default=[]) *************** *** 90,99 **** default=False) ! try: ! import comtypes ! except ImportError: ! default_modules = ["ctypes", "ctypes.com"] ! else: ! default_modules = ["ctypes", "comtypes"] parser.add_option("-m", --- 90,100 ---- default=False) ! ## try: ! ## import comtypes ! ## except ImportError: ! ## default_modules = ["ctypes", "ctypes.com"] ! ## else: ! ## default_modules = ["ctypes", "comtypes"] ! default_modules = ["ctypes"] parser.add_option("-m", |
From: Thomas H. <th...@us...> - 2005-01-10 16:20:41
|
Update of /cvsroot/ctypes/ctypes/sandbox/tools/codegen In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23317 Modified Files: codegenerator.py Log Message: Be less chatty. Index: codegenerator.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/sandbox/tools/codegen/codegenerator.py,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** codegenerator.py 7 Jan 2005 19:42:33 -0000 1.17 --- codegenerator.py 10 Jan 2005 16:20:00 -0000 1.18 *************** *** 345,350 **** else: return dll._name ! ## print >> sys.stderr, "warning: dll not found for function %s" % name ! ## return "???" return None --- 345,351 ---- else: return dll._name ! ## if self.verbose: ! # warnings.warn, maybe? ! ## print >> sys.stderr, "function %s not found in any dll" % name return None *************** *** 414,418 **** name = getattr(item, "name", None) if name in self.known_symbols: ! print >> self.stream, "# %s is in known_symbols" % name print >> self.stream, "from %s import %s" % (self.known_symbols[name].__module__, name) self.done.add(item) --- 415,419 ---- name = getattr(item, "name", None) if name in self.known_symbols: ! ## print >> self.stream, "# %s is in known_symbols" % name print >> self.stream, "from %s import %s" % (self.known_symbols[name].__module__, name) self.done.add(item) |
From: Thomas H. <th...@us...> - 2005-01-10 16:17:02
|
Update of /cvsroot/ctypes/ctypes/sandbox/tools/codegen In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22562 Modified Files: h2xml.py Log Message: The .exe extension doesn't work on linux ;-) Index: h2xml.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/sandbox/tools/codegen/h2xml.py,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** h2xml.py 17 Dec 2004 09:35:58 -0000 1.3 --- h2xml.py 10 Jan 2005 16:16:52 -0000 1.4 *************** *** 53,58 **** try: if verbose: ! print >> sys.stderr, r"gccxml.exe %s %s -fxml=%s" % (options, c_file, xml_file) ! i, o = os.popen4(r"gccxml.exe %s %s -fxml=%s" % (options, c_file, xml_file)) i.close() sys.stderr.write(o.read()) --- 53,58 ---- try: if verbose: ! print >> sys.stderr, r"gccxml %s %s -fxml=%s" % (options, c_file, xml_file) ! i, o = os.popen4(r"gccxml %s %s -fxml=%s" % (options, c_file, xml_file)) i.close() sys.stderr.write(o.read()) |
From: Thomas H. <th...@us...> - 2005-01-07 20:17:54
|
Update of /cvsroot/ctypes/ctypes/sandbox/tools/codegen In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32707 Removed Files: _support.py Log Message: No longer needed. --- _support.py DELETED --- |
From: Thomas H. <th...@us...> - 2005-01-07 19:42:44
|
Update of /cvsroot/ctypes/ctypes/sandbox/tools/codegen In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24305 Modified Files: codegenerator.py Log Message: No need to output the actual _api_ call. Index: codegenerator.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/sandbox/tools/codegen/codegenerator.py,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** codegenerator.py 7 Jan 2005 18:57:22 -0000 1.16 --- codegenerator.py 7 Jan 2005 19:42:33 -0000 1.17 *************** *** 387,391 **** print >> self.stream, "def %s(%s):" % (func.name, ", ".join(argnames)) print >> self.stream, " 'Function %s in %s'" % (func.name, dllname) ! print >> self.stream, " return _api_(%s)" % ", ".join(argnames) if not self.use_decorators: print >> self.stream, "%s = %s(%s, %r, [%s]) (%s)" % \ --- 387,391 ---- print >> self.stream, "def %s(%s):" % (func.name, ", ".join(argnames)) print >> self.stream, " 'Function %s in %s'" % (func.name, dllname) ! ## print >> self.stream, " return _api_(%s)" % ", ".join(argnames) if not self.use_decorators: print >> self.stream, "%s = %s(%s, %r, [%s]) (%s)" % \ |
From: Thomas H. <th...@us...> - 2005-01-07 18:59:30
|
Update of /cvsroot/ctypes/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15190 Added Files: decorators.py Log Message: Preliminary location for decorator functions. --- NEW FILE: decorators.py --- ''' This module implements decorators for native api function calls. stdcall(restype, dllname, argtypes[, logging=False]) cdecl(restype, dllname, argtypes[, logging=False]) The decorator functions are used like this: >>> from ctypes import * >>> # wrap the GetModuleFileNameA function >>> @ stdcall(c_ulong, "kernel32", [c_ulong, POINTER(c_char), c_ulong]) ... def GetModuleFileNameA(handle=0): ... buf = create_string_buffer(256) ... if 0 == _api_(handle, buf, sizeof(buf)): ... raise WinError() ... return buf.value >>> >>> sys.executable == GetModuleFileNameA() True >>> ''' import sys from opcode import opmap, HAVE_ARGUMENT, EXTENDED_ARG LOAD_GLOBAL = opmap["LOAD_GLOBAL"] LOAD_CONST = opmap["LOAD_CONST"] import ctypes LOGGING = False def _create_func_codestring(func, doc=None): # given a function object <func>, build the source code for # another function, having the same argument list, and a function # body which contains a call to an _api_ function. # # Assuming the <func> has this definition: # def func(first, second="spam", third=42): # .... # a string containing the following code is returned: # def func(first, second="spam", third=42): # return _api_(first, second, third) import inspect args, varargs, varkw, defaults = inspect.getargspec(func) if varkw: raise TypeError, "function argument list cannot contain ** argument" if doc: return "def %s%s:\n %r\n return _api_%s" % \ (func.func_name, inspect.formatargspec(args, varargs, varkw, defaults), doc, inspect.formatargspec(args, varargs, varkw)) return "def %s%s:\n return _api_%s" % \ (func.func_name, inspect.formatargspec(args, varargs, varkw, defaults), inspect.formatargspec(args, varargs, varkw)) VERBOSE = False # print opcodes replaced def _make_constants(f, **env): # Replace 'LOAD_GLOBAL <name>' opcodes with 'LOAD_CONST <const>' # opcodes, where <const> comes from the 'name' stored in env. # # based on Raymond Hettinger's recipe 'binding constants at compile time' # http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/277940 if len(f.func_code.co_code) == 4: # Hacky way to detect an empty function body. codestring = _create_func_codestring(f, f.__doc__) d = {} exec codestring in d #print codestring f = d[f.func_name] co = f.func_code newcode = map(ord, co.co_code) newconsts = list(co.co_consts) names = co.co_names codelen = len(newcode) i = 0 while i < codelen: opcode = newcode[i] if opcode == LOAD_GLOBAL: oparg = newcode[i+1] + (newcode[i+2] << 8) name = names[oparg] if name in env: value = env[name] for pos, v in enumerate(newconsts): if v is value: break else: pos = len(newconsts) newconsts.append(value) newcode[i] = LOAD_CONST newcode[i+1] = pos & 0xFF newcode[i+2] = pos >> 8 if VERBOSE: print >> sys.stderr, "# _make_constants: %s --> %s" % (name, value) if opcode >= HAVE_ARGUMENT: i += 3 else: i += 1 codestr = ''.join(map(chr, newcode)) codeobj = type(co)(co.co_argcount, co.co_nlocals, co.co_stacksize, co.co_flags, codestr, tuple(newconsts), names, co.co_varnames, co.co_filename, co.co_name, co.co_firstlineno, co.co_lnotab, co.co_freevars, co.co_cellvars) func = type(f)(codeobj, f.func_globals, f.func_name, f.func_defaults, f.func_closure) # for introspection? ## func._api_ = env["_api_"] return func ################################################################ def stdcall(restype, dllname, argtypes, logging=LOGGING): def decorate(func): dll = getattr(ctypes.windll, dllname) api = getattr(dll, func.func_name) api.restype = restype api.argtypes = argtypes func = _make_constants(func, _api_=api) if logging: def f(*args): result = func(*args) print >> sys.stderr, "# function call: %s%s -> %s" % (func.func_name, args, result) return result return f else: return func return decorate def cdecl(restype, dllname, argtypes, logging=LOGGING): def decorate(func): dll = getattr(ctypes.cdll, dllname) api = getattr(dll, func.func_name) api.restype = restype api.argtypes = argtypes func = _make_constants(func, _api_=api) if logging: def f(*args): result = func(*args) print >> sys.stderr, func.func_name, args, "->", result return result return f else: return func return decorate ################################################################ if __name__ == "__main__": import doctest doctest.testmod() |
From: Thomas H. <th...@us...> - 2005-01-07 18:58:41
|
Update of /cvsroot/ctypes/ctypes/sandbox/tools/codegen In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15074 Modified Files: gccxmlparser.py Log Message: Convert internal names into valid Python identifiers. Index: gccxmlparser.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/sandbox/tools/codegen/gccxmlparser.py,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** gccxmlparser.py 22 Dec 2004 08:39:40 -0000 1.8 --- gccxmlparser.py 7 Jan 2005 18:58:32 -0000 1.9 *************** *** 21,25 **** def demangle(self, name): ! return "_py_" + name.replace("$", "_") def startElement(self, name, attrs): --- 21,27 ---- def demangle(self, name): ! if name.startswith("__"): ! name = "_py_" + name ! return name.replace("$", "_") def startElement(self, name, attrs): *************** *** 62,66 **** def Typedef(self, attrs): ! name = attrs["name"] typ = attrs["type"] return typedesc.Typedef(name, typ) --- 64,68 ---- def Typedef(self, attrs): ! name = self.demangle(attrs["name"]) typ = attrs["type"] return typedesc.Typedef(name, typ) *************** *** 70,74 **** def FundamentalType(self, attrs): ! name = attrs["name"] if name == "void": size = "" --- 72,76 ---- def FundamentalType(self, attrs): ! name = self.demangle(attrs["name"]) if name == "void": size = "" *************** *** 118,122 **** def Function(self, attrs): # name, returns, extern, attributes ! name = attrs["name"] returns = attrs["returns"] attributes = attrs.get("attributes", "").split() --- 120,124 ---- def Function(self, attrs): # name, returns, extern, attributes ! name = self.demangle(attrs["name"]) returns = attrs["returns"] attributes = attrs.get("attributes", "").split() *************** *** 140,144 **** def OperatorFunction(self, attrs): # name, returns, extern, attributes ! name = attrs["name"] returns = attrs["returns"] return typedesc.OperatorFunction(name, returns) --- 142,146 ---- def OperatorFunction(self, attrs): # name, returns, extern, attributes ! name = self.demangle(attrs["name"]) returns = attrs["returns"] return typedesc.OperatorFunction(name, returns) *************** *** 148,152 **** def Constructor(self, attrs): ! name = attrs["name"] return typedesc.Constructor(name) --- 150,154 ---- def Constructor(self, attrs): ! name = self.demangle(attrs["name"]) return typedesc.Constructor(name) *************** *** 155,159 **** def Method(self, attrs): # name, virtual, pure_virtual, returns ! name = attrs["name"] returns = attrs["returns"] return typedesc.Method(name, returns) --- 157,161 ---- def Method(self, attrs): # name, virtual, pure_virtual, returns ! name = self.demangle(attrs["name"]) returns = attrs["returns"] return typedesc.Method(name, returns) *************** *** 173,177 **** def Enumeration(self, attrs): # id, name ! name = attrs["name"] size = attrs["size"] align = attrs["align"] --- 175,179 ---- def Enumeration(self, attrs): # id, name ! name = self.demangle(attrs["name"]) size = attrs["size"] align = attrs["align"] *************** *** 188,192 **** def EnumValue(self, attrs): ! name = attrs["name"] value = attrs["init"] self.context[-1].add_value(name, value) --- 190,194 ---- def EnumValue(self, attrs): ! name = self.demangle(attrs["name"]) value = attrs["init"] self.context[-1].add_value(name, value) *************** *** 237,241 **** def Field(self, attrs): # name, type ! name = attrs["name"] typ = attrs["type"] bits = attrs.get("bits", None) --- 239,243 ---- def Field(self, attrs): # name, type ! name = self.demangle(attrs["name"]) typ = attrs["type"] bits = attrs.get("bits", None) |
From: Thomas H. <th...@us...> - 2005-01-07 18:57:34
|
Update of /cvsroot/ctypes/ctypes/sandbox/tools/codegen In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14897 Modified Files: codegenerator.py Log Message: Import decorators from their new, official location. Use %r to output a dll name, it may contain backslashes. Import fundamental types from ctypes, when needed. Fix the output file header. Index: codegenerator.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/sandbox/tools/codegen/codegenerator.py,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** codegenerator.py 7 Jan 2005 16:10:05 -0000 1.15 --- codegenerator.py 7 Jan 2005 18:57:22 -0000 1.16 *************** *** 143,147 **** return t.name - # Is this needed? ##renames = { --- 143,146 ---- *************** *** 354,358 **** if self._stdcall_defined: return ! print >> self.stream, "from deco import stdcall" self._stdcall_defined = True --- 353,357 ---- if self._stdcall_defined: return ! print >> self.stream, "from ctypes.decorators import stdcall" self._stdcall_defined = True *************** *** 361,365 **** if self._cdecl_defined: return ! print >> self.stream, "from deco import cdecl" self._cdecl_defined = True --- 360,364 ---- if self._cdecl_defined: return ! print >> self.stream, "from ctypes.decorators import cdecl" self._cdecl_defined = True *************** *** 382,386 **** print >> self.stream if self.use_decorators: ! print >> self.stream, "@ %s(%s, '%s', [%s])" % \ (cc, type_name(func.returns), dllname, ", ".join(args)) argnames = ["p%d" % i for i in range(1, 1+len(args))] --- 381,385 ---- print >> self.stream if self.use_decorators: ! print >> self.stream, "@ %s(%s, %r, [%s])" % \ (cc, type_name(func.returns), dllname, ", ".join(args)) argnames = ["p%d" % i for i in range(1, 1+len(args))] *************** *** 390,394 **** print >> self.stream, " return _api_(%s)" % ", ".join(argnames) if not self.use_decorators: ! print >> self.stream, "%s = %s(%s, '%s', [%s]) (%s)" % \ (func.name, cc, type_name(func.returns), dllname, ", ".join(args), func.name) print >> self.stream --- 389,393 ---- print >> self.stream, " return _api_(%s)" % ", ".join(argnames) if not self.use_decorators: ! print >> self.stream, "%s = %s(%s, %r, [%s]) (%s)" % \ (func.name, cc, type_name(func.returns), dllname, ", ".join(args), func.name) print >> self.stream *************** *** 401,404 **** --- 400,408 ---- def FundamentalType(self, item): + if item in self.done: + return + name = ctypes_names[item.name] + if name != "None": + print >> self.stream, "from ctypes import %s" % name self.done.add(item) *************** *** 497,504 **** gen = Generator(outfile, use_decorators=use_decorators) # output header ! print >> outfile, "from ctypes import *" ! print >> outfile, "class _com_interface(Structure): # fake" ! print >> outfile, " _fields_ = [('lpVtbl', c_void_p)]" ! print >> outfile, "def STDMETHOD(*args,**kw): pass # fake" print >> outfile loops = gen.generate_code(items, --- 501,506 ---- gen = Generator(outfile, use_decorators=use_decorators) # output header ! print >> outfile, "from ctypes import Structure, Union, CFUNCTYPE, WINFUNCTYPE, POINTER" ! print >> outfile, "from ctypes import sizeof, alignment, c_void_p, c_int" print >> outfile loops = gen.generate_code(items, |
From: Thomas H. <th...@us...> - 2005-01-07 16:10:15
|
Update of /cvsroot/ctypes/ctypes/sandbox/tools/codegen In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6971 Modified Files: codegenerator.py Log Message: Accept a list of dlls to search for exported functions. Index: codegenerator.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/sandbox/tools/codegen/codegenerator.py,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** codegenerator.py 7 Jan 2005 15:34:33 -0000 1.14 --- codegenerator.py 7 Jan 2005 16:10:05 -0000 1.15 *************** *** 162,201 **** ) - 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 - msvcrt - msimg32 - netapi32 - rpcrt4""".split() - ##glut32 - - ##rpcndr - ##ntdll - ##dll_names = "libxml2".split() - - from ctypes import CDLL - searched_dlls = [CDLL(name) for name in dll_names] - class Generator(object): def __init__(self, stream, use_decorators=False): --- 162,165 ---- *************** *** 375,379 **** def find_dllname(self, name): ! for dll in searched_dlls: try: getattr(dll, name) --- 339,343 ---- def find_dllname(self, name): ! for dll in self.searched_dlls: try: getattr(dll, name) *************** *** 457,461 **** self.generate(item) ! def generate_code(self, items, known_symbols): items = set(items) if known_symbols: --- 421,425 ---- self.generate(item) ! def generate_code(self, items, known_symbols, searched_dlls): items = set(items) if known_symbols: *************** *** 463,466 **** --- 427,431 ---- else: self.known_symbols = {} + self.searched_dlls = searched_dlls loops = 0 while items: *************** *** 498,502 **** verbose=False, use_decorators=False, ! known_symbols=None): # expressions is a sequence of compiled regular expressions, # symbols is a sequence of names --- 463,468 ---- verbose=False, use_decorators=False, ! known_symbols=None, ! searched_dlls=None): # expressions is a sequence of compiled regular expressions, # symbols is a sequence of names *************** *** 536,540 **** print >> outfile, "def STDMETHOD(*args,**kw): pass # fake" print >> outfile ! loops = gen.generate_code(items, known_symbols) if verbose: gen.print_stats(sys.stderr) --- 502,508 ---- print >> outfile, "def STDMETHOD(*args,**kw): pass # fake" print >> outfile ! loops = gen.generate_code(items, ! known_symbols, ! searched_dlls) if verbose: gen.print_stats(sys.stderr) |
From: Thomas H. <th...@us...> - 2005-01-07 16:08:18
|
Update of /cvsroot/ctypes/ctypes/sandbox/tools/codegen In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6511 Modified Files: xml2py.py Log Message: Make the --dll and --windows-dlls options work. Add a -m option which allows to specify Python modules containing symbols that will be imported instead of generated. Current defaults are ctypes and comtypes or ctypes.com. Index: xml2py.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/sandbox/tools/codegen/xml2py.py,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** xml2py.py 7 Jan 2005 15:34:32 -0000 1.6 --- xml2py.py 7 Jan 2005 16:08:09 -0000 1.7 *************** *** 6,9 **** --- 6,40 ---- ################################################################ + 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 + msvcrt + msimg32 + netapi32 + rpcrt4""".split() + ##glut32 + + ##rpcndr + ##ntdll def main(args=None): *************** *** 12,16 **** def windows_dlls(option, opt, value, parser): ! parser.values.dlls.extend("kernel32 gdi32 user32".split()) parser = OptionParser("usage: %prog [options] xmlfile") --- 43,47 ---- def windows_dlls(option, opt, value, parser): ! parser.values.dlls.extend(windows_dll_names) parser = OptionParser("usage: %prog [options] xmlfile") *************** *** 18,26 **** action="callback", callback=windows_dlls, ! help="add all standard windows dlls") parser.add_option("--dll", dest="dlls", action="append", default=[]) parser.add_option("-s", dest="symbols", --- 49,60 ---- action="callback", callback=windows_dlls, ! help="add all standard windows dlls to the searched dlls list") ! parser.add_option("--dll", dest="dlls", + help="dlls to search for exported functions", action="append", default=[]) + parser.add_option("-s", dest="symbols", *************** *** 30,33 **** --- 64,68 ---- "(if neither symbols nor expressions are specified, everything will be included)", default=None) + parser.add_option("-r", dest="expressions", *************** *** 37,40 **** --- 72,76 ---- "(if neither symbols nor expressions are specified, everything will be included)", default=None) + parser.add_option("-o", dest="output", *************** *** 54,57 **** --- 90,107 ---- default=False) + try: + import comtypes + except ImportError: + default_modules = ["ctypes", "ctypes.com"] + else: + default_modules = ["ctypes", "comtypes"] + + parser.add_option("-m", + dest="modules", + metavar="module", + help="Python module(s) containing symbols which will be imported instead of generated", + action="append", + default=default_modules) + options, files = parser.parse_args(args[1:]) *************** *** 70,75 **** stream.write("# flags '%s'\n" % " ".join(sys.argv[1:])) ! import ctypes ! known_symbols = ctypes.__dict__ generate_code(files[0], stream, --- 120,133 ---- stream.write("# flags '%s'\n" % " ".join(sys.argv[1:])) ! known_symbols = {} ! ! from ctypes import CDLL ! dlls = [CDLL(name) for name in options.dlls] ! ! for name in options.modules: ! mod = __import__(name) ! for submodule in name.split(".")[1:]: ! mod = getattr(mod, submodule) ! known_symbols.update(mod.__dict__) generate_code(files[0], stream, *************** *** 78,82 **** verbose=options.verbose, use_decorators=options.use_decorators, ! known_symbols=known_symbols) --- 136,141 ---- verbose=options.verbose, use_decorators=options.use_decorators, ! known_symbols=known_symbols, ! searched_dlls=dlls) |
From: Thomas H. <th...@us...> - 2005-01-07 15:34:47
|
Update of /cvsroot/ctypes/ctypes/sandbox/tools/codegen In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31357 Modified Files: xml2py.py codegenerator.py Log Message: generate_code accepts known_symbols, which must be a dict mapping names to symbols (like a module's __dict__). These symbols stop code generation, and instead code is generated that imports this name. Index: xml2py.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/sandbox/tools/codegen/xml2py.py,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** xml2py.py 17 Dec 2004 08:27:40 -0000 1.5 --- xml2py.py 7 Jan 2005 15:34:32 -0000 1.6 *************** *** 70,78 **** stream.write("# flags '%s'\n" % " ".join(sys.argv[1:])) generate_code(files[0], stream, symbols=options.symbols, expressions=options.expressions, verbose=options.verbose, ! use_decorators=options.use_decorators) --- 70,82 ---- stream.write("# flags '%s'\n" % " ".join(sys.argv[1:])) + import ctypes + known_symbols = ctypes.__dict__ + generate_code(files[0], stream, symbols=options.symbols, expressions=options.expressions, verbose=options.verbose, ! use_decorators=options.use_decorators, ! known_symbols=known_symbols) Index: codegenerator.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/sandbox/tools/codegen/codegenerator.py,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** codegenerator.py 7 Jan 2005 15:02:22 -0000 1.13 --- codegenerator.py 7 Jan 2005 15:34:33 -0000 1.14 *************** *** 442,445 **** --- 442,453 ---- def generate(self, item): + if item in self.done: + return + name = getattr(item, "name", None) + if name in self.known_symbols: + print >> self.stream, "# %s is in known_symbols" % name + print >> self.stream, "from %s import %s" % (self.known_symbols[name].__module__, name) + self.done.add(item) + return mth = getattr(self, type(item).__name__) mth(item) *************** *** 449,454 **** self.generate(item) ! def generate_code(self, items): items = set(items) loops = 0 while items: --- 457,466 ---- self.generate(item) ! def generate_code(self, items, known_symbols): items = set(items) + if known_symbols: + self.known_symbols = known_symbols + else: + self.known_symbols = {} loops = 0 while items: *************** *** 486,490 **** verbose=False, use_decorators=False, ! exclude=None): # expressions is a sequence of compiled regular expressions, # symbols is a sequence of names --- 498,502 ---- verbose=False, use_decorators=False, ! known_symbols=None): # expressions is a sequence of compiled regular expressions, # symbols is a sequence of names *************** *** 524,528 **** print >> outfile, "def STDMETHOD(*args,**kw): pass # fake" print >> outfile ! loops = gen.generate_code(items) if verbose: gen.print_stats(sys.stderr) --- 536,540 ---- print >> outfile, "def STDMETHOD(*args,**kw): pass # fake" print >> outfile ! loops = gen.generate_code(items, known_symbols) if verbose: gen.print_stats(sys.stderr) |
From: Thomas H. <th...@us...> - 2005-01-07 15:02:31
|
Update of /cvsroot/ctypes/ctypes/sandbox/tools/codegen In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24530 Modified Files: codegenerator.py Log Message: Structure sub-subclasses automatically inherit the fields from their base class. Remove the call_as hack - apply decorators manually when use_decorators is False. Prepare for a exclude list, for symbols not the generate. Index: codegenerator.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/sandbox/tools/codegen/codegenerator.py,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** codegenerator.py 7 Jan 2005 14:42:46 -0000 1.12 --- codegenerator.py 7 Jan 2005 15:02:22 -0000 1.13 *************** *** 338,344 **** base = body.struct.bases[0].name self.StructureBody(body.struct.bases[0].get_body()) ! print >> self.stream, "%s._fields_ = %s._fields_ + [" % (body.struct.name, base) ! else: ! print >> self.stream, "%s._fields_ = [" % body.struct.name # unnamed fields will get autogenerated names "_", "_1". "_2", "_3", ... unnamed_index = 0 --- 338,342 ---- base = body.struct.bases[0].name self.StructureBody(body.struct.bases[0].get_body()) ! print >> self.stream, "%s._fields_ = [" % body.struct.name # unnamed fields will get autogenerated names "_", "_1". "_2", "_3", ... unnamed_index = 0 *************** *** 388,398 **** return None - _call_as_defined = False - def need_call_as(self): - if self._call_as_defined: - return - print >> self.stream, "from deco import call_as" - self._call_as_defined = True - _stdcall_defined = False def need_stdcall(self): --- 386,389 ---- *************** *** 426,437 **** cc = "cdecl" print >> self.stream - # decorator if self.use_decorators: print >> self.stream, "@ %s(%s, '%s', [%s])" % \ (cc, type_name(func.returns), dllname, ", ".join(args)) - else: - self.need_call_as() - print >> self.stream, "[ call_as(%s(%s, '%s', [%s])) ]" % \ - (cc, type_name(func.returns), dllname, ", ".join(args)) argnames = ["p%d" % i for i in range(1, 1+len(args))] # function definition --- 417,423 ---- *************** *** 439,442 **** --- 425,431 ---- print >> self.stream, " 'Function %s in %s'" % (func.name, dllname) print >> self.stream, " return _api_(%s)" % ", ".join(argnames) + if not self.use_decorators: + print >> self.stream, "%s = %s(%s, '%s', [%s]) (%s)" % \ + (func.name, cc, type_name(func.returns), dllname, ", ".join(args), func.name) print >> self.stream self._functiontypes += 1 *************** *** 473,476 **** --- 462,467 ---- def print_stats(self, stream): + total = self._structures + self._functiontypes + self._enumtypes + self._typedefs +\ + self._pointertypes + self._arraytypes print >> stream, "###########################" print >> stream, "# Symbols defined:" *************** *** 484,489 **** print >> stream, "# unknown functions: %5d" % self._notfound_functiontypes print >> stream, "#" - total = self._structures + self._functiontypes + self._enumtypes + self._typedefs +\ - self._pointertypes + self._arraytypes print >> stream, "# Total symbols: %5d" % total print >> stream, "###########################" --- 475,478 ---- *************** *** 491,498 **** ################################################################ ! def generate_code(xmlfile, outfile, ! expressions=None, symbols=None, verbose=False, ! use_decorators=False): # expressions is a sequence of compiled regular expressions, # symbols is a sequence of names --- 480,490 ---- ################################################################ ! def generate_code(xmlfile, ! outfile, ! expressions=None, ! symbols=None, verbose=False, ! use_decorators=False, ! exclude=None): # expressions is a sequence of compiled regular expressions, # symbols is a sequence of names *************** *** 528,531 **** --- 520,526 ---- # output header print >> outfile, "from ctypes import *" + print >> outfile, "class _com_interface(Structure): # fake" + print >> outfile, " _fields_ = [('lpVtbl', c_void_p)]" + print >> outfile, "def STDMETHOD(*args,**kw): pass # fake" print >> outfile loops = gen.generate_code(items) |
From: Thomas H. <th...@us...> - 2005-01-07 14:42:59
|
Update of /cvsroot/ctypes/ctypes/sandbox/tools/codegen In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19437 Modified Files: codegenerator.py Log Message: const and volatile are ignored. Index: codegenerator.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/sandbox/tools/codegen/codegenerator.py,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** codegenerator.py 6 Jan 2005 11:00:37 -0000 1.11 --- codegenerator.py 7 Jan 2005 14:42:46 -0000 1.12 *************** *** 1,2 **** --- 1,5 ---- + # Create ctypes wrapper code for abstract type descriptions. + # Type descriptions are collections of typedesc instances. + import typedesc, sys *************** *** 126,130 **** return "CFUNCTYPE(%s)" % ", ".join(args) elif isinstance(t, typedesc.CvQualifiedType): ! return "const(%s)" % type_name(t.typ) elif isinstance(t, typedesc.FundamentalType): return ctypes_names[t.name] --- 129,134 ---- return "CFUNCTYPE(%s)" % ", ".join(args) elif isinstance(t, typedesc.CvQualifiedType): ! # const and volatile are ignored ! return "%s" % type_name(t.typ) elif isinstance(t, typedesc.FundamentalType): return ctypes_names[t.name] *************** *** 524,529 **** # output header print >> outfile, "from ctypes import *" - print >> outfile, "def const(x): return x" - print >> outfile, "def volatile(x): return x" print >> outfile loops = gen.generate_code(items) --- 528,531 ---- |
From: Thomas H. <th...@us...> - 2005-01-06 11:00:46
|
Update of /cvsroot/ctypes/ctypes/sandbox/tools/codegen In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4247 Modified Files: codegenerator.py Log Message: STDMETHOD 3rd arg is now a sequence of argtypes. Quote the dll name for function calls, since it is a string. Index: codegenerator.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/sandbox/tools/codegen/codegenerator.py,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** codegenerator.py 22 Dec 2004 08:45:29 -0000 1.10 --- codegenerator.py 6 Jan 2005 11:00:37 -0000 1.11 *************** *** 358,362 **** for m in methods: args = [type_name(a) for a in m.arguments] ! print >> self.stream, " STDMETHOD(%s, '%s', %s)," % ( type_name(m.returns), m.name, --- 358,362 ---- for m in methods: args = [type_name(a) for a in m.arguments] ! print >> self.stream, " STDMETHOD(%s, '%s', [%s])," % ( type_name(m.returns), m.name, *************** *** 424,436 **** # decorator if self.use_decorators: ! print >> self.stream, "@ %s(%s, %s, [%s])" % \ (cc, type_name(func.returns), dllname, ", ".join(args)) else: self.need_call_as() ! print >> self.stream, "[ call_as(%s(%s, %s, [%s])) ]" % \ (cc, type_name(func.returns), dllname, ", ".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)) print >> self.stream, " return _api_(%s)" % ", ".join(argnames) print >> self.stream --- 424,437 ---- # decorator if self.use_decorators: ! print >> self.stream, "@ %s(%s, '%s', [%s])" % \ (cc, type_name(func.returns), dllname, ", ".join(args)) else: self.need_call_as() ! print >> self.stream, "[ call_as(%s(%s, '%s', [%s])) ]" % \ (cc, type_name(func.returns), dllname, ", ".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)) + print >> self.stream, " 'Function %s in %s'" % (func.name, dllname) print >> self.stream, " return _api_(%s)" % ", ".join(argnames) print >> self.stream |
From: Thomas H. <th...@us...> - 2005-01-04 18:28:17
|
Update of /cvsroot/ctypes/misc/misc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20790 Modified Files: import.c Log Message: *** empty log message *** Index: import.c =================================================================== RCS file: /cvsroot/ctypes/misc/misc/import.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** import.c 4 Jan 2005 12:48:01 -0000 1.3 --- import.c 4 Jan 2005 18:28:01 -0000 1.4 *************** *** 2,5 **** --- 2,7 ---- import.17.c - test suite works with new test some cleanup and error checking + import.18.c - passes (most) tests on OSX on SF compile farm. + more cleanup. */ *************** *** 1393,1406 **** } ! /* case_ok(char* buf, int len, int namelen, char* name) ! * The arguments here are tricky, best shown by example: ! * /a/b/c/d/e/f/g/h/i/j/k/some_long_module_name.py\0 ! * ^ ^ ^ ^ ! * |--------------------- buf ---------------------| ! * |------------------- len ------------------| ! * |------ name -------| ! * |----- namelen -----| ! * buf is the full path, but len only counts up to (& exclusive of) the ! * extension. name is the module name, also exclusive of extension. * * We've already done a successful stat() or fopen() on buf, so know that --- 1395,1399 ---- } ! /* case_ok(PyObject *fname, char* name) * * We've already done a successful stat() or fopen() on buf, so know that *************** *** 1417,1435 **** */ - /* First we may need a pile of platform-specific header files; the sequence - * of #if's here should match the sequence in the body of case_ok(). - */ - #if defined(MS_WINDOWS) || defined(__CYGWIN__) - - #elif defined(DJGPP) - - #elif defined(__MACH__) && defined(__APPLE__) && defined(HAVE_DIRENT_H) - - #elif defined(PYOS_OS2) - - #elif defined(RISCOS) - - #endif - /* MS_WINDOWS || __CYGWIN__ */ #if defined(MS_WINDOWS) || defined(__CYGWIN__) --- 1410,1413 ---- *************** *** 1533,1537 **** struct dirent *dp; char dirname[MAXPATHLEN + 1]; - int dirlen; char *nameWithExt; --- 1511,1514 ---- |
From: Thomas H. <th...@us...> - 2005-01-04 12:48:16
|
Update of /cvsroot/ctypes/misc/misc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5164 Modified Files: import.c Log Message: *** empty log message *** Index: import.c =================================================================== RCS file: /cvsroot/ctypes/misc/misc/import.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** import.c 4 Jan 2005 12:25:45 -0000 1.2 --- import.c 4 Jan 2005 12:48:01 -0000 1.3 *************** *** 1534,1555 **** char dirname[MAXPATHLEN + 1]; int dirlen; ! char *cp; if (Py_GETENV("PYTHONCASEOK") != NULL) return 1; ! /* XXX check size */ strcpy(dirname, PyString_AS_STRING(fname)); ! cp = strrchr(dirname, SEP); ! if (cp) ! *cp = '\0'; ! else ! dirname[0] = '\0'; ! ! dirlen = strlen(dirname); ! /* Copy the dir component into dirname; substitute "." if empty */ ! if (dirlen <= 0) { dirname[0] = '.'; dirname[1] = '\0'; } --- 1534,1551 ---- char dirname[MAXPATHLEN + 1]; int dirlen; ! char *nameWithExt; if (Py_GETENV("PYTHONCASEOK") != NULL) return 1; ! /* XXX check size of dirname buffer */ strcpy(dirname, PyString_AS_STRING(fname)); ! nameWithExt = strrchr(dirname, SEP); ! if (nameWithExt) ! *nameWithExt++ = '\0'; ! else { dirname[0] = '.'; dirname[1] = '\0'; + nameWithExt = PyString_AS_STRING(fname); } *************** *** 1557,1570 **** dirp = opendir(dirname); if (dirp) { - char *nameWithExt = PyString_AS_STRING(fname) + len - namelen; while ((dp = readdir(dirp)) != NULL) { ! const int thislen = ! #ifdef _DIRENT_HAVE_D_NAMELEN ! dp->d_namlen; ! #else ! strlen(dp->d_name); ! #endif ! if (thislen >= namelen && ! strcmp(dp->d_name, nameWithExt) == 0) { (void)closedir(dirp); return 1; /* Found */ --- 1553,1558 ---- dirp = opendir(dirname); if (dirp) { while ((dp = readdir(dirp)) != NULL) { ! if (strcmp(dp->d_name, nameWithExt) == 0) { (void)closedir(dirp); return 1; /* Found */ |
From: Thomas H. <th...@us...> - 2005-01-04 12:25:57
|
Update of /cvsroot/ctypes/misc/misc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1619 Modified Files: import.c Log Message: Cleanup. Index: import.c =================================================================== RCS file: /cvsroot/ctypes/misc/misc/import.c,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** import.c 4 Jan 2005 12:16:45 -0000 1.1.1.1 --- import.c 4 Jan 2005 12:25:45 -0000 1.2 *************** *** 1441,1468 **** static int - X_case_ok(PyObject *fname, char *name) - { - char dirname[MAXPATHLEN + 1]; - int dirlen; - char *cp; - - strcpy(dirname, PyString_AS_STRING(fname)); - cp = strrchr(dirname, SEP); - if (cp) - *cp = '\0'; - else - dirname[0] = '\0'; - - dirlen = strlen(dirname); - /* Copy the dir component into dirname; substitute "." if empty */ - if (dirlen <= 0) { - dirname[0] = '.'; - dirname[1] = '\0'; - } - printf("dirname '%s'\n", dirname); - return 0; - } - - static int case_ok(PyObject *fname, char *name) { --- 1441,1444 ---- *************** *** 1473,1480 **** #endif - #ifdef _DEBUG - X_case_ok(fname, name); - #endif - if (Py_GETENV("PYTHONCASEOK") != NULL) return 1; --- 1449,1452 ---- *************** *** 1561,1572 **** struct dirent *dp; char dirname[MAXPATHLEN + 1]; ! const int dirlen; ! if (Py_GETENV("PYTHONCASEOK") != NULL) return 1; ! namelen = strlen(name); ! len = strlen(PyString_AS_STRING(fname)); ! dirlen = len - namelen - 1; /* don't want trailing SEP */ /* Copy the dir component into dirname; substitute "." if empty */ if (dirlen <= 0) { --- 1533,1551 ---- struct dirent *dp; char dirname[MAXPATHLEN + 1]; ! int dirlen; ! char *cp; ! if (Py_GETENV("PYTHONCASEOK") != NULL) return 1; ! /* XXX check size */ ! strcpy(dirname, PyString_AS_STRING(fname)); ! cp = strrchr(dirname, SEP); ! if (cp) ! *cp = '\0'; ! else ! dirname[0] = '\0'; ! ! dirlen = strlen(dirname); /* Copy the dir component into dirname; substitute "." if empty */ if (dirlen <= 0) { *************** *** 1574,1582 **** dirname[1] = '\0'; } ! else { ! assert(dirlen <= MAXPATHLEN); ! memcpy(dirname, PyString_AS_STRING(fname), dirlen); ! dirname[dirlen] = '\0'; ! } /* Open the directory and search the entries for an exact match. */ dirp = opendir(dirname); --- 1553,1557 ---- dirname[1] = '\0'; } ! /* Open the directory and search the entries for an exact match. */ dirp = opendir(dirname); *************** *** 1586,1592 **** const int thislen = #ifdef _DIRENT_HAVE_D_NAMELEN ! dp->d_namlen; #else ! strlen(dp->d_name); #endif if (thislen >= namelen && --- 1561,1567 ---- const int thislen = #ifdef _DIRENT_HAVE_D_NAMELEN ! dp->d_namlen; #else ! strlen(dp->d_name); #endif if (thislen >= namelen && |
From: Thomas H. <th...@us...> - 2004-12-30 18:03:59
|
Update of /cvsroot/ctypes/ctypes/docs In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9987 Modified Files: tutorial.stx Log Message: c_string and c_buffer are replaced by create_string_buffer. Index: tutorial.stx =================================================================== RCS file: /cvsroot/ctypes/ctypes/docs/tutorial.stx,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** tutorial.stx 22 Jul 2004 17:27:55 -0000 1.23 --- tutorial.stx 30 Dec 2004 18:03:50 -0000 1.24 *************** *** 230,234 **** You should be careful, however, not to pass them to functions expecting pointers to mutable memory. If you need mutable memory ! blocks, ctypes has a 'c_buffer' function which creates these in various ways. The current memory block contents can be accessed (or changed) with the 'raw' property, if you want to access it as --- 230,234 ---- You should be careful, however, not to pass them to functions expecting pointers to mutable memory. If you need mutable memory ! blocks, ctypes has a 'create_string_buffer' function which creates these in various ways. The current memory block contents can be accessed (or changed) with the 'raw' property, if you want to access it as *************** *** 236,248 **** >>> from ctypes import * ! >>> p = c_buffer(3) # create a 3 byte buffer, initialized to NUL bytes >>> print sizeof(p), repr(p.raw) 3 '\x00\x00\x00' ! >>> p = c_buffer("Hello") # create a buffer containing a NUL terminated string >>> print sizeof(p), repr(p.raw) 6 'Hello\x00' >>> print repr(p.value) 'Hello' ! >>> p = c_buffer("Hello", 10) # create a 10 byte buffer >>> print sizeof(p), repr(p.raw) 10 'Hello\x00\x00\x00\x00\x00' --- 236,248 ---- >>> from ctypes import * ! >>> p = create_string_buffer(3) # create a 3 byte buffer, initialized to NUL bytes >>> print sizeof(p), repr(p.raw) 3 '\x00\x00\x00' ! >>> p = create_string_buffer("Hello") # create a buffer containing a NUL terminated string >>> print sizeof(p), repr(p.raw) 6 'Hello\x00' >>> print repr(p.value) 'Hello' ! >>> p = create_string_buffer("Hello", 10) # create a 10 byte buffer >>> print sizeof(p), repr(p.raw) 10 'Hello\x00\x00\x00\x00\x00' *************** *** 252,255 **** --- 252,262 ---- >>> + The 'create_string_buffer' function replaces the 'c_buffer' + function (which is still available as an alias to the new + function), as well as the 'c_string' function from earlier ctypes + releases. To create a mutable memory block containing unicode + characters of the C type 'wchar_t' use the 'create_unicode_buffer' + function. + Calling functions, continued *************** *** 445,449 **** >>> i = c_int() >>> f = c_float() ! >>> s = c_string('\000' * 32) >>> print i.value, f.value, repr(s.value) 0 0.0 '' --- 452,456 ---- >>> i = c_int() >>> f = c_float() ! >>> s = create_string_buffer('\000' * 32) >>> print i.value, f.value, repr(s.value) 0 0.0 '' |
From: Thomas H. <th...@us...> - 2004-12-30 13:36:41
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17927 Modified Files: _ctypes.c Log Message: Assinging None to a POINTER structure field makes a NULL pointer. Index: _ctypes.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes.c,v retrieving revision 1.194 retrieving revision 1.195 diff -C2 -d -r1.194 -r1.195 *** _ctypes.c 30 Dec 2004 13:03:51 -0000 1.194 --- _ctypes.c 30 Dec 2004 13:36:25 -0000 1.195 *************** *** 1901,1904 **** --- 1901,1908 ---- return _CData_set(dst, type, setfunc, ob, size, ptr); + } else if (value == Py_None && PointerTypeObject_Check(type)) { + *(void **)dst->b_ptr = NULL; + Py_INCREF(Py_None); + return Py_None; } else { PyErr_Format(PyExc_TypeError, |
From: Thomas H. <th...@us...> - 2004-12-30 13:04:11
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11835 Modified Files: _ctypes.c Log Message: Prevent NULL pointer access when assigning to pointer instances. Index: _ctypes.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes.c,v retrieving revision 1.193 retrieving revision 1.194 diff -C2 -d -r1.193 -r1.194 *** _ctypes.c 17 Dec 2004 13:08:23 -0000 1.193 --- _ctypes.c 30 Dec 2004 13:03:51 -0000 1.194 *************** *** 3238,3241 **** --- 3238,3247 ---- return -1; } + + if (*(void **)self->b_ptr == NULL) { + PyErr_SetString(PyExc_ValueError, + "NULL pointer access"); + return -1; + } stgdict = PyObject_stgdict((PyObject *)self); |
From: Thomas H. <th...@us...> - 2004-12-22 08:45:38
|
Update of /cvsroot/ctypes/ctypes/sandbox/tools/codegen In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17524 Modified Files: codegenerator.py Log Message: fix typo. Index: codegenerator.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/sandbox/tools/codegen/codegenerator.py,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** codegenerator.py 22 Dec 2004 08:44:27 -0000 1.9 --- codegenerator.py 22 Dec 2004 08:45:29 -0000 1.10 *************** *** 103,107 **** raise PackingError, "PACKING FAILED: %s" % details ! def _type_name(t): # Return a string, containing an expression which can be used to # refer to the type. Assumes the ctypes.* namespace is available. --- 103,107 ---- raise PackingError, "PACKING FAILED: %s" % details ! def type_name(t): # Return a string, containing an expression which can be used to # refer to the type. Assumes the ctypes.* namespace is available. |