ctypes-commit Mailing List for ctypes (Page 5)
Brought to you by:
theller
You can subscribe to this list here.
2004 |
Jan
|
Feb
|
Mar
|
Apr
(8) |
May
(90) |
Jun
(143) |
Jul
(106) |
Aug
(94) |
Sep
(84) |
Oct
(163) |
Nov
(60) |
Dec
(58) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2005 |
Jan
(128) |
Feb
(79) |
Mar
(227) |
Apr
(192) |
May
(179) |
Jun
(41) |
Jul
(53) |
Aug
(103) |
Sep
(28) |
Oct
(38) |
Nov
(81) |
Dec
(17) |
2006 |
Jan
(184) |
Feb
(111) |
Mar
(188) |
Apr
(67) |
May
(58) |
Jun
(123) |
Jul
(73) |
Aug
|
Sep
|
Oct
(1) |
Nov
|
Dec
|
From: Thomas H. <th...@us...> - 2006-06-18 14:28:06
|
Update of /cvsroot/ctypes/ctypes/docs/manual In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv10517 Modified Files: tutorial.txt Log Message: Fix a test in the tutorial. Index: tutorial.txt =================================================================== RCS file: /cvsroot/ctypes/ctypes/docs/manual/tutorial.txt,v retrieving revision 1.32 retrieving revision 1.33 diff -C2 -d -r1.32 -r1.33 *** tutorial.txt 13 Jun 2006 17:57:34 -0000 1.32 --- tutorial.txt 18 Jun 2006 14:28:01 -0000 1.33 *************** *** 129,134 **** be used as the NULL pointer):: ! >>> print libc.time(None) ! 114... >>> print hex(windll.kernel32.GetModuleHandleA(None)) # doctest: +WINDOWS 0x1d000000 --- 129,134 ---- be used as the NULL pointer):: ! >>> print libc.time(None) # doctest: +SKIP ! 1150640792 >>> print hex(windll.kernel32.GetModuleHandleA(None)) # doctest: +WINDOWS 0x1d000000 |
From: Thomas H. <th...@us...> - 2006-06-16 18:48:54
|
Update of /cvsroot/ctypes/ctypes/codegen/ctypes_codegen In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv17508 Modified Files: codegenerator.py Log Message: Fix generated code: "restypes" should be "restype". Thanks to Mark Heslep for the heads up. Index: codegenerator.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/codegen/ctypes_codegen/codegenerator.py,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** codegenerator.py 9 Jun 2006 17:35:01 -0000 1.4 --- codegenerator.py 16 Jun 2006 18:48:51 -0000 1.5 *************** *** 563,567 **** print >> self.stream, "# %s %s" % func.location print >> self.stream, "%s = %s.%s" % (func.name, libname, func.name) ! print >> self.stream, "%s.restypes = %s" % (func.name, self.type_name(func.returns)) print >> self.stream, "# %s(%s)" % (func.name, ", ".join(argnames)) print >> self.stream, "%s.argtypes = [%s]" % (func.name, ", ".join(args)) --- 563,567 ---- print >> self.stream, "# %s %s" % func.location print >> self.stream, "%s = %s.%s" % (func.name, libname, func.name) ! print >> self.stream, "%s.restype = %s" % (func.name, self.type_name(func.returns)) print >> self.stream, "# %s(%s)" % (func.name, ", ".join(argnames)) print >> self.stream, "%s.argtypes = [%s]" % (func.name, ", ".join(args)) |
From: Thomas H. <th...@us...> - 2006-06-16 16:33:54
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv27252 Modified Files: Tag: array_interface_branch _ctypes.c Log Message: Add simpleminded and still incomplete implementation of the __array_interface__ attribute to ctypes array types. Index: _ctypes.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes.c,v retrieving revision 1.339 retrieving revision 1.339.2.1 diff -C2 -d -r1.339 -r1.339.2.1 *** _ctypes.c 12 Jun 2006 20:28:16 -0000 1.339 --- _ctypes.c 16 Jun 2006 16:33:49 -0000 1.339.2.1 *************** *** 3731,3738 **** --- 3731,3836 ---- return (PyObject *)p; } + /* + http://numeric.scipy.org/array_interface.html + */ + + typedef struct { + int version; /* contains the integer 2 as a sanity check */ + int nd; /* number of dimensions */ + char typekind; /* kind in array --- character code of typestr */ + int itemsize; /* size of each element */ + int flags; /* flags indicating how the data should be interpreted */ + Py_intptr_t *shape; /* A length-nd array of shape information */ + Py_intptr_t *strides; /* A length-nd array of stride information */ + void *data; /* A pointer to the first element of the array */ + PyObject *descr; /* NULL or data-description (same as descr key + of __array_interface__ */ + /* end of 'official' structure, add some private fields */ + PyObject *obj; + int dimensions[10]; + } PyArrayInterface; + + #define CONTIGUOUS 0x001 + #define FORTRAN 0x002 + #define ALIGNED 0x100 + #define NOTSWAPPED 0x200 + #define WRITEABLE 0x400 + #define ARR_HAS_DESCR 0x800 + + void _free_PyArrayInterface(PyArrayInterface *pai) + { + Py_XDECREF(pai->obj); + PyMem_Free(pai); + } + + static PyObject * + Array_struct(CDataObject *self) + { + PyArrayInterface *pai; + PyObject *typ; + StgDictObject *dict; + int i; + + pai = (PyArrayInterface *)PyMem_Malloc(sizeof(PyArrayInterface)); + if (pai == NULL) + return PyErr_NoMemory(); + pai->version = 2; /* Version number of the __array_struct__ definition we use */ + pai->flags = CONTIGUOUS | ALIGNED | NOTSWAPPED | WRITEABLE; + pai->shape = &pai->dimensions[0]; + pai->strides = NULL; + pai->data = self->b_ptr; + + typ = (PyObject *)self->ob_type; + for (i = 0; i < 10; ++i) { + dict = PyType_stgdict(typ); + if (!ArrayTypeObject_Check(typ)) + break; + pai->shape[i] = dict->length; + typ = dict->proto; + } + /* XXX CHECK FOR OVERFLOW */ + pai->nd = i; + + switch(dict->ffi_type_pointer.type) { + case FFI_TYPE_INT: + case FFI_TYPE_SINT8: + case FFI_TYPE_SINT16: + case FFI_TYPE_SINT32: + case FFI_TYPE_SINT64: + pai->typekind = 'i'; + break; + + case FFI_TYPE_UINT8: + case FFI_TYPE_UINT16: + case FFI_TYPE_UINT32: + case FFI_TYPE_UINT64: + pai->typekind = 'u'; + break; + + case FFI_TYPE_FLOAT: + case FFI_TYPE_DOUBLE: + pai->typekind = 'f'; + break; + + /* other types not yet supported */ + default: + PyErr_SetString(PyExc_TypeError, + "array type not supported"); + PyMem_Free(pai); + return NULL; + } + pai->itemsize = dict->size; + + Py_INCREF(self); + pai->obj = (PyObject *)self; + + return PyCObject_FromVoidPtr(pai, _free_PyArrayInterface); + } static PyGetSetDef Array_getsets[] = { { "_as_parameter_", (getter)Array_as_parameter, (setter)NULL, "convert to a parameter", NULL }, + { "__array_struct__", (getter)Array_struct, + (setter)NULL, "See array_interface.html", NULL }, { NULL }, }; |
From: Thomas H. <th...@us...> - 2006-06-16 16:19:42
|
Update of /cvsroot/ctypes/ctypes/ctypes/test In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv21511 Added Files: Tag: array_interface_branch test_array_interface.py Log Message: Add test for __array_interface__ attribute. --- NEW FILE: test_array_interface.py --- import unittest from ctypes import * class ArrayInterfaceTest(unittest.TestCase): def test_has_attribute(self): typ = (c_int * 3 * 4 * 5) cobj = typ.__array_interface__ if __name__ == "__main__": unittest.main() |
From: Thomas H. <th...@us...> - 2006-06-14 19:45:34
|
Update of /cvsroot/ctypes/ctypes/codegen/docs In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv11333 Added Files: codegen.txt Log Message: Add the latest docs for codegenerator again - still has to be updated. --- NEW FILE: codegen.txt --- =============================== README: ctypes code generation =============================== .. _REST quickref (only for the editor): http://docutils.sourceforge.net/docs/user/rst/quickstart.html This document describes the ctypes code generator. The generator converts declarations in C header files into executable Python code: enums, structs, unions, function declarations, com interfaces, and preprocessor definitions. **The code generator is brand new and still experimental, although hopefully better than in the 0.9.5 release.** .. contents:: Overview ======== Creating wrappers for C header file(s) is a two step process. First, the ``h2xml.py`` script runs GCC-XML_ over the include file(s), creating a XML file containing declarations and definitions. Second, the ``xml2py.py`` script parses the XML files and creates Python code containing all or a subset of these definitions. Python code is generated for C enums, structure, unions, typedefs and function declarations. Also included are preprocessor definitions, as far as they can be converted to valid Python code. It is possible to filter the output so that only a subset of the definitions are converted, so it is either possible to generate a complete Python module wrapping a shared library, or the generator can be used to create snippets of Python code which can be pasted into a manually written module. Requirements ============ GCC-XML_ (from http://www.gccxml.org/) is required to parse C header files into an XML description. **Unfortunately the latest official version 0.6.0 does not fulfill the ctypes code generator requirements.** For windows, you can download a prebuild `GCC-XML windows installer`_ from `the ctypes download page`_ (this is an unofficial release). Please note that even the *installation* of GCC-XML requires that MSVC 6, 7, or 7.1 is installed on your system, because it needs the system header files. For other platforms you must `get the development version from CVS`_ and `build GCC-XML from source`_. .. _the ctypes download page: http://sourceforge.net/project/showfiles.php?group_id=71702 .. _GCC-XML windows installer: http://sourceforge.net/project/showfiles.php?group_id=71702&package_id=71318&release_id=313813 .. _GCC-XML: http://www.gccxml.org/ .. _build GCC-XML from source: http://www.gccxml.org/HTML/Install.html .. _get the development version from CVS: http://www.gccxml.org/HTML/Download.html Changes in the ctypes 0.9.6 release =================================== - ``h2xml.py`` doesn't try to find preprocessor definitions by default anymore. Can be changed with the new ``-c`` or ``--cpp-symbols`` flag. - Added ``-k`` option to ``h2xml.py`` to not delete temporary files. - Better error output if the compilation fails. - ``h2xml.py`` can load an optional local configuration file from the current directory - several bugs in the gccxml installer plus one bug in gccxml has been fixed, and the gccxml installer snapshot has been rebuilt. Usage examples ============== Here are several examples that show how to call the ``h2xml.py`` and ``xml2py.py`` scripts, and the code they generate. The output has sometimes been cleaned up a bit, for clarity. Generally, the codegenerator creates a lot of comments pointing to the C header file. This is useful to quickly look up the C source code. Parse the windows header files (this may take a while), and include preprocessor definitions in the xml file:: C:\>python h2xml.py windows.h -o windows.xml -q -c C:\> Generate code for the ``RECT`` structure:: C:\>xml2py.py windows.xml -s RECT from ctypes import * LONG = c_long class tagRECT(Structure): pass RECT = tagRECT tagRECT._fields_ = [ ('left', c_long), ('top', c_long), ('right', c_long), ('bottom', c_long), ] assert sizeof(tagRECT) == 16, sizeof(tagRECT) assert alignment(tagRECT) == 4, alignment(tagRECT) C:\> Generate the ``MB_xxx`` constants, which are flags used for the ``MessageBox`` function - since these are #define'd symbols this works only when the xml file includes preprocessor definitions:: c:\>python xml2py.py windows.xml -r MB_.* # generated by 'xml2py.py' # flags 'windows.xml -r MB_.*' MB_USERICON = 128 MB_DEFBUTTON3 = 512 MB_USEGLYPHCHARS = 4 MB_ABORTRETRYIGNORE = 2 MB_ICONASTERISK = 64 MB_ICONINFORMATION = MB_ICONASTERISK MB_ICONHAND = 16 MB_ICONERROR = MB_ICONHAND MB_ICONEXCLAMATION = 48 MB_ICONWARNING = MB_ICONEXCLAMATION MB_RIGHT = 524288 MB_SYSTEMMODAL = 4096 MB_ICONQUESTION = 32 MB_APPLMODAL = 0 MB_OK = 0 MB_TYPEMASK = 15 MB_MODEMASK = 12288 MB_TASKMODAL = 8192 MB_OKCANCEL = 1 MB_RETRYCANCEL = 5 MB_DEFAULT_DESKTOP_ONLY = 131072 MB_RTLREADING = 1048576 MB_PRECOMPOSED = 1 MB_DEFBUTTON1 = 0 MB_DEFMASK = 3840 MB_DEFBUTTON2 = 256 MB_YESNOCANCEL = 3 MB_CANCELTRYCONTINUE = 6 MB_HELP = 16384 MB_ICONMASK = 240 MB_SETFOREGROUND = 65536 MB_TOPMOST = 262144 MB_COMPOSITE = 2 MB_DEFBUTTON4 = 768 MB_YESNO = 4 MB_ERR_INVALID_CHARS = 8 MB_NOFOCUS = 32768 MB_ICONSTOP = MB_ICONHAND MB_MISCMASK = 49152 C:\> Generate code for the ``RegisterClass`` function, note how this pulls in a lot of types (if you want code compatible with Python 2.3 don't use the ``-d`` flag):: C:\>python xml2py.py windows.xml -w -s RegisterClass -d # generated by 'xml2py' # flags 'windows.xml -w -s RegisterClass' from ctypes import * from ctypes import decorators WORD = c_ushort ATOM = WORD class tagWNDCLASSA(Structure): pass WNDCLASSA = tagWNDCLASSA @ decorators.stdcall(ATOM, 'user32', [POINTER(WNDCLASSA)]) def RegisterClassA(p1): return RegisterClassA._api_(p1) RegisterClass = RegisterClassA UINT = c_uint LONG_PTR = c_long LRESULT = LONG_PTR WNDPROC = WINFUNCTYPE(LRESULT, c_void_p, c_uint, c_uint, c_long) PVOID = c_void_p HANDLE = PVOID HINSTANCE = HANDLE HICON = HANDLE HCURSOR = HICON HBRUSH = HANDLE CHAR = c_char LPCSTR = POINTER(CHAR) tagWNDCLASSA._fields_ = [ ('style', UINT), ('lpfnWndProc', WNDPROC), ('cbClsExtra', c_int), ('cbWndExtra', c_int), ('hInstance', HINSTANCE), ('hIcon', HICON), ('hCursor', HCURSOR), ('hbrBackground', HBRUSH), ('lpszMenuName', LPCSTR), ('lpszClassName', LPCSTR), ] assert sizeof(tagWNDCLASSA) == 40, sizeof(tagWNDCLASSA) assert alignment(tagWNDCLASSA) == 4, alignment(tagWNDCLASSA) Generate code for the ``ICreateErrorInfo`` com interface. This example uses the ``-m`` command line flag, and the generated code imports several symbols from the specified ``ctypes.com`` module. Note that the ``_iid_`` member of the interface cannot be created by the code generator, but the generated comments allows to quickly locate the header file and patch this manually:: C:\sf\ctypes\ctypes\wrap>xml2py windows.xml -s ICreateErrorInfo -m ctypes.com # generated by 'xml2py' # flags 'windows.xml -s ICreateErrorInfo -m ctypes.com' from ctypes import * from ctypes.com import IUnknown from ctypes.com import GUID class ICreateErrorInfo(IUnknown): _iid_ = GUID('{}') # please look up iid and fill in! # C:/Programme/gccxml/bin/Vc71/PlatformSDK/oaidl.h 5366 pass from ctypes.com import HRESULT from ctypes.com import GUID WCHAR = c_wchar OLECHAR = WCHAR LPOLESTR = POINTER(OLECHAR) from ctypes.com import DWORD from ctypes.com import STDMETHOD ICreateErrorInfo._methods_ = IUnknown._methods + [ # C:/Programme/gccxml/bin/Vc71/PlatformSDK/oaidl.h 5366 STDMETHOD(HRESULT, 'SetGUID', [POINTER(GUID)]), STDMETHOD(HRESULT, 'SetSource', [LPOLESTR]), STDMETHOD(HRESULT, 'SetDescription', [LPOLESTR]), STDMETHOD(HRESULT, 'SetHelpFile', [LPOLESTR]), STDMETHOD(HRESULT, 'SetHelpContext', [DWORD]), ] Create a Python module ``win_lean.py`` containing wrappers for the 'lean' windows api, this creates a fairly large file:: C:\>python h2xml.py windows.h -D WIN32_LEAN_AND_MEAN -D NO_STRICT -o win_lean.xml -q C:\>python xml2py.py win_lean.xml -w -o win_lean.py Create a Python module ``SDL.py`` containing wrappers for the ``SDL`` library. To work around a problem GCC-XML has with a certain construct in the SDL header files on Windows, you must define the ``SDLCALL`` macro to an empty value:: C:\>python h2xml.py SDL.h -I SDL\include -D SDLCALL= -o SDL.xml -q C:\>python xml2py.py SDL.xml -o SDL.py -l SDL.dll C:\> On linux, the ``SDL.py`` module could be created in this way - both the location of the include file and the name of the shared library is different:: thomas@linux:~/ctypes/wrap> locate SDL.h /usr/include/SDL/SDL.h thomas@linux:~/ctypes/wrap> python h2xml.py SDL/SDL.h -o SDL.xml -q thomas@linux:~/ctypes/wrap> python xml2py.py SDL.xml -o SDL.py -l libSDL.so thomas@linux:~/ctypes/wrap> ls -l SDL.py -rw-r--r-- 1 thomas users 95772 2004-10-26 02:23 SDL.py thomas@linux:~/ctypes/wrap> The h2xml.py script =================== ``h2xml.py`` lets you specify the names of the header files to parse, the name of the XML output file, and a few options which are passed to GCC-XML. The ``-D``, ``-E``, and ``-I`` flags may occur several times. ``-h, --help`` Print a short usage summary and exit. ``-q, --quiet`` Run in quiet mode. The default mode is verbose, ``h2xml.py`` prints what it is currently doing. ``-D name[=value]`` This flag defines a preprocessor name. ``-U name`` This flag undefines a preprocessor name. ``-I directory`` This flag defines an additional include directory. ``-o xmlfile`` This flag specifies name and path of the XML output file. ``-c, --cpp-symbols`` Run additional magic to include #define symbols in the xml output. Depending on the madness in the header files this may or may not work. ``-k`` Do not delete temporary files created - this may be useful to find compilation problems. The h2xml.cfg configuration file ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ If you enable preprocessor definition processing with the ``-c`` flag, it is possible that you get compiler errors on certain symbols. In this case, it is needed to exclude those symbols by writing in local configuration file named ``h2xml.cfg`` in the current directory. The configuration file sections are named after ``sys.platform``, and it allows to specify the symbols to exclude by names or by regular expressions:: # h2xml.cfg # # config file for h2xml script # # sections should be named after 'sys.platform' # options supported are: # 'excluded' - names of preprocessor symbols to exclude, # separated by whitespace # 'excluded_re' - regular expressions, separated by whitespace, matching # cpp symbols to exclude # See the documentation of the standard Python ConfigParser module # for maore information on the file format. [win32] excluded = foo bar excluded_re = spam.* .*spam [cygwin] excluded = excluded_re = [linux2] excluded = excluded_re = [darwin] excluded = excluded_re = [freebsd5] excluded = excluded_re = The xml2py.py script ==================== ``-h, --help`` Print a short usage summary and exit. ``-d`` Use Python 2.4 decorators for wrapped functions. ``-k[d][e][f][m][s][t]`` Specifies the kind of types to include in the output: ``d`` - simple preprocessor definitions: #define <identifier> <identifier> ``e`` - enumerations ``f`` - function declarations ``m`` - preprocessor macros taking parameters: #define <ident>(parameters) something ``s`` - structures and unions ``t`` - typedefs ``-l sharedlib`` specify shared library to search for exported functions. ``-m module`` specifies a Python module containing symbols that will be imported instead of generated. ``-o outputfile`` name of the output file containing Python code. If not specified, the code is printed to standard output. ``-r regular_expression`` regular expression specifying names of symbols to include. ``-s symbol`` name of symbol to include. ``-v`` verbose mode: prints a short summary of types generated. ``-w`` windows only: add all standard windows dlls to the list of shared libraries searched for functions. Note that specifying the ``-k``, ``-s``, and ``-r`` flags create a start set of type declarations, the generated code, however, may also contain other types. If, for example, the code for an external function is generated, code for the argument and return types is also needed. Also note that code for function declarations is only created when ``xml2py.py`` can locate the function in one of the shared libraries specified with ``-l`` or ``-w``. Getting Help ============ If you have questions or need assistance with *ctypes* or the code generator, please `post a message`_ to the `ctypes-users mailing list`_. .. _post a message: mailto:cty...@li... .. _ctypes-users mailing list: http://lists.sourceforge.net/lists/listinfo/ctypes-users .. Local Variables: mode: indented-text indent-tabs-mode: nil sentence-end-double-space: t fill-column: 70 compile-command: "make" End: |
From: Thomas H. <th...@us...> - 2006-06-14 19:41:35
|
Update of /cvsroot/ctypes/ctypes/codegen/docs In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv9607/docs Log Message: Directory /cvsroot/ctypes/ctypes/codegen/docs added to the repository |
From: Thomas H. <th...@us...> - 2006-06-14 18:23:58
|
Update of /cvsroot/ctypes/ctypes/codegen In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv12693 Modified Files: ChangeLog Log Message: Index: ChangeLog =================================================================== RCS file: /cvsroot/ctypes/ctypes/codegen/ChangeLog,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** ChangeLog 14 Jun 2006 14:04:12 -0000 1.7 --- ChangeLog 14 Jun 2006 18:23:48 -0000 1.8 *************** *** 1,2 **** --- 1,7 ---- + 2006-06-13 Thomas Heller <th...@py...> + + * The '-l' option for the xml2py.py script now takes the linker + library name instead of the library pathname. + 2006-06-14 Thomas Heller <th...@py...> |
From: Thomas H. <th...@us...> - 2006-06-14 18:23:34
|
Update of /cvsroot/ctypes/ctypes/codegen/ctypes_codegen In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv12677/ctypes_codegen Modified Files: xml2py_main.py Log Message: The '-l' option for the xml2py.py script now takes the linker library name instead of the library pathname. Index: xml2py_main.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/codegen/ctypes_codegen/xml2py_main.py,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** xml2py_main.py 8 Jun 2006 20:22:05 -0000 1.3 --- xml2py_main.py 14 Jun 2006 18:23:27 -0000 1.4 *************** *** 133,137 **** from ctypes import CDLL ! dlls = [CDLL(name) for name in options.dlls] for name in options.modules: --- 133,145 ---- from ctypes import CDLL ! from ctypes.util import find_library ! ! def load_library(name): ! path = find_library(name) ! if path is None: ! raise RuntimeError("Library '%s' not found" % name) ! return CDLL(path) ! ! dlls = [load_library(name) for name in options.dlls] for name in options.modules: |
From: Thomas H. <th...@us...> - 2006-06-14 18:09:18
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv7506 Modified Files: ChangeLog Log Message: Index: ChangeLog =================================================================== RCS file: /cvsroot/ctypes/ctypes/ChangeLog,v retrieving revision 1.139 retrieving revision 1.140 diff -C2 -d -r1.139 -r1.140 *** ChangeLog 10 Jun 2006 19:37:31 -0000 1.139 --- ChangeLog 14 Jun 2006 18:09:11 -0000 1.140 *************** *** 1,2 **** --- 1,9 ---- + 2006-06-12 Thomas Heller <th...@py...> + + * Fix wrong printf format in _ctypes.c. + + * Release the GIL during COM method calls, to avoid deadlocks in + Python coded COM objects. + 2006-06-10 Thomas Heller <th...@py...> |
From: Thomas H. <th...@us...> - 2006-06-14 17:43:26
|
Update of /cvsroot/ctypes/ctypes/codegen/ctypes_codegen In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv29960 Modified Files: h2xml_main.py cparser.py Log Message: Remove now unused stuff, and print some info when the compilation failed. Index: h2xml_main.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/codegen/ctypes_codegen/h2xml_main.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** h2xml_main.py 8 Jun 2006 18:46:47 -0000 1.1 --- h2xml_main.py 14 Jun 2006 17:43:23 -0000 1.2 *************** *** 1,4 **** """h2xml - convert C include file(s) into an xml file by running gccxml.""" ! import sys, os, tempfile, re, ConfigParser from ctypes_codegen import cparser from optparse import OptionParser --- 1,4 ---- """h2xml - convert C include file(s) into an xml file by running gccxml.""" ! import sys, os, ConfigParser from ctypes_codegen import cparser from optparse import OptionParser *************** *** 20,35 **** return 1 - def get_option(option, default_value): - # return an option from the platform specific section of the - # config file, or return the default_value if either the - # section or the option is not present. - try: - return config.get(sys.platform, option) - except (ConfigParser.NoOptionError, ConfigParser.NoSectionError): - return default_value - - excluded = get_option("excluded", "").split() - excluded_re = get_option("excluded_re", "").split() - parser = OptionParser("usage: %prog includefile ... [options]") parser.add_option("-q", "--quiet", --- 20,23 ---- *************** *** 81,96 **** default=False) - parser.add_option("-s", - dest="excluded_symbols", - action="append", - help="specify preprocessor symbol name to exclude", - default=excluded) - - parser.add_option("-r", - dest="excluded_symbols_re", - action="append", - help="regular expression for preprocessor symbol names to exclude", - default=[]) - options, files = parser.parse_args(argv[1:]) --- 69,72 ---- *************** *** 101,109 **** options.flags = options.gccxml_options - options.verbose = not options.quiet - options.excluded_symbols_re = [re.compile(pat) for pat in options.excluded_symbols_re] - try: parser = cparser.IncludeParser(options) --- 77,82 ---- Index: cparser.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/codegen/ctypes_codegen/cparser.py,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** cparser.py 14 Jun 2006 14:02:54 -0000 1.3 --- cparser.py 14 Jun 2006 17:43:23 -0000 1.4 *************** *** 1,4 **** ! import sys, os, re, tempfile ! C_KEYWORDS = EXCLUDED = EXCLUDED_RE = [] import gccxmlparser, typedesc import subprocess # the subprocess module is required --- 1,3 ---- ! import sys, os, re, tempfile, linecache import gccxmlparser, typedesc import subprocess # the subprocess module is required *************** *** 44,55 **** keep_temporary_files - true if temporary files should not be deleted cpp_symbols - whether to include preprocessor symbols in the XML file - excluded_symbols - collection of names for additional preprocessor symbols to exclude - excluded_symbols_re - collection of regular expressions for names to exclude xml_file - pathname of output file (may be None) """ self.options = options self.excluded = set() - self.excluded.update(EXCLUDED) - self.excluded.update(self.options.excluded_symbols) try: data = open(EXCLUDES_FILE, "U").read() --- 43,50 ---- *************** *** 59,67 **** self.excluded.update(data.splitlines()) - - self.excluded_re = set() - self.excluded_re.update(EXCLUDED_RE) - self.excluded_re.update(self.options.excluded_symbols_re) - def create_source_file(self, lines, ext=".cpp"): "Create a temporary file, write lines to it, and return the filename" --- 54,57 ---- *************** *** 125,130 **** def display_compiler_errors(self, lines): - print >> sys.stderr, "Compiler errors on these source lines:" - import re, linecache pat = re.compile(r"(.*\.cpp):(\d+):(.*)") output = [] --- 115,118 ---- *************** *** 144,153 **** if line.startswith(" ") and output: output[-1] = output[-1] + line.strip() - for line in output: - print >> sys.stderr, line if invalid_symbols: ofi = open(EXCLUDES_FILE, "a") for sym in invalid_symbols: ofi.write("%s\n" % sym) def get_defines(self, include_files): --- 132,147 ---- if line.startswith(" ") and output: output[-1] = output[-1] + line.strip() if invalid_symbols: + print >> sys.stderr, "There were compiler errors on #define symbols." + print >> sys.stderr, "These symbols were added to the config file:" ofi = open(EXCLUDES_FILE, "a") for sym in invalid_symbols: ofi.write("%s\n" % sym) + print >> sys.stderr, "\t%s" % sym + print >> sys.stderr, "Please restart the script to try again!" + else: + print >> sys.stderr, "Compiler errors on these source lines:" + for line in output: + print >> sys.stderr, line def get_defines(self, include_files): *************** *** 172,186 **** wordpat = re.compile("^[a-zA-Z_][a-zA-Z0-9_]*$") def is_excluded(self, name, value): - INVALID_CHARS = "=/{}&;" if "(" in name: return "IS_FUNCTION" - if value in C_KEYWORDS: - return "value is keyword" if name in self.excluded: return "excluded" - for pat in self.excluded_re: - if pat.match(name): - return "excluded (regex)" if value[0] in INVALID_CHARS or value[-1] in INVALID_CHARS: return "cannot be a value" --- 166,174 ---- |
From: Thomas H. <th...@us...> - 2006-06-14 14:04:17
|
Update of /cvsroot/ctypes/ctypes/codegen In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv9860 Modified Files: ChangeLog Log Message: *** empty log message *** Index: ChangeLog =================================================================== RCS file: /cvsroot/ctypes/ctypes/codegen/ChangeLog,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** ChangeLog 13 Jun 2006 08:30:02 -0000 1.6 --- ChangeLog 14 Jun 2006 14:04:12 -0000 1.7 *************** *** 1,2 **** --- 1,22 ---- + 2006-06-14 Thomas Heller <th...@py...> + + * The subprocess module is now required, although the code is + still compatible with Python 2.3. + + * The '#define' symbols that cause compilation errors are now + determined at runtime: + + If the '-c' option is given, compiler error messages are parsed to + find those '#define ' symbols that are causing them. These + symbols are then appended to the file + ~/.ctypes_codegen/cparser_excludes. If these errors occur, it is + required to restart h2xml.py, but chances are good that the next + run works better (it may be required to repeat this process + several times until all errors have vanished). + + The cparser_config.py module has been removed because it does no + longer list symbols that have to be excluded. + + 2006-06-13 Thomas Heller <th...@py...> |
From: Thomas H. <th...@us...> - 2006-06-14 14:03:04
|
Update of /cvsroot/ctypes/ctypes/codegen/ctypes_codegen In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv9097 Modified Files: cparser.py Removed Files: cparser_config.py Log Message: The subprocess module is now required, although the code is still compatible with Python 2.3. The '#define' symbols that cause compilation errors are now determined at runtime: If the '-c' option is given, compiler error messages are parsed to find those '#define ' symbols that are causing them. These symbols are then appended to the file ~/.ctypes_codegen/cparser_excludes. If these errors occur, it is required to restart h2xml.py, but chances are good that the next run works better (it may be required to repeat this process several times until all errors have vanished). The cparser_config.py module has been removed because it does no longer list symbols that have to be excluded. Index: cparser.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/codegen/ctypes_codegen/cparser.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** cparser.py 8 Jun 2006 19:11:41 -0000 1.2 --- cparser.py 14 Jun 2006 14:02:54 -0000 1.3 *************** *** 1,9 **** import sys, os, re, tempfile ! from cparser_config import C_KEYWORDS, EXCLUDED, EXCLUDED_RE import gccxmlparser, typedesc ! try: ! import subprocess ! except ImportError: ! subprocess = None try: set --- 1,7 ---- import sys, os, re, tempfile ! C_KEYWORDS = EXCLUDED = EXCLUDED_RE = [] import gccxmlparser, typedesc ! import subprocess # the subprocess module is required ! try: set *************** *** 29,44 **** os.environ["PATH"] = loc ! def find_gccxml(): ! # find gccxml on $PATH ! if sys.platform == "win32": ! GCCXML = "gccxml.exe" ! else: ! GCCXML = "gccxml" ! for directory in os.environ["PATH"].split(os.pathsep): ! what = os.path.join(directory, GCCXML) ! if os.path.isfile(what): ! return what ! return None ! class CompilerError(Exception): pass --- 27,36 ---- os.environ["PATH"] = loc ! CFG_DIR = os.path.expanduser(os.path.join("~", ".ctypes_codegen")) ! if not os.path.exists(CFG_DIR): ! os.mkdir(CFG_DIR) ! ! EXCLUDES_FILE = os.path.join(CFG_DIR, "cparser_excludes") ! class CompilerError(Exception): pass *************** *** 60,72 **** self.excluded.update(EXCLUDED) self.excluded.update(self.options.excluded_symbols) self.excluded_re = set() self.excluded_re.update(EXCLUDED_RE) self.excluded_re.update(self.options.excluded_symbols_re) - if subprocess is None: - if not find_gccxml(): - import errno - raise OSError, (errno.ENOENT, "gccxml not found") - def create_source_file(self, lines, ext=".cpp"): --- 52,66 ---- self.excluded.update(EXCLUDED) self.excluded.update(self.options.excluded_symbols) + try: + data = open(EXCLUDES_FILE, "U").read() + except IOError: + pass + else: + self.excluded.update(data.splitlines()) + self.excluded_re = set() self.excluded_re.update(EXCLUDED_RE) self.excluded_re.update(self.options.excluded_symbols_re) def create_source_file(self, lines, ext=".cpp"): *************** *** 90,102 **** if self.options.verbose: print >> sys.stderr, "running:", " ".join(args) ! if subprocess: ! proc = subprocess.Popen(args, ! stdout=subprocess.PIPE, ! stdin=subprocess.PIPE) ! data, err = proc.communicate() ! else: ! i, o = os.popen4(" ".join(args)) ! i.close() ! data = o.read() finally: if not self.options.keep_temporary_files: --- 84,91 ---- if self.options.verbose: print >> sys.stderr, "running:", " ".join(args) ! proc = subprocess.Popen(args, ! stdout=subprocess.PIPE, ! stdin=subprocess.PIPE) ! data, err = proc.communicate() finally: if not self.options.keep_temporary_files: *************** *** 120,135 **** if self.options.verbose: print >> sys.stderr, "running:", " ".join(args) ! if subprocess: ! proc = subprocess.Popen(args, ! stdout=subprocess.PIPE, ! stderr=subprocess.PIPE, ! stdin=subprocess.PIPE) ! data, err = proc.communicate() ! retcode = proc.wait() ! if retcode: ! self.display_compiler_errors(err.splitlines()) ! else: ! retcode = os.system(" ".join(args)) if retcode: raise CompilerError, "gccxml returned %s" % retcode finally: --- 109,120 ---- if self.options.verbose: print >> sys.stderr, "running:", " ".join(args) ! proc = subprocess.Popen(args, ! stdout=subprocess.PIPE, ! stderr=subprocess.PIPE, ! stdin=subprocess.PIPE) ! data, err = proc.communicate() ! retcode = proc.wait() if retcode: + self.display_compiler_errors(err.splitlines()) raise CompilerError, "gccxml returned %s" % retcode finally: *************** *** 144,147 **** --- 129,133 ---- pat = re.compile(r"(.*\.cpp):(\d+):(.*)") output = [] + invalid_symbols = set() for line in lines: match = pat.search(line) *************** *** 150,154 **** if re.match(r"\d+:", errmsg): errmsg = errmsg.split(":", 1)[1] ! text = "'%s' %s" % (linecache.getline(fnm, int(lineno)).rstrip(), errmsg) output.append(text) if line.startswith(" ") and output: --- 136,144 ---- if re.match(r"\d+:", errmsg): errmsg = errmsg.split(":", 1)[1] ! src_line = linecache.getline(fnm, int(lineno)).rstrip() ! is_define = re.match(r"^ DEFINE\((.*)\);$", src_line) ! if is_define: ! invalid_symbols.add(is_define.group(1)) ! text = "'%s' %s" % (src_line, errmsg) output.append(text) if line.startswith(" ") and output: *************** *** 156,159 **** --- 146,153 ---- for line in output: print >> sys.stderr, line + if invalid_symbols: + ofi = open(EXCLUDES_FILE, "a") + for sym in invalid_symbols: + ofi.write("%s\n" % sym) def get_defines(self, include_files): *************** *** 255,259 **** except TypeError, detail: # XXX Warning? ! print >> sys.stderr, "skipped #define %s %s" % (name, defines[name]), detail else: types[name] = typ --- 249,254 ---- except TypeError, detail: # XXX Warning? ! ## print >> sys.stderr, "skipped #define %s %s" % (name, defines[name]), detail ! pass else: types[name] = typ --- cparser_config.py DELETED --- |
From: Thomas H. <th...@us...> - 2006-06-14 13:58:07
|
Update of /cvsroot/ctypes/ctypes/codegen/ctypes_codegen In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv7175 Removed Files: cparser.diff Log Message: Remove temporary file. --- cparser.diff DELETED --- |
From: Thomas H. <th...@us...> - 2006-06-14 13:18:45
|
Update of /cvsroot/ctypes/ctypes/codegen/ctypes_codegen In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv24518 Added Files: cparser.diff Log Message: A patch. --- NEW FILE: cparser.diff --- pcl-cvs: descending directory Index: cparser.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/codegen/ctypes_codegen/cparser.py,v retrieving revision 1.2 diff -u -r1.2 cparser.py --- cparser.py 8 Jun 2006 19:11:41 -0000 1.2 +++ cparser.py 14 Jun 2006 13:18:04 -0000 @@ -1,10 +1,9 @@ import sys, os, re, tempfile -from cparser_config import C_KEYWORDS, EXCLUDED, EXCLUDED_RE +##from cparser_config import C_KEYWORDS, EXCLUDED, EXCLUDED_RE +C_KEYWORDS = EXCLUDED = EXCLUDED_RE = [] import gccxmlparser, typedesc -try: - import subprocess -except ImportError: - subprocess = None +import subprocess # the subprocess is required + try: set except NameError: @@ -28,18 +27,6 @@ if loc: os.environ["PATH"] = loc -def find_gccxml(): - # find gccxml on $PATH - if sys.platform == "win32": - GCCXML = "gccxml.exe" - else: - GCCXML = "gccxml" - for directory in os.environ["PATH"].split(os.pathsep): - what = os.path.join(directory, GCCXML) - if os.path.isfile(what): - return what - return None - class CompilerError(Exception): pass @@ -59,15 +46,17 @@ self.excluded = set() self.excluded.update(EXCLUDED) self.excluded.update(self.options.excluded_symbols) + try: + data = open("cparser.cfg", "U").read() + except IOError: + pass + else: + self.excluded.update(data.splitlines()) + self.excluded_re = set() self.excluded_re.update(EXCLUDED_RE) self.excluded_re.update(self.options.excluded_symbols_re) - if subprocess is None: - if not find_gccxml(): - import errno - raise OSError, (errno.ENOENT, "gccxml not found") - def create_source_file(self, lines, ext=".cpp"): "Create a temporary file, write lines to it, and return the filename" @@ -89,15 +78,10 @@ args.extend(self.options.flags) if self.options.verbose: print >> sys.stderr, "running:", " ".join(args) - if subprocess: - proc = subprocess.Popen(args, - stdout=subprocess.PIPE, - stdin=subprocess.PIPE) - data, err = proc.communicate() - else: - i, o = os.popen4(" ".join(args)) - i.close() - data = o.read() + proc = subprocess.Popen(args, + stdout=subprocess.PIPE, + stdin=subprocess.PIPE) + data, err = proc.communicate() finally: if not self.options.keep_temporary_files: os.remove(fname) @@ -119,18 +103,14 @@ try: if self.options.verbose: print >> sys.stderr, "running:", " ".join(args) - if subprocess: - proc = subprocess.Popen(args, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, - stdin=subprocess.PIPE) - data, err = proc.communicate() - retcode = proc.wait() - if retcode: - self.display_compiler_errors(err.splitlines()) - else: - retcode = os.system(" ".join(args)) + proc = subprocess.Popen(args, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + stdin=subprocess.PIPE) + data, err = proc.communicate() + retcode = proc.wait() if retcode: + self.display_compiler_errors(err.splitlines()) raise CompilerError, "gccxml returned %s" % retcode finally: if not self.options.keep_temporary_files: @@ -143,18 +123,27 @@ import re, linecache pat = re.compile(r"(.*\.cpp):(\d+):(.*)") output = [] + invalid_symbols = set() for line in lines: match = pat.search(line) if match: fnm, lineno, errmsg = match.groups() if re.match(r"\d+:", errmsg): errmsg = errmsg.split(":", 1)[1] - text = "'%s' %s" % (linecache.getline(fnm, int(lineno)).rstrip(), errmsg) + src_line = linecache.getline(fnm, int(lineno)).rstrip() + is_define = re.match(r"^ DEFINE\((.*)\);$", src_line) + if is_define: + invalid_symbols.add(is_define.group(1)) + text = "'%s' %s" % (src_line, errmsg) output.append(text) if line.startswith(" ") and output: output[-1] = output[-1] + line.strip() for line in output: print >> sys.stderr, line + if invalid_symbols: + ofi = open("cparser.cfg", "a") + for sym in invalid_symbols: + ofi.write("%s\n" % sym) def get_defines(self, include_files): """'Compile' an include file with gccxml, and return a @@ -254,7 +243,8 @@ typ = self.c_type_name(i.returns) except TypeError, detail: # XXX Warning? - print >> sys.stderr, "skipped #define %s %s" % (name, defines[name]), detail + ## print >> sys.stderr, "skipped #define %s %s" % (name, defines[name]), detail + pass else: types[name] = typ return types |
From: Thomas H. <th...@us...> - 2006-06-14 09:13:59
|
Update of /cvsroot/ctypes/ctypes/ctypes In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv18422 Modified Files: wintypes.py Log Message: Merge in changes from Python SVN. Index: wintypes.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/wintypes.py,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** wintypes.py 8 Mar 2006 19:02:47 -0000 1.3 --- wintypes.py 14 Jun 2006 09:13:52 -0000 1.4 *************** *** 1,42 **** ! # XXX This module needs cleanup. ! from ctypes import * - DWORD = c_ulong - WORD = c_ushort BYTE = c_byte ULONG = c_ulong LONG = c_long LARGE_INTEGER = c_longlong ULARGE_INTEGER = c_ulonglong HANDLE = c_ulong # in the header files: void * ! HWND = HANDLE HDC = HANDLE ! HMODULE = HANDLE HINSTANCE = HANDLE - HRGN = HANDLE - HTASK = HANDLE HKEY = HANDLE ! HPEN = HANDLE ! HGDIOBJ = HANDLE HMENU = HANDLE ! LCID = DWORD ! ! WPARAM = c_uint ! LPARAM = c_long ! ! BOOL = c_long ! VARIANT_BOOL = c_short ! ! LPCOLESTR = LPOLESTR = OLESTR = c_wchar_p ! LPCWSTR = LPWSTR = c_wchar_p ! ! LPCSTR = LPSTR = c_char_p class RECT(Structure): --- 1,74 ---- ! # This file contains the most useful windows datatypes. from ctypes import * BYTE = c_byte + WORD = c_ushort + DWORD = c_ulong + + BOOLEAN = BYTE + BOOL = c_long + VARIANT_BOOL = c_short ULONG = c_ulong LONG = c_long + # in the windows header files, these are structures. LARGE_INTEGER = c_longlong ULARGE_INTEGER = c_ulonglong + LPCOLESTR = LPOLESTR = OLESTR = c_wchar_p + LPCWSTR = LPWSTR = c_wchar_p + LPCSTR = LPSTR = c_char_p + + WPARAM = c_uint + LPARAM = c_long + + ATOM = WORD + LANGID = WORD + + COLORREF = DWORD + LGRPID = DWORD + LCTYPE = DWORD + + LCID = DWORD + ################################################################ + # HANDLE types HANDLE = c_ulong # in the header files: void * ! HACCEL = HANDLE ! HBITMAP = HANDLE ! HBRUSH = HANDLE ! HCOLORSPACE = HANDLE HDC = HANDLE ! HDESK = HANDLE ! HDWP = HANDLE ! HENHMETAFILE = HANDLE ! HFONT = HANDLE ! HGDIOBJ = HANDLE ! HGLOBAL = HANDLE ! HHOOK = HANDLE ! HICON = HANDLE HINSTANCE = HANDLE HKEY = HANDLE ! HKL = HANDLE ! HLOCAL = HANDLE HMENU = HANDLE + HMETAFILE = HANDLE + HMODULE = HANDLE + HMONITOR = HANDLE + HPALETTE = HANDLE + HPEN = HANDLE + HRGN = HANDLE + HRSRC = HANDLE + HSTR = HANDLE + HTASK = HANDLE + HWINSTA = HANDLE + HWND = HANDLE + SC_HANDLE = HANDLE + SERVICE_STATUS_HANDLE = HANDLE ! ################################################################ ! # Some important structure definitions class RECT(Structure): *************** *** 45,59 **** ("right", c_long), ("bottom", c_long)] ! RECTL = RECT class POINT(Structure): _fields_ = [("x", c_long), ("y", c_long)] ! POINTL = POINT class SIZE(Structure): _fields_ = [("cx", c_long), ("cy", c_long)] ! SIZEL = SIZE def RGB(red, green, blue): --- 77,102 ---- ("right", c_long), ("bottom", c_long)] ! tagRECT = _RECTL = RECTL = RECT ! ! class _SMALL_RECT(Structure): ! _fields_ = [('Left', c_short), ! ('Top', c_short), ! ('Right', c_short), ! ('Bottom', c_short)] ! SMALL_RECT = _SMALL_RECT ! ! class _COORD(Structure): ! _fields_ = [('X', c_short), ! ('Y', c_short)] class POINT(Structure): _fields_ = [("x", c_long), ("y", c_long)] ! tagPOINT = _POINTL = POINTL = POINT class SIZE(Structure): _fields_ = [("cx", c_long), ("cy", c_long)] ! tagSIZE = SIZEL = SIZE def RGB(red, green, blue): *************** *** 63,66 **** --- 106,110 ---- _fields_ = [("dwLowDateTime", DWORD), ("dwHighDateTime", DWORD)] + _FILETIME = FILETIME class MSG(Structure): *************** *** 71,74 **** --- 115,119 ---- ("time", DWORD), ("pt", POINT)] + tagMSG = MSG MAX_PATH = 260 |
From: Thomas H. <th...@us...> - 2006-06-14 09:03:15
|
Update of /cvsroot/ctypes/ctypes/docs/manual In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv14570 Modified Files: reference.txt Log Message: errcheck is only called with three arguments. Add examples for paramflags. Index: reference.txt =================================================================== RCS file: /cvsroot/ctypes/ctypes/docs/manual/reference.txt,v retrieving revision 1.39 retrieving revision 1.40 diff -C2 -d -r1.39 -r1.40 *** reference.txt 14 Jun 2006 08:16:31 -0000 1.39 --- reference.txt 14 Jun 2006 09:03:08 -0000 1.40 *************** *** 236,240 **** The callable will be called with three or more arguments: ! ``callable(result, func, arguments, *others)`` : funcdescni ``result`` is what the foreign function returns, as specified by the ``restype`` attribute. --- 236,240 ---- The callable will be called with three or more arguments: ! ``callable(result, func, arguments)`` : funcdescni ``result`` is what the foreign function returns, as specified by the ``restype`` attribute. *************** *** 252,257 **** raise an exception if the foreign function call failed. - ``others`` will usually be an empty tuple, it is only used in - combination with ``paramflags`` documented below. ``ArgumentError()`` : excdesc --- 252,255 ---- *************** *** 353,357 **** Here is the wrapping with ``ctypes``: ! >>> from ctypes import c_int, WINFUNCTYPE, wndll >>> from ctypes.wintypes import HWND, LPCSTR, UINT >>> prototype = WINFUNCTYPE(c_int, HWND, LPCSTR, LPCSTR, c_uint) --- 351,355 ---- Here is the wrapping with ``ctypes``: ! >>> from ctypes import c_int, WINFUNCTYPE, windll >>> from ctypes.wintypes import HWND, LPCSTR, UINT >>> prototype = WINFUNCTYPE(c_int, HWND, LPCSTR, LPCSTR, c_uint) *************** *** 367,372 **** --- 365,420 ---- >>> + A second example demonstrates output parameters. The win32 + ``GetWindowRect`` function retrieves the dimensions of a specified + window by copying them into ``RECT`` structure that the caller has to + supply. Here is the C declaration:: + + WINUSERAPI BOOL WINAPI + GetWindowRect( + HWND hWnd, + LPRECT lpRect); + + Here is the wrapping with ``ctypes``: + + >>> from ctypes import POINTER, WINFUNCTYPE, windll + >>> from ctypes.wintypes import BOOL, HWND, RECT + >>> prototype = WINFUNCTYPE(BOOL, HWND, POINTER(RECT)) + >>> paramflags = (1, "hwnd"), (2, "lprect") + >>> GetWindowRect = prototype(("GetWindowRect", windll.user32), paramflags) + >>> + + Functions with output parameters will automatically return the output + parameter value if there is a single one, or a tuple containing the + output parameter values when there are more than one, so the + GetWindowRect function now returns a RECT instance, when called. + + Output parameters can be combined with the ``errcheck`` protocol to do + further output processing and error checking. The win32 + ``GetWindowRect`` api function returns a ``BOOL`` to signal success or + failure, so this function could do the error checking, and raises an + exception when the api call failed:: + + >>> def errcheck(result, func, args): + ... if not result: + ... raise WinError() + ... return args + >>> GetWindowRect.errcheck = errcheck + >>> + If the ``errcheck`` function returns the argument tuple it receives + unchanged, ``ctypes`` continues the normal processing it does on the + output parameters. If you want to return a tuple of window + coordinates instead of a ``RECT`` instance, you can retrieve the + fields in the function and return them instead, the normal processing + will no longer take place:: + >>> def errcheck(result, func, args): + ... if not result: + ... raise WinError() + ... rc = args[1] + ... return rc.left, rc.top, rc.bottom, rc.right + >>> + >>> GetWindowRect.errcheck = errcheck + >>> Utility functions |
From: Thomas H. <th...@us...> - 2006-06-14 08:16:34
|
Update of /cvsroot/ctypes/ctypes/docs/manual In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv26580 Modified Files: reference.txt Log Message: First example for paramflags. Index: reference.txt =================================================================== RCS file: /cvsroot/ctypes/ctypes/docs/manual/reference.txt,v retrieving revision 1.38 retrieving revision 1.39 diff -C2 -d -r1.38 -r1.39 *** reference.txt 14 Jun 2006 07:40:00 -0000 1.38 --- reference.txt 14 Jun 2006 08:16:31 -0000 1.39 *************** *** 317,329 **** The optional ``paramflags`` parameter creates foreign function wrappers with much more functionality than the features described ! above, it may be used to implement frameworks with ctypes. ! It must be a sequence of tuples, it must have the same length as ! ``argtypes``. Each item in the ``paramflags`` tuple contains further ! information about each parameter, it must be a tuple again which ! contains 1, 2, or 3 items. ! The first item must be an integer which specifies flags for the ! parameter. The following flag values are defined: 1 --- 317,328 ---- The optional ``paramflags`` parameter creates foreign function wrappers with much more functionality than the features described ! above. ! ``paramflags`` must be a tuple of the same length as ``argtypes``. ! Each item in this tuple contains further information about a ! parameter, it must be a tuple containing 1, 2, or 3 items. ! ! The first item is an integer containing flags for the parameter. 1 *************** *** 336,343 **** Input parameter which defaults to the integer zero. ! The second item is the parameter name. If this is specified, the ! foreign function supports named parameters. - The third item is the default value for this parameter. --- 335,370 ---- Input parameter which defaults to the integer zero. ! The optional second item is the parameter name as string. If this is ! specified, the foreign function can be called with named parameters. ! ! The optional third item is the default value for this parameter. ! ! This example demonstrates how to wrap the Windows ``MessageBoxA`` ! function so that it supports default parameters and named arguments. ! The C declaration from the windows header file is this:: ! ! WINUSERAPI int WINAPI ! MessageBoxA( ! HWND hWnd , ! LPCSTR lpText, ! LPCSTR lpCaption, ! UINT uType); ! ! Here is the wrapping with ``ctypes``: ! ! >>> from ctypes import c_int, WINFUNCTYPE, wndll ! >>> from ctypes.wintypes import HWND, LPCSTR, UINT ! >>> prototype = WINFUNCTYPE(c_int, HWND, LPCSTR, LPCSTR, c_uint) ! >>> paramflags = (1, "hwnd", 0), (1, "text", "Hi"), (1, "caption", None), (1, "flags", 0) ! >>> MessageBox = prototype(("MessageBoxA", windll.user32), paramflags) ! >>> ! ! The MessageBox foreign function can now be called in these ways:: ! ! >>> MessageBox() ! >>> MessageBox(text="Spam, spam, spam") ! >>> MessageBox(flags=2, text="foo bar") ! >>> |
From: Thomas H. <th...@us...> - 2006-06-14 07:40:04
|
Update of /cvsroot/ctypes/ctypes/docs/manual In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv13246 Modified Files: reference.txt Log Message: paramflags. Index: reference.txt =================================================================== RCS file: /cvsroot/ctypes/ctypes/docs/manual/reference.txt,v retrieving revision 1.37 retrieving revision 1.38 diff -C2 -d -r1.37 -r1.38 *** reference.txt 14 Jun 2006 07:24:28 -0000 1.37 --- reference.txt 14 Jun 2006 07:40:00 -0000 1.38 *************** *** 302,306 **** The first item is the name of the exported function as string, or the ordinal of the exported function as small integer. The second ! item must the shared library instance. ``prototype(vtbl_index, name[, paramflags[, iid]])`` : funcdescni --- 302,306 ---- The first item is the name of the exported function as string, or the ordinal of the exported function as small integer. The second ! item is the shared library instance. ``prototype(vtbl_index, name[, paramflags[, iid]])`` : funcdescni *************** *** 315,319 **** those parameters that are specified in the ``argtypes`` tuple. ! XXX Document paramflags. --- 315,344 ---- those parameters that are specified in the ``argtypes`` tuple. ! The optional ``paramflags`` parameter creates foreign function ! wrappers with much more functionality than the features described ! above, it may be used to implement frameworks with ctypes. ! ! It must be a sequence of tuples, it must have the same length as ! ``argtypes``. Each item in the ``paramflags`` tuple contains further ! information about each parameter, it must be a tuple again which ! contains 1, 2, or 3 items. ! ! The first item must be an integer which specifies flags for the ! parameter. The following flag values are defined: ! ! 1 ! Specifies an input parameter to the function. ! ! 2 ! Output parameter. The foreign function fills in a value. ! ! 4 ! Input parameter which defaults to the integer zero. ! ! The second item is the parameter name. If this is specified, the ! foreign function supports named parameters. ! ! The third item is the default value for this parameter. ! |
From: Thomas H. <th...@us...> - 2006-06-14 07:24:32
|
Update of /cvsroot/ctypes/ctypes/docs/manual In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv7893 Modified Files: reference.txt Log Message: Correct markup, 'mkpydoc.py' does not handle tuples in parameter lists. Index: reference.txt =================================================================== RCS file: /cvsroot/ctypes/ctypes/docs/manual/reference.txt,v retrieving revision 1.36 retrieving revision 1.37 diff -C2 -d -r1.36 -r1.37 *** reference.txt 14 Jun 2006 07:13:25 -0000 1.36 --- reference.txt 14 Jun 2006 07:24:28 -0000 1.37 *************** *** 297,308 **** ``callable``. ! ``prototype((name, library)[, paramflags])`` : funcdescni ! Returns a foreign function by looking up ``name`` in the shared ! library ``dll``. ! ! ``prototype((ordinal, library)[, paramflags])`` : funcdescni ! Returns a foreign function which is exported by the ordinal number ! ``ordinal`` in the shared library ``dll``. This mechanism only ! exists on Windows. ``prototype(vtbl_index, name[, paramflags[, iid]])`` : funcdescni --- 297,306 ---- ``callable``. ! ``prototype(func_spec[, paramflags])`` : funcdescni ! Returns a foreign function exported by a shared library. ! ``func_spec`` must be a 2-tuple ``(name_or_ordinal, library)``. ! The first item is the name of the exported function as string, or ! the ordinal of the exported function as small integer. The second ! item must the shared library instance. ``prototype(vtbl_index, name[, paramflags[, iid]])`` : funcdescni |
From: Thomas H. <th...@us...> - 2006-06-14 07:13:28
|
Update of /cvsroot/ctypes/ctypes/docs/manual In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv3748 Modified Files: reference.txt Log Message: *** empty log message *** Index: reference.txt =================================================================== RCS file: /cvsroot/ctypes/ctypes/docs/manual/reference.txt,v retrieving revision 1.35 retrieving revision 1.36 diff -C2 -d -r1.35 -r1.36 *** reference.txt 14 Jun 2006 06:58:37 -0000 1.35 --- reference.txt 14 Jun 2006 07:13:25 -0000 1.36 *************** *** 198,201 **** --- 198,204 ---- Base class for C callable foreign functions. + Instances of foreign functions are also C compatible data types; they + represent C function pointers. + This behaviour can be customized by assigning to special attributes of the foreign function object. *************** *** 252,257 **** combination with ``paramflags`` documented below. ! Instances of foreign functions are also C compatible data types; they ! represent C function pointers. Foreign functions can also be created by instantiating function --- 255,265 ---- combination with ``paramflags`` documented below. ! ``ArgumentError()`` : excdesc ! This exception is raised when a foreign function call cannot ! convert one of the passed arguments. ! ! ! Function prototypes ! ------------------- Foreign functions can also be created by instantiating function *************** *** 311,321 **** XXX Document paramflags. - XXX Where does the exception description belong? - - ``ArgumentError()`` : excdesc - This exception is raised when a foreign function call cannot - convert one of the passed arguments. - - Utility functions --- 319,322 ---- |
From: Thomas H. <th...@us...> - 2006-06-14 06:58:40
|
Update of /cvsroot/ctypes/ctypes/docs/manual In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv29552 Modified Files: reference.txt Log Message: *** empty log message *** Index: reference.txt =================================================================== RCS file: /cvsroot/ctypes/ctypes/docs/manual/reference.txt,v retrieving revision 1.34 retrieving revision 1.35 diff -C2 -d -r1.34 -r1.35 *** reference.txt 14 Jun 2006 06:51:19 -0000 1.34 --- reference.txt 14 Jun 2006 06:58:37 -0000 1.35 *************** *** 195,199 **** private class: ! ``_FuncPtr`` : classdesc Base class for C callable foreign functions. --- 195,199 ---- private class: ! ``_FuncPtr`` : classdesc* Base class for C callable foreign functions. |
From: Thomas H. <th...@us...> - 2006-06-14 06:51:22
|
Update of /cvsroot/ctypes/ctypes/docs/manual In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv26695 Modified Files: reference.txt Log Message: Document the signature of function prototypes. Index: reference.txt =================================================================== RCS file: /cvsroot/ctypes/ctypes/docs/manual/reference.txt,v retrieving revision 1.33 retrieving revision 1.34 diff -C2 -d -r1.33 -r1.34 *** reference.txt 14 Jun 2006 06:19:43 -0000 1.33 --- reference.txt 14 Jun 2006 06:51:19 -0000 1.34 *************** *** 279,289 **** Function prototypes created by the factory functions can be ! instantiated in different ways, depending on how they are called. ! prototype(integer address) -> foreign function ! prototype(callable) -> create and return a C callable function from callable ! prototype(integer index, method name[, paramflags]) -> foreign function calling a COM method ! prototype((ordinal number, dll object)[, paramflags]) -> foreign function exported by ordinal ! prototype((function name, dll object)[, paramflags]) -> foreign function exported by name XXX Where does the exception description belong? --- 279,313 ---- Function prototypes created by the factory functions can be ! instantiated in different ways, depending on the type and number of ! the parameters in the call. ! ``prototype(address)`` : funcdescni ! Returns a foreign function at the specified address. ! ! ``prototype(callable)`` : funcdescni ! Create a C callable function (a callback function) from a Python ! ``callable``. ! ! ``prototype((name, library)[, paramflags])`` : funcdescni ! Returns a foreign function by looking up ``name`` in the shared ! library ``dll``. ! ! ``prototype((ordinal, library)[, paramflags])`` : funcdescni ! Returns a foreign function which is exported by the ordinal number ! ``ordinal`` in the shared library ``dll``. This mechanism only ! exists on Windows. ! ! ``prototype(vtbl_index, name[, paramflags[, iid]])`` : funcdescni ! Returns a foreign function that will call a COM method. ! ``vtbl_index`` is the index into the virtual function table, a ! small nonnegative integer. ``name`` is name of the COM method. ! ``iid`` is an optional pointer to the interface identifier which ! is used in extended error reporting. ! ! COM methods use a special calling convention: They require a ! pointer to the COM interface as first argument, in addition to ! those parameters that are specified in the ``argtypes`` tuple. ! ! XXX Document paramflags. XXX Where does the exception description belong? |
From: Thomas H. <th...@us...> - 2006-06-14 06:19:46
|
Update of /cvsroot/ctypes/ctypes/docs/manual In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv13672 Modified Files: reference.txt Log Message: *** empty log message *** Index: reference.txt =================================================================== RCS file: /cvsroot/ctypes/ctypes/docs/manual/reference.txt,v retrieving revision 1.32 retrieving revision 1.33 diff -C2 -d -r1.32 -r1.33 *** reference.txt 14 Jun 2006 06:16:16 -0000 1.32 --- reference.txt 14 Jun 2006 06:19:43 -0000 1.33 *************** *** 195,199 **** private class: ! ``_FuncPtr`` : classdescni Base class for C callable foreign functions. --- 195,199 ---- private class: ! ``_FuncPtr`` : classdesc Base class for C callable foreign functions. *************** *** 278,287 **** GIL during the call. ! Instantiating function prototypes ! ................................. ! ! Function prototypes created by the factory functions can be instatiated ! in different ways, depending on how they are called. XXX Where does the exception description belong? --- 278,289 ---- GIL during the call. ! Function prototypes created by the factory functions can be ! instantiated in different ways, depending on how they are called. + prototype(integer address) -> foreign function + prototype(callable) -> create and return a C callable function from callable + prototype(integer index, method name[, paramflags]) -> foreign function calling a COM method + prototype((ordinal number, dll object)[, paramflags]) -> foreign function exported by ordinal + prototype((function name, dll object)[, paramflags]) -> foreign function exported by name XXX Where does the exception description belong? |
From: Thomas H. <th...@us...> - 2006-06-14 06:16:19
|
Update of /cvsroot/ctypes/ctypes/docs/manual In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv12491 Modified Files: reference.txt Log Message: *** empty log message *** Index: reference.txt =================================================================== RCS file: /cvsroot/ctypes/ctypes/docs/manual/reference.txt,v retrieving revision 1.31 retrieving revision 1.32 diff -C2 -d -r1.31 -r1.32 *** reference.txt 14 Jun 2006 06:13:24 -0000 1.31 --- reference.txt 14 Jun 2006 06:16:16 -0000 1.32 *************** *** 192,196 **** objects created in this way by default accept any number of arguments, accept any ctypes data instances as arguments, and return the default ! result type specified by the library loader. This behaviour can be customized by assigning to special attributes of --- 192,200 ---- objects created in this way by default accept any number of arguments, accept any ctypes data instances as arguments, and return the default ! result type specified by the library loader. They are instances of a ! private class: ! ! ``_FuncPtr`` : classdescni ! Base class for C callable foreign functions. This behaviour can be customized by assigning to special attributes of |
From: Thomas H. <th...@us...> - 2006-06-14 06:13:27
|
Update of /cvsroot/ctypes/ctypes/docs/manual In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv11319 Modified Files: reference.txt Log Message: Markup. Index: reference.txt =================================================================== RCS file: /cvsroot/ctypes/ctypes/docs/manual/reference.txt,v retrieving revision 1.30 retrieving revision 1.31 diff -C2 -d -r1.30 -r1.31 *** reference.txt 14 Jun 2006 06:01:42 -0000 1.30 --- reference.txt 14 Jun 2006 06:13:24 -0000 1.31 *************** *** 210,214 **** ``errcheck`` attribute. ! ``argtypes``: memberdesc Assign a tuple of ctypes types to specify the argument types that the function accepts. Functions using the ``stdcall`` calling --- 210,214 ---- ``errcheck`` attribute. ! ``argtypes`` : memberdesc Assign a tuple of ctypes types to specify the argument types that the function accepts. Functions using the ``stdcall`` calling |