ctypes-commit Mailing List for ctypes (Page 80)
Brought to you by:
theller
You can subscribe to this list here.
2004 |
Jan
|
Feb
|
Mar
|
Apr
(8) |
May
(90) |
Jun
(143) |
Jul
(106) |
Aug
(94) |
Sep
(84) |
Oct
(163) |
Nov
(60) |
Dec
(58) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2005 |
Jan
(128) |
Feb
(79) |
Mar
(227) |
Apr
(192) |
May
(179) |
Jun
(41) |
Jul
(53) |
Aug
(103) |
Sep
(28) |
Oct
(38) |
Nov
(81) |
Dec
(17) |
2006 |
Jan
(184) |
Feb
(111) |
Mar
(188) |
Apr
(67) |
May
(58) |
Jun
(123) |
Jul
(73) |
Aug
|
Sep
|
Oct
(1) |
Nov
|
Dec
|
From: Thomas H. <th...@us...> - 2004-12-22 08:44:38
|
Update of /cvsroot/ctypes/ctypes/sandbox/tools/codegen In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17305 Modified Files: codegenerator.py Log Message: Add a dummy function for volatile. Import stdcall, cdecl, and call_as symbols only when needed. Index: codegenerator.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/sandbox/tools/codegen/codegenerator.py,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** codegenerator.py 17 Dec 2004 09:04:01 -0000 1.8 --- codegenerator.py 22 Dec 2004 08:44:27 -0000 1.9 *************** *** 139,142 **** --- 139,143 ---- return t.name + # Is this needed? ##renames = { *************** *** 144,153 **** ## } - ##def type_name(t): - ## result = _type_name(t) - ## return renames.get(result, result) - - type_name = _type_name - def get_real_type(tp): if type(tp) is typedesc.Typedef: --- 145,148 ---- *************** *** 389,392 **** --- 384,408 ---- 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): + if self._stdcall_defined: + return + print >> self.stream, "from deco import stdcall" + self._stdcall_defined = True + + _cdecl_defined = False + def need_cdecl(self): + if self._cdecl_defined: + return + print >> self.stream, "from deco import cdecl" + self._cdecl_defined = True + _functiontypes = 0 _notfound_functiontypes = 0 *************** *** 400,405 **** --- 416,423 ---- args = [type_name(a) for a in func.arguments] if "__stdcall__" in func.attributes: + self.need_stdcall() cc = "stdcall" else: + self.need_cdecl() cc = "cdecl" print >> self.stream *************** *** 409,412 **** --- 427,431 ---- (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)) *************** *** 504,513 **** # output header print >> outfile, "from ctypes import *" - ## print >> outfile, "from _support import STDCALL, CDECL" - if use_decorators: - print >> outfile, "from deco import stdcall" - else: - print >> outfile, "from deco import stdcall, call_as" print >> outfile, "def const(x): return x" print >> outfile loops = gen.generate_code(items) --- 523,528 ---- # 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) |
From: Thomas H. <th...@us...> - 2004-12-22 08:39:49
|
Update of /cvsroot/ctypes/ctypes/sandbox/tools/codegen In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16464 Modified Files: typedesc.py gccxmlparser.py Log Message: Fix the handling of 'const' and 'volatile' modifiers. Index: typedesc.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/sandbox/tools/codegen/typedesc.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** typedesc.py 8 Dec 2004 16:09:57 -0000 1.2 --- typedesc.py 22 Dec 2004 08:39:39 -0000 1.3 *************** *** 117,123 **** class CvQualifiedType(object): ! def __init__(self, typ, attrib): self.typ = typ ! self.attrib = attrib class Enumeration(object): --- 117,124 ---- class CvQualifiedType(object): ! def __init__(self, typ, const, volatile): self.typ = typ ! self.const = const ! self.volatile = volatile class Enumeration(object): Index: gccxmlparser.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/sandbox/tools/codegen/gccxmlparser.py,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** gccxmlparser.py 7 Dec 2004 08:25:26 -0000 1.7 --- gccxmlparser.py 22 Dec 2004 08:39:40 -0000 1.8 *************** *** 107,113 **** # id, type, [const|volatile] typ = attrs["type"] ! ## const = attrs["const"] ! ## volatile = attrs["volatile"] ! return typedesc.CvQualifiedType(typ, "xxx") def _fixup_CvQualifiedType(self, c): --- 107,113 ---- # id, type, [const|volatile] typ = attrs["type"] ! const = attrs.get("const", None) ! volatile = attrs.get("volatile", None) ! return typedesc.CvQualifiedType(typ, const, volatile) def _fixup_CvQualifiedType(self, c): |
From: Thomas H. <th...@us...> - 2004-12-17 13:08:39
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31484 Modified Files: ctypes.h callproc.c _ctypes.c Log Message: Move some functions from _ctypes.c into callbacks.c so that they can be static. Index: ctypes.h =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/ctypes.h,v retrieving revision 1.65 retrieving revision 1.66 diff -C2 -d -r1.65 -r1.66 *** ctypes.h 2 Dec 2004 19:51:32 -0000 1.65 --- ctypes.h 17 Dec 2004 13:08:23 -0000 1.66 *************** *** 123,131 **** extern PyMethodDef module_methods[]; - extern PyObject *sizeof_func(PyObject *self, PyObject *obj); - extern PyObject *align_func(PyObject *self, PyObject *obj); - extern PyObject *byref(PyObject *self, PyObject *obj); - extern PyObject *addressof(PyObject *self, PyObject *obj); - typedef PyObject *(* GETFUNC)(void *, unsigned size); typedef PyObject *(* SETFUNC)(void *, PyObject *value, unsigned size); --- 123,126 ---- Index: callproc.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/callproc.c,v retrieving revision 1.122 retrieving revision 1.123 diff -C2 -d -r1.122 -r1.123 *** callproc.c 2 Dec 2004 20:57:29 -0000 1.122 --- callproc.c 17 Dec 2004 13:08:23 -0000 1.123 *************** *** 1219,1226 **** } ! static char alignment_doc[] = ! "alignment(C type) -> integer\n" ! "alignment(C instance) -> integer\n" ! "Return the alignment requirements of a C instance"; static char sizeof_doc[] = "sizeof(C type) -> integer\n" --- 1219,1225 ---- } ! /***************************************************************** ! * functions ! */ static char sizeof_doc[] = "sizeof(C type) -> integer\n" *************** *** 1228,1239 **** --- 1227,1313 ---- "Return the size in bytes of a C instance"; + static PyObject * + sizeof_func(PyObject *self, PyObject *obj) + { + StgDictObject *dict; + + dict = PyType_stgdict(obj); + if (dict) + return PyInt_FromLong(dict->size); + + if (CDataObject_Check(obj)) + return PyInt_FromLong(((CDataObject *)obj)->b_size); + PyErr_SetString(PyExc_TypeError, + "this type has no size"); + return NULL; + } + + static char alignment_doc[] = + "alignment(C type) -> integer\n" + "alignment(C instance) -> integer\n" + "Return the alignment requirements of a C instance"; + + static PyObject * + align_func(PyObject *self, PyObject *obj) + { + StgDictObject *dict; + + dict = PyType_stgdict(obj); + if (dict) + return PyInt_FromLong(dict->align); + + dict = PyObject_stgdict(obj); + if (dict) + return PyInt_FromLong(dict->align); + + PyErr_SetString(PyExc_TypeError, + "no alignment info"); + return NULL; + } + static char byref_doc[] = "byref(C instance) -> byref-object\n" "Return a pointer lookalike to a C instance, only usable\n" "as function argument"; + + /* + * We must return something which can be converted to a parameter, + * but still has a reference to self. + */ + static PyObject * + byref(PyObject *self, PyObject *obj) + { + PyCArgObject *parg; + if (!CDataObject_Check(obj)) { + PyErr_SetString(PyExc_TypeError, + "expected CData instance"); + return NULL; + } + + parg = new_CArgObject(); + if (parg == NULL) + return NULL; + + parg->tag = 'P'; + parg->pffi_type = &ffi_type_pointer; + Py_INCREF(obj); + parg->obj = obj; + parg->value.p = ((CDataObject *)obj)->b_ptr; + return (PyObject *)parg; + } + static char addressof_doc[] = "addressof(C instance) -> integer\n" "Return the address of the C instance internal buffer"; + static PyObject * + addressof(PyObject *self, PyObject *obj) + { + if (CDataObject_Check(obj)) + return PyInt_FromLong((long)((CDataObject *)obj)->b_ptr); + PyErr_SetString(PyExc_TypeError, + "invalid type"); + return NULL; + } static PyObject * *************** *** 1267,1270 **** --- 1341,1350 ---- #ifdef CTYPES_UNICODE + static char set_conversion_mode_doc[] = + "FormatError(encoding, errors) -> (previous-encoding, previous-errors)\n\ + \n\ + Set the encoding and error handling ctypes uses when converting\n\ + between unicode and strings. Returns the previous values.\n"; + static PyObject * set_conversion_mode(PyObject *self, PyObject *args) *************** *** 1288,1297 **** return result; } - - static char set_conversion_mode_doc[] = - "FormatError(encoding, errors) -> (previous-encoding, previous-errors)\n\ - \n\ - Set the encoding and error handling ctypes uses when converting\n\ - between unicode and strings. Returns the previous values.\n"; #endif --- 1368,1371 ---- Index: _ctypes.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes.c,v retrieving revision 1.192 retrieving revision 1.193 diff -C2 -d -r1.192 -r1.193 *** _ctypes.c 2 Dec 2004 19:51:32 -0000 1.192 --- _ctypes.c 17 Dec 2004 13:08:23 -0000 1.193 *************** *** 3480,3557 **** */ - PyObject * - sizeof_func(PyObject *self, PyObject *obj) - { - StgDictObject *dict; - - dict = PyType_stgdict(obj); - if (dict) - return PyInt_FromLong(dict->size); - - if (CDataObject_Check(obj)) - return PyInt_FromLong(((CDataObject *)obj)->b_size); - PyErr_SetString(PyExc_TypeError, - "this type has no size"); - return NULL; - } - - PyObject * - align_func(PyObject *self, PyObject *obj) - { - StgDictObject *dict; - - dict = PyType_stgdict(obj); - if (dict) - return PyInt_FromLong(dict->align); - - dict = PyObject_stgdict(obj); - if (dict) - return PyInt_FromLong(dict->align); - - PyErr_SetString(PyExc_TypeError, - "no alignment info"); - return NULL; - } - - /* - * We must return something which can be converted to a parameter, - * but still has a reference to self. - */ - PyObject * - byref(PyObject *self, PyObject *obj) - { - PyCArgObject *parg; - if (!CDataObject_Check(obj)) { - PyErr_SetString(PyExc_TypeError, - "expected CData instance"); - return NULL; - } - - parg = new_CArgObject(); - if (parg == NULL) - return NULL; - - parg->tag = 'P'; - parg->pffi_type = &ffi_type_pointer; - Py_INCREF(obj); - parg->obj = obj; - parg->value.p = ((CDataObject *)obj)->b_ptr; - return (PyObject *)parg; - } - - /* - * Better to implement addressof here, than to do it in ctypes.py, - * and have to know about the exact format returned by byref(). - */ - PyObject * - addressof(PyObject *self, PyObject *obj) - { - if (CDataObject_Check(obj)) - return PyInt_FromLong((long)((CDataObject *)obj)->b_ptr); - PyErr_SetString(PyExc_TypeError, - "invalid type"); - return NULL; - } - static char *module_docs = "Create and manipulate C compatible data types in Python."; --- 3480,3483 ---- |
From: Thomas H. <th...@us...> - 2004-12-17 12:54:25
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28802 Modified Files: callbacks.c Log Message: Correctly handle SystemExit exceptions in C callbacks - they now exit the interpreter. Index: callbacks.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/callbacks.c,v retrieving revision 1.67 retrieving revision 1.68 diff -C2 -d -r1.67 -r1.68 *** callbacks.c 2 Dec 2004 20:00:00 -0000 1.67 --- callbacks.c 17 Dec 2004 12:54:15 -0000 1.68 *************** *** 169,174 **** result = PyObject_CallObject(callable, arglist); if (!result) { ! Extend_Error_Info(PyExc_RuntimeError, "(in callback) "); PyErr_Print(); } else if (result != Py_None) { /* another big endian hack */ --- 169,181 ---- result = PyObject_CallObject(callable, arglist); if (!result) { ! /* If the exception is SystemExit, we cannot call ExtendErrorInfo, ! because otherwise PyErr_Print() would not call Py_Exit(). ! */ ! if (!PyErr_ExceptionMatches(PyExc_SystemExit)) ! Extend_Error_Info(PyExc_RuntimeError, "(in callback) "); PyErr_Print(); + /* See also PyErr_WriteUnraisable(...), but this + prints only the repr of the original exception + */ } else if (result != Py_None) { /* another big endian hack */ |
From: Thomas H. <th...@us...> - 2004-12-17 09:45:45
|
Update of /cvsroot/ctypes/ctypes/sandbox/tools/codegen In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23589 Added Files: setup_gccxml.iss Log Message: An inno-setup installer script for gccxml. --- NEW FILE: setup_gccxml.iss --- [Setup] AppName=gccxml AppVerName=gccxml-20041208 DefaultDirName={pf}\gccxml DefaultGroupName=gccxml Compression=lzma ;;Compression=None SolidCompression=yes LicenseFile="C:\sf\gccxml\GCC_XML\Copyright.txt" InfoBeforeFile=snapshot.txt [Files] Source: "C:\sf\gccxml\GCC_XML\Copyright.txt"; DestDir: "{app}\doc"; Flags: ignoreversion Source: "C:\sf\buildgcc\bin\release\snapshot.txt"; DestDir: "{app}\doc"; Destname: README.txt; Flags: ignoreversion Source: "C:\sf\buildgcc\bin\release\gccxml.exe"; DestDir: "{app}\bin"; Flags: ignoreversion Source: "C:\sf\buildgcc\bin\release\gccxml_cc1plus.exe"; DestDir: "{app}\bin"; Flags: ignoreversion Source: "C:\sf\buildgcc\bin\release\vcInstallPatch.exe"; DestDir: "{app}\install"; Flags: ignoreversion Source: "C:\sf\buildgcc\bin\release\vcInstall.exe"; DestDir: "{app}\install"; Flags: ignoreversion Source: "C:\sf\gccxml\GCC_XML\VcInstall\*.patch"; DestDir: "{app}\install"; Flags: ignoreversion Source: "C:\sf\gccxml\GCC_XML\VcInstall\vcCat.exe"; DestName: cat.exe; DestDir: "{app}\install"; Flags: ignoreversion Source: "C:\sf\gccxml\GCC_XML\VcInstall\vcPatch.exe"; DestName: patch.exe; DestDir: "{app}\install"; Flags: ignoreversion [Icons] Name: {group}\Uninstall gccxml; Filename: {uninstallexe}; Comment: Click to uninstall gccxml [Run] Filename: "{app}\install\vcInstall.exe"; Parameters: "{app}\install {app}\bin"; Check: CreateConfig({app}\bin\config) [UninstallDelete] Type: files; Name: {app}\bin\config Type: filesandordirs; Name: {app}\bin\Vc6 Type: filesandordirs; Name: {app}\bin\Vc7 Type: filesandordirs; Name: {app}\bin\Vc71 [Registry] Root: HKLM; Subkey: "Software\gccxml"; ValueType: string; ValueName: "loc"; ValueData: {app}; Flags: uninsdeletekey [Code] function CreateConfig(filename: String) : Boolean; begin SaveStringToFile(filename, 'GCCXML_COMPILER="cl"', false); Result := true; end; |
From: Thomas H. <th...@us...> - 2004-12-17 09:36:11
|
Update of /cvsroot/ctypes/ctypes/sandbox/tools/codegen In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21734 Modified Files: h2xml.py Log Message: Try to locate the gccxml installation location in the registry. Index: h2xml.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/sandbox/tools/codegen/h2xml.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** h2xml.py 2 Dec 2004 12:55:36 -0000 1.2 --- h2xml.py 17 Dec 2004 09:35:58 -0000 1.3 *************** *** 1,6 **** """h2xml - convert C include file(s) into an xml file by running gccxml.""" import sys, os, tempfile ! os.environ["PATH"] = r"c:\sf\buildgcc\bin\release" ################################################################ --- 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 ################################################################ |
From: Thomas H. <th...@us...> - 2004-12-17 09:04:09
|
Update of /cvsroot/ctypes/ctypes/sandbox/tools/codegen In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15742 Modified Files: codegenerator.py Log Message: Slightly better formatting of the generated code. Index: codegenerator.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/sandbox/tools/codegen/codegenerator.py,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** codegenerator.py 17 Dec 2004 08:27:40 -0000 1.7 --- codegenerator.py 17 Dec 2004 09:04:01 -0000 1.8 *************** *** 409,413 **** (cc, type_name(func.returns), dllname, ", ".join(args)) else: ! 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))] --- 409,413 ---- (cc, type_name(func.returns), dllname, ", ".join(args)) else: ! 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))] |
From: Thomas H. <th...@us...> - 2004-12-17 08:27:49
|
Update of /cvsroot/ctypes/ctypes/sandbox/tools/codegen In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9181 Modified Files: xml2py.py codegenerator.py Log Message: Can now use '@' decorators, or PEAK's add_assignment_advisor (imported as 'call_as'). Index: xml2py.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/sandbox/tools/codegen/xml2py.py,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** xml2py.py 17 Dec 2004 08:18:06 -0000 1.4 --- xml2py.py 17 Dec 2004 08:27:40 -0000 1.5 *************** *** 45,48 **** --- 45,55 ---- action="store_true", dest="verbose", + help="verbose output", + default=False) + + parser.add_option("-d", + action="store_true", + dest="use_decorators", + help="use Python 2.4 function decorators", default=False) *************** *** 66,70 **** symbols=options.symbols, expressions=options.expressions, ! verbose=options.verbose) --- 73,78 ---- symbols=options.symbols, expressions=options.expressions, ! verbose=options.verbose, ! use_decorators=options.use_decorators) Index: codegenerator.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/sandbox/tools/codegen/codegenerator.py,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** codegenerator.py 17 Dec 2004 08:02:19 -0000 1.6 --- codegenerator.py 17 Dec 2004 08:27:40 -0000 1.7 *************** *** 200,206 **** class Generator(object): ! def __init__(self, stream): self.done = set() self.stream = stream def StructureHead(self, head): --- 200,207 ---- class Generator(object): ! def __init__(self, stream, use_decorators=False): self.done = set() self.stream = stream + self.use_decorators = use_decorators def StructureHead(self, head): *************** *** 399,412 **** args = [type_name(a) for a in func.arguments] if "__stdcall__" in func.attributes: ! print >> self.stream, "@ stdcall(%s, %s)" % \ ! (type_name(func.returns), ", ".join(["'%s'" % dllname] + args)) ! ## print >> self.stream, "%s = STDCALL('%s', %s, '%s', [%s])" % \ ! ## (func.name, dllname, type_name(func.returns), func.name, ", ".join(args)) else: ! ## print >> self.stream, "%s = CDECL('%s', %s, '%s', [%s])" % \ ! ## (func.name, dllname, type_name(func.returns), func.name, ", ".join(args)) ! print >> self.stream, "@ cdecl(%s, %s)" % \ ! (type_name(func.returns), ", ".join(["'%s'" % dllname] + args)) argnames = ["p%d" % i for i in range(1, 1+len(args))] print >> self.stream, "def %s(%s):" % (func.name, ", ".join(argnames)) print >> self.stream, " return _api_(%s)" % ", ".join(argnames) --- 400,416 ---- args = [type_name(a) for a in func.arguments] if "__stdcall__" in func.attributes: ! cc = "stdcall" else: ! 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: ! 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) *************** *** 463,467 **** ################################################################ ! def generate_code(xmlfile, outfile, expressions=None, symbols=None): # expressions is a sequence of compiled regular expressions, # symbols is a sequence of names --- 467,474 ---- ################################################################ ! 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 *************** *** 494,507 **** items = todo ! gen = Generator(outfile) # output header print >> outfile, "from ctypes import *" ## print >> outfile, "from _support import STDCALL, CDECL" ! print >> outfile, "from deco import stdcall" print >> outfile, "def const(x): return x" print >> outfile loops = gen.generate_code(items) ! gen.print_stats(sys.stderr) ! ! print "needed %d loop(s)" % loops --- 501,517 ---- items = todo ! gen = Generator(outfile, use_decorators=use_decorators) # output header print >> outfile, "from ctypes import *" ## print >> outfile, "from _support import STDCALL, CDECL" ! if use_decorators: ! print >> outfile, "from deco import stdcall" ! else: ! print >> outfile, "from deco import stdcall, call_as" print >> outfile, "def const(x): return x" print >> outfile loops = gen.generate_code(items) ! if verbose: ! gen.print_stats(sys.stderr) ! print >> sys.stderr, "needed %d loop(s)" % loops |
From: Thomas H. <th...@us...> - 2004-12-17 08:18:25
|
Update of /cvsroot/ctypes/ctypes/sandbox/tools/codegen In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7410 Modified Files: xml2py.py Log Message: Add a "-v" verbose command line option. Index: xml2py.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/sandbox/tools/codegen/xml2py.py,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** xml2py.py 17 Dec 2004 08:05:51 -0000 1.3 --- xml2py.py 17 Dec 2004 08:18:06 -0000 1.4 *************** *** 41,44 **** --- 41,50 ---- help="output filename (if not specified, standard output will be used)", default="-") + + parser.add_option("-v", + action="store_true", + dest="verbose", + default=False) + options, files = parser.parse_args(args[1:]) *************** *** 59,63 **** generate_code(files[0], stream, symbols=options.symbols, ! expressions=options.expressions) --- 65,70 ---- generate_code(files[0], stream, symbols=options.symbols, ! expressions=options.expressions, ! verbose=options.verbose) |
From: Thomas H. <th...@us...> - 2004-12-17 08:06:01
|
Update of /cvsroot/ctypes/ctypes/sandbox/tools/codegen In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5406 Modified Files: xml2py.py Log Message: Command line option changes. -s 'symbol' symbol to generate, -r 'regexp' symbols to generate, multiple -s and -r options allowed. Index: xml2py.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/sandbox/tools/codegen/xml2py.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** xml2py.py 2 Dec 2004 12:56:16 -0000 1.2 --- xml2py.py 17 Dec 2004 08:05:51 -0000 1.3 *************** *** 1,5 **** # bugs: # packing of structures/unions with bitfields? See '##XXX FIXME' ! import sys from codegenerator import generate_code --- 1,6 ---- # bugs: # packing of structures/unions with bitfields? See '##XXX FIXME' ! import sys, re ! from optparse import OptionParser from codegenerator import generate_code *************** *** 9,13 **** if args is None: args = sys.argv - from optparse import OptionParser def windows_dlls(option, opt, value, parser): --- 10,13 ---- *************** *** 25,30 **** parser.add_option("-s", dest="symbols", ! help="comma separated list of symbols to include " ! "(if not specified, all symbols will be included)", default=None) parser.add_option("-o", --- 25,39 ---- parser.add_option("-s", dest="symbols", ! metavar="SYMBOL", ! action="append", ! help="symbol to include " ! "(if neither symbols nor expressions are specified, everything will be included)", ! default=None) ! parser.add_option("-r", ! dest="expressions", ! metavar="EXPRESSION", ! action="append", ! help="regular expression for symbol to include " ! "(if neither symbols nor expressions are specified, everything will be included)", default=None) parser.add_option("-o", *************** *** 42,46 **** stream = open(options.output, "w") ! generate_code(files[0], stream, symbols=options.symbols) --- 51,63 ---- stream = open(options.output, "w") ! if options.expressions: ! options.expressions = map(re.compile, options.expressions) ! ! stream.write("# generated by 'xml2py'\n") ! stream.write("# flags '%s'\n" % " ".join(sys.argv[1:])) ! ! generate_code(files[0], stream, ! symbols=options.symbols, ! expressions=options.expressions) |
From: Thomas H. <th...@us...> - 2004-12-17 08:02:30
|
Update of /cvsroot/ctypes/ctypes/sandbox/tools/codegen In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4919 Modified Files: codegenerator.py Log Message: Avoid conflict when a Structure/Uniony contains more than one unnamed field. Names generated are "_", "_1", "_2", and so on. Index: codegenerator.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/sandbox/tools/codegen/codegenerator.py,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** codegenerator.py 17 Dec 2004 07:56:10 -0000 1.5 --- codegenerator.py 17 Dec 2004 08:02:19 -0000 1.6 *************** *** 341,348 **** else: print >> self.stream, "%s._fields_ = [" % body.struct.name for f in fields: if not f.name: ! print >> self.stream, " # Unnamed field renamed to '_'" ! fieldname = f.name or "_" if f.bits is None: print >> self.stream, " ('%s', %s)," % (fieldname, type_name(f.typ)) --- 341,356 ---- else: print >> self.stream, "%s._fields_ = [" % body.struct.name + # unnamed fields will get autogenerated names "_", "_1". "_2", "_3", ... + unnamed_index = 0 for f in fields: if not f.name: ! if unnamed_index: ! fieldname = "_%d" % unnamed_index ! else: ! fieldname = "_" ! unnamed_index += 1 ! print >> self.stream, " # Unnamed field renamed to '%s'" % fieldname ! else: ! fieldname = f.name if f.bits is None: print >> self.stream, " ('%s', %s)," % (fieldname, type_name(f.typ)) |
From: Thomas H. <th...@us...> - 2004-12-17 07:56:30
|
Update of /cvsroot/ctypes/ctypes/sandbox/tools/codegen In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3859 Modified Files: codegenerator.py Log Message: Automatically name unnamed structure fields '_'. The generate_code function now takes a sequence of symbols plus a sequence of compiled regular expressions for symbols. The regular expressions have to match the whole symbol name. Index: codegenerator.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/sandbox/tools/codegen/codegenerator.py,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** codegenerator.py 7 Dec 2004 09:38:19 -0000 1.4 --- codegenerator.py 17 Dec 2004 07:56:10 -0000 1.5 *************** *** 164,167 **** --- 164,168 ---- dll_names = """\ + imagehlp user32 kernel32 *************** *** 189,192 **** --- 190,194 ---- netapi32 rpcrt4""".split() + ##glut32 ##rpcndr *************** *** 340,347 **** print >> self.stream, "%s._fields_ = [" % body.struct.name for f in fields: if f.bits is None: ! print >> self.stream, " ('%s', %s)," % (f.name, type_name(f.typ)) else: ! print >> self.stream, " ('%s', %s, %s)," % (f.name, type_name(f.typ), f.bits) print >> self.stream, "]" if methods: --- 342,352 ---- print >> self.stream, "%s._fields_ = [" % body.struct.name for f in fields: + if not f.name: + print >> self.stream, " # Unnamed field renamed to '_'" + fieldname = f.name or "_" if f.bits is None: ! print >> self.stream, " ('%s', %s)," % (fieldname, type_name(f.typ)) else: ! print >> self.stream, " ('%s', %s, %s)," % (fieldname, type_name(f.typ), f.bits) print >> self.stream, "]" if methods: *************** *** 372,376 **** return dll._name ## print >> sys.stderr, "warning: dll not found for function %s" % name ! return "???" return None --- 377,381 ---- return dll._name ## print >> sys.stderr, "warning: dll not found for function %s" % name ! ## return "???" return None *************** *** 386,394 **** args = [type_name(a) for a in func.arguments] if "__stdcall__" in func.attributes: ! print >> self.stream, "%s = STDCALL('%s', %s, '%s', [%s])" % \ ! (func.name, dllname, type_name(func.returns), func.name, ", ".join(args)) else: ! print >> self.stream, "%s = CDECL('%s', %s, '%s', [%s])" % \ ! (func.name, dllname, type_name(func.returns), func.name, ", ".join(args)) self._functiontypes += 1 else: --- 391,407 ---- args = [type_name(a) for a in func.arguments] if "__stdcall__" in func.attributes: ! print >> self.stream, "@ stdcall(%s, %s)" % \ ! (type_name(func.returns), ", ".join(["'%s'" % dllname] + args)) ! ## print >> self.stream, "%s = STDCALL('%s', %s, '%s', [%s])" % \ ! ## (func.name, dllname, type_name(func.returns), func.name, ", ".join(args)) else: ! ## print >> self.stream, "%s = CDECL('%s', %s, '%s', [%s])" % \ ! ## (func.name, dllname, type_name(func.returns), func.name, ", ".join(args)) ! print >> self.stream, "@ cdecl(%s, %s)" % \ ! (type_name(func.returns), ", ".join(["'%s'" % dllname] + args)) ! argnames = ["p%d" % i for i in range(1, 1+len(args))] ! print >> self.stream, "def %s(%s):" % (func.name, ", ".join(argnames)) ! print >> self.stream, " return _api_(%s)" % ", ".join(argnames) ! print >> self.stream self._functiontypes += 1 else: *************** *** 442,446 **** ################################################################ ! def generate_code(xmlfile, outfile, symbols=None): from gccxmlparser import parse items = parse(xmlfile) --- 455,461 ---- ################################################################ ! def generate_code(xmlfile, outfile, expressions=None, symbols=None): ! # expressions is a sequence of compiled regular expressions, ! # symbols is a sequence of names from gccxmlparser import parse items = parse(xmlfile) *************** *** 449,453 **** if symbols: ! syms = set(symbols.split(",")) for i in items: if i.name in syms: --- 464,468 ---- if symbols: ! syms = set(symbols) for i in items: if i.name in syms: *************** *** 455,466 **** syms.remove(i.name) - items = todo if syms: ! print "SYMS NOT FOUND", list(syms) gen = Generator(outfile) # output header print >> outfile, "from ctypes import *" ! print >> outfile, "from _support import STDCALL, CDECL" print >> outfile, "def const(x): return x" print >> outfile --- 470,494 ---- syms.remove(i.name) if syms: ! print "symbols not found", list(syms) ! ! if expressions: ! for i in items: ! for s in expressions: ! if i.name is None: ! continue ! match = s.match(i.name) ! # we only want complete matches ! if match and match.group() == i.name: ! todo.append(i) ! break ! if symbols or expressions: ! items = todo gen = Generator(outfile) # output header print >> outfile, "from ctypes import *" ! ## print >> outfile, "from _support import STDCALL, CDECL" ! print >> outfile, "from deco import stdcall" print >> outfile, "def const(x): return x" print >> outfile |
From: Bob I. <et...@us...> - 2004-12-12 03:13:56
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31218 Modified Files: setup.py Log Message: That distutils hack was only relevant to the Python 2.2.0 distributed with Mac OS X 10.2. Since 2.3 is the minumum supported version, there is no longer a reason to have it. Index: setup.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/setup.py,v retrieving revision 1.111 retrieving revision 1.112 diff -C2 -d -r1.111 -r1.112 *** setup.py 25 Nov 2004 14:04:54 -0000 1.111 --- setup.py 12 Dec 2004 03:13:47 -0000 1.112 *************** *** 32,47 **** # Manipulate the environment for the build process. # - if sys.platform == 'darwin': - # This section copied from the PyObjC project - # Apple has used build options that don't work with a 'normal' system. - # Remove '-arch i386' from the LDFLAGS. - import distutils.sysconfig - distutils.sysconfig.get_config_vars() - x = distutils.sysconfig._config_vars['LDSHARED'] - y = x.replace('-arch i386', '') - if y != x: - print "Fixing Apple strangeness in Python configuration" - distutils.sysconfig._config_vars['LDSHARED'] = y - if get_platform() in ["solaris-2.9-sun4u", "linux-x86_64"]: os.environ["CFLAGS"] = "-fPIC" --- 32,35 ---- |
From: Thomas H. <th...@us...> - 2004-12-08 16:10:07
|
Update of /cvsroot/ctypes/ctypes/sandbox/tools/codegen In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16624 Modified Files: typedesc.py Log Message: Add attributes to FunctionType. Index: typedesc.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/sandbox/tools/codegen/typedesc.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** typedesc.py 25 Nov 2004 09:05:25 -0000 1.1 --- typedesc.py 8 Dec 2004 16:09:57 -0000 1.2 *************** *** 31,36 **** class FunctionType(_HasArgs): ! def __init__(self, returns): self.returns = returns self.arguments = [] --- 31,37 ---- class FunctionType(_HasArgs): ! def __init__(self, returns, attributes): self.returns = returns + self.attributes = attributes self.arguments = [] |
From: Thomas H. <th...@us...> - 2004-12-07 09:38:29
|
Update of /cvsroot/ctypes/ctypes/sandbox/tools/codegen In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15593 Modified Files: codegenerator.py Log Message: Output the correct callback type (WINFUNCTYPE or CFUNCTYPE). Index: codegenerator.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/sandbox/tools/codegen/codegenerator.py,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** codegenerator.py 2 Dec 2004 12:54:50 -0000 1.3 --- codegenerator.py 7 Dec 2004 09:38:19 -0000 1.4 *************** *** 121,126 **** elif isinstance(t, typedesc.FunctionType): args = map(type_name, [t.returns] + t.arguments) ! # WINFUNCTYPE already *is* a pointer to a function! ! return "CFUNCTYPE(%s)" % ", ".join(args) elif isinstance(t, typedesc.CvQualifiedType): return "const(%s)" % type_name(t.typ) --- 121,128 ---- elif isinstance(t, typedesc.FunctionType): args = map(type_name, [t.returns] + t.arguments) ! if "__stdcall__" in t.attributes: ! return "WINFUNCTYPE(%s)" % ", ".join(args) ! else: ! return "CFUNCTYPE(%s)" % ", ".join(args) elif isinstance(t, typedesc.CvQualifiedType): return "const(%s)" % type_name(t.typ) *************** *** 181,184 **** --- 183,187 ---- ws2_32 opengl32 + glu32 mswsock msvcrt *************** *** 369,372 **** --- 372,376 ---- return dll._name ## print >> sys.stderr, "warning: dll not found for function %s" % name + return "???" return None |
From: Thomas H. <th...@us...> - 2004-12-07 08:25:36
|
Update of /cvsroot/ctypes/ctypes/sandbox/tools/codegen In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1382 Modified Files: gccxmlparser.py Log Message: Add attributes to FunctionType. Index: gccxmlparser.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/sandbox/tools/codegen/gccxmlparser.py,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** gccxmlparser.py 25 Nov 2004 09:05:25 -0000 1.6 --- gccxmlparser.py 7 Dec 2004 08:25:26 -0000 1.7 *************** *** 131,135 **** # id, returns, attributes returns = attrs["returns"] ! return typedesc.FunctionType(returns) def _fixup_FunctionType(self, func): --- 131,136 ---- # id, returns, attributes returns = attrs["returns"] ! attributes = attrs.get("attributes", "").split() ! return typedesc.FunctionType(returns, attributes) def _fixup_FunctionType(self, func): |
From: Thomas H. <th...@us...> - 2004-12-03 09:10:00
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22754 Modified Files: test_functions.py Log Message: Passing structures as parameters to function call *does* work, here's the test that proves it. Index: test_functions.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_functions.py,v retrieving revision 1.45 retrieving revision 1.46 diff -C2 -d -r1.45 -r1.46 *** test_functions.py 2 Dec 2004 20:59:56 -0000 1.45 --- test_functions.py 3 Dec 2004 09:09:49 -0000 1.46 *************** *** 336,341 **** ("y", c_short)] dll.ret_2h_func.restype = S2H ! s2h = dll.ret_2h_func() ! self.failUnlessEqual((s2h.x, s2h.y), (42, 24)) if sys.platform == "win32": --- 336,343 ---- ("y", c_short)] dll.ret_2h_func.restype = S2H ! dll.ret_2h_func.argtypes = [S2H] ! inp = S2H(99, 88) ! s2h = dll.ret_2h_func(inp) ! self.failUnlessEqual((s2h.x, s2h.y), (99*2, 88*3)) if sys.platform == "win32": *************** *** 346,351 **** windll.s_ret_2h_func.restype = S2H ! s2h = windll.s_ret_2h_func() ! self.failUnlessEqual((s2h.x, s2h.y), (42, 24)) def test_struct_return_8H(self): --- 348,354 ---- windll.s_ret_2h_func.restype = S2H ! windll.s_ret_2h_func.argtypes = [S2H] ! s2h = windll.s_ret_2h_func(S2H(99, 88)) ! self.failUnlessEqual((s2h.x, s2h.y), (99*2, 88*3)) def test_struct_return_8H(self): *************** *** 360,366 **** ("h", c_int)] dll.ret_8i_func.restype = S8I ! s8i = dll.ret_8i_func() self.failUnlessEqual((s8i.a, s8i.b, s8i.c, s8i.d, s8i.e, s8i.f, s8i.g, s8i.h), ! (1, 2, 3, 4, 5, 6, 7, 8)) if sys.platform == "win32": --- 363,371 ---- ("h", c_int)] dll.ret_8i_func.restype = S8I ! dll.ret_8i_func.argtypes = [S8I] ! inp = S8I(9, 8, 7, 6, 5, 4, 3, 2) ! s8i = dll.ret_8i_func(inp) self.failUnlessEqual((s8i.a, s8i.b, s8i.c, s8i.d, s8i.e, s8i.f, s8i.g, s8i.h), ! (9*2, 8*3, 7*4, 6*5, 5*6, 4*7, 3*8, 2*9)) if sys.platform == "win32": *************** *** 376,382 **** ("h", c_int)] windll.s_ret_8i_func.restype = S8I ! s8i = windll.s_ret_8i_func() self.failUnlessEqual((s8i.a, s8i.b, s8i.c, s8i.d, s8i.e, s8i.f, s8i.g, s8i.h), ! (1, 2, 3, 4, 5, 6, 7, 8)) if __name__ == '__main__': --- 381,389 ---- ("h", c_int)] windll.s_ret_8i_func.restype = S8I ! windll.s_ret_8i_func.argtypes = [S8I] ! inp = S8I(9, 8, 7, 6, 5, 4, 3, 2) ! s8i = windll.s_ret_8i_func(inp) self.failUnlessEqual((s8i.a, s8i.b, s8i.c, s8i.d, s8i.e, s8i.f, s8i.g, s8i.h), ! (9*2, 8*3, 7*4, 6*5, 5*6, 4*7, 3*8, 2*9)) if __name__ == '__main__': |
From: Thomas H. <th...@us...> - 2004-12-03 09:09:49
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22712 Modified Files: _ctypes_test.c Log Message: Passing structures as parameters to function call *does* work, here's the test that proves it. Index: _ctypes_test.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes_test.c,v retrieving revision 1.40 retrieving revision 1.41 diff -C2 -d -r1.40 -r1.41 *** _ctypes_test.c 2 Dec 2004 20:36:41 -0000 1.40 --- _ctypes_test.c 3 Dec 2004 09:09:40 -0000 1.41 *************** *** 451,461 **** } S2H; ! EXPORT(S2H) ret_2h_func(void) { ! S2H s2h; ! s2h.x = 42; ! s2h.y = 24; ! ! return s2h; } --- 451,459 ---- } S2H; ! EXPORT(S2H) ret_2h_func(S2H inp) { ! inp.x *= 2; ! inp.y *= 3; ! return inp; } *************** *** 464,476 **** } S8I; ! EXPORT(S8I) ret_8i_func(void) { ! S8I s8i = {1, 2, 3, 4, 5, 6, 7, 8}; ! return s8i; } #ifdef MS_WIN32 ! EXPORT(S2H) __stdcall s_ret_2h_func(void) { return ret_2h_func(); } ! EXPORT(S8I) __stdcall s_ret_8i_func(void) { return ret_8i_func(); } #endif --- 462,481 ---- } S8I; ! EXPORT(S8I) ret_8i_func(S8I inp) { ! inp.a *= 2; ! inp.b *= 3; ! inp.c *= 4; ! inp.d *= 5; ! inp.e *= 6; ! inp.f *= 7; ! inp.g *= 8; ! inp.h *= 9; ! return inp; } #ifdef MS_WIN32 ! EXPORT(S2H) __stdcall s_ret_2h_func(S2H inp) { return ret_2h_func(inp); } ! EXPORT(S8I) __stdcall s_ret_8i_func(S8I inp) { return ret_8i_func(inp); } #endif |
From: Thomas H. <th...@us...> - 2004-12-02 21:05:05
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1618 Modified Files: ChangeLog Log Message: Index: ChangeLog =================================================================== RCS file: /cvsroot/ctypes/ctypes/ChangeLog,v retrieving revision 1.73 retrieving revision 1.74 diff -C2 -d -r1.73 -r1.74 *** ChangeLog 2 Dec 2004 09:53:30 -0000 1.73 --- ChangeLog 2 Dec 2004 21:04:50 -0000 1.74 *************** *** 1,6 **** 2004-12-02 Thomas Heller <th...@py...> ! * (Message): The _fields_ attribute is now handled correctly in ! Structure sub-subclasses. It is extended instead of replaced. if 'sizeof(int) == sizeof(long)', c_int/c_uint are now aliases for --- 1,10 ---- 2004-12-02 Thomas Heller <th...@py...> ! * Structure types as restype of functions do work now. But I have ! severe doubts that passing structures by values works. Not to ! speak about callback functions! ! ! The _fields_ attribute is now handled correctly in Structure ! sub-subclasses. It is extended instead of replaced. if 'sizeof(int) == sizeof(long)', c_int/c_uint are now aliases for |
From: Thomas H. <th...@us...> - 2004-12-02 21:00:05
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv333 Modified Files: test_functions.py Log Message: Add stdcall tests for structure return types. Index: test_functions.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_functions.py,v retrieving revision 1.44 retrieving revision 1.45 diff -C2 -d -r1.44 -r1.45 *** test_functions.py 2 Dec 2004 19:53:37 -0000 1.44 --- test_functions.py 2 Dec 2004 20:59:56 -0000 1.45 *************** *** 17,20 **** --- 17,22 ---- import _ctypes_test dll = CDLL(_ctypes_test.__file__) + if sys.platform == "win32": + windll = WinDLL(_ctypes_test.__file__) class FunctionTestCase(unittest.TestCase): *************** *** 337,340 **** --- 339,352 ---- self.failUnlessEqual((s2h.x, s2h.y), (42, 24)) + if sys.platform == "win32": + def test_struct_return_2H_stdcall(self): + class S2H(Structure): + _fields_ = [("x", c_short), + ("y", c_short)] + + windll.s_ret_2h_func.restype = S2H + s2h = windll.s_ret_2h_func() + self.failUnlessEqual((s2h.x, s2h.y), (42, 24)) + def test_struct_return_8H(self): class S8I(Structure): *************** *** 352,355 **** --- 364,383 ---- (1, 2, 3, 4, 5, 6, 7, 8)) + if sys.platform == "win32": + def test_struct_return_8H_stdcall(self): + class S8I(Structure): + _fields_ = [("a", c_int), + ("b", c_int), + ("c", c_int), + ("d", c_int), + ("e", c_int), + ("f", c_int), + ("g", c_int), + ("h", c_int)] + windll.s_ret_8i_func.restype = S8I + s8i = windll.s_ret_8i_func() + self.failUnlessEqual((s8i.a, s8i.b, s8i.c, s8i.d, s8i.e, s8i.f, s8i.g, s8i.h), + (1, 2, 3, 4, 5, 6, 7, 8)) + if __name__ == '__main__': unittest.main() |
From: Thomas H. <th...@us...> - 2004-12-02 20:57:39
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32102 Modified Files: callproc.c Log Message: Structure returns from functions does work now on windows. Index: callproc.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/callproc.c,v retrieving revision 1.121 retrieving revision 1.122 diff -C2 -d -r1.121 -r1.122 *** callproc.c 2 Dec 2004 19:53:21 -0000 1.121 --- callproc.c 2 Dec 2004 20:57:29 -0000 1.122 *************** *** 591,594 **** --- 591,605 ---- if (dict == NULL) return &ffi_type_sint; + #ifdef MS_WIN32 + /* This little trick works correctly with MSVC. + It returns small structures in registers + */ + if (dict->ffi_type.type == FFI_TYPE_STRUCT) { + if (dict->ffi_type.size <= 4) + return &ffi_type_sint32; + else if (dict->ffi_type.size <= 8) + return &ffi_type_sint64; + } + #endif return &dict->ffi_type; } |
From: Thomas H. <th...@us...> - 2004-12-02 20:37:05
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26885 Modified Files: _ctypes_test.c Log Message: Add stdcall functions returning structures. Index: _ctypes_test.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes_test.c,v retrieving revision 1.39 retrieving revision 1.40 diff -C2 -d -r1.39 -r1.40 *** _ctypes_test.c 2 Dec 2004 16:00:44 -0000 1.39 --- _ctypes_test.c 2 Dec 2004 20:36:41 -0000 1.40 *************** *** 470,473 **** --- 470,478 ---- } + #ifdef MS_WIN32 + EXPORT(S2H) __stdcall s_ret_2h_func(void) { return ret_2h_func(); } + EXPORT(S8I) __stdcall s_ret_8i_func(void) { return ret_8i_func(); } + #endif + DL_EXPORT(void) init_ctypes_test(void) |
From: Thomas H. <th...@us...> - 2004-12-02 20:35:35
|
Update of /cvsroot/ctypes/ctypes/source/libffi_msvc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26353 Modified Files: prep_cif.c Log Message: Revert the last checkin, and leave only a comment. We have a different workaround. Index: prep_cif.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/libffi_msvc/prep_cif.c,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** prep_cif.c 2 Dec 2004 20:24:35 -0000 1.5 --- prep_cif.c 2 Dec 2004 20:35:25 -0000 1.6 *************** *** 117,124 **** /* Make space for the return structure pointer */ if (cif->rtype->type == FFI_TYPE_STRUCT ! #ifdef _MSC_VER ! /* MSVC returns small structures in registers */ ! && cif->rtype->size > 8 ! #endif #ifdef SPARC && (cif->abi != FFI_V9 || cif->rtype->size > 32) --- 117,123 ---- /* Make space for the return structure pointer */ if (cif->rtype->type == FFI_TYPE_STRUCT ! /* MSVC returns small structures in registers. But we have a different ! workaround: pretend int32 or int64 return type, and converting to ! structure afterwards. */ #ifdef SPARC && (cif->abi != FFI_V9 || cif->rtype->size > 32) |
From: Thomas H. <th...@us...> - 2004-12-02 20:24:44
|
Update of /cvsroot/ctypes/ctypes/source/libffi_msvc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23785 Modified Files: prep_cif.c Log Message: MSVC returns small structures in registers. Returning small structures does still not work on Windows, but at least the stack is ok now. Index: prep_cif.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/libffi_msvc/prep_cif.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** prep_cif.c 25 May 2004 11:38:33 -0000 1.4 --- prep_cif.c 2 Dec 2004 20:24:35 -0000 1.5 *************** *** 117,120 **** --- 117,124 ---- /* Make space for the return structure pointer */ if (cif->rtype->type == FFI_TYPE_STRUCT + #ifdef _MSC_VER + /* MSVC returns small structures in registers */ + && cif->rtype->size > 8 + #endif #ifdef SPARC && (cif->abi != FFI_V9 || cif->rtype->size > 32) |
From: Thomas H. <th...@us...> - 2004-12-02 20:00:10
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17110 Modified Files: callbacks.c Log Message: Removed double definition of alloca. Index: callbacks.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/callbacks.c,v retrieving revision 1.66 retrieving revision 1.67 diff -C2 -d -r1.66 -r1.67 *** callbacks.c 21 Oct 2004 10:39:10 -0000 1.66 --- callbacks.c 2 Dec 2004 20:00:00 -0000 1.67 *************** *** 5,9 **** #ifdef MS_WIN32 #include <windows.h> - #define alloca _alloca #endif --- 5,8 ---- |