ctypes-commit Mailing List for ctypes (Page 21)
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-03-03 17:16:22
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29594 Modified Files: Tag: branch_1_0 setup.py Log Message: Change version number to 0.9.9.4. Index: setup.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/setup.py,v retrieving revision 1.122.2.17 retrieving revision 1.122.2.18 diff -C2 -d -r1.122.2.17 -r1.122.2.18 *** setup.py 3 Mar 2006 16:26:11 -0000 1.122.2.17 --- setup.py 3 Mar 2006 17:16:14 -0000 1.122.2.18 *************** *** 12,16 **** LIBFFI_SOURCES='source/libffi' ! __version__ = "0.9.9.3" ################################################################ --- 12,16 ---- LIBFFI_SOURCES='source/libffi' ! __version__ = "0.9.9.4" ################################################################ |
From: Thomas H. <th...@us...> - 2006-03-03 17:05:43
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20607 Removed Files: Tag: branch_1_0 run_remote_test.py remotetest.py Log Message: Remove files no longer needed. --- run_remote_test.py DELETED --- --- remotetest.py DELETED --- |
From: Thomas H. <th...@us...> - 2006-03-01 19:52:20
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22815 Removed Files: Tag: branch_1_0 MANIFEST.windows.in MANIFEST.other.in Log Message: Remove platform-specific MANIFEST files. --- MANIFEST.other.in DELETED --- --- MANIFEST.windows.in DELETED --- |
From: Thomas H. <th...@us...> - 2006-03-01 19:51:44
|
Update of /cvsroot/ctypes/ctypes/wince In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22433 Modified Files: Tag: branch_1_0 .cvsignore Log Message: Ignore temporary files. Index: .cvsignore =================================================================== RCS file: /cvsroot/ctypes/ctypes/wince/Attic/.cvsignore,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -C2 -d -r1.1.2.2 -r1.1.2.3 *** .cvsignore 12 Jan 2006 12:22:09 -0000 1.1.2.2 --- .cvsignore 1 Mar 2006 19:51:32 -0000 1.1.2.3 *************** *** 1,6 **** --- 1,12 ---- ARMV4Dbg ARMV4Rel + _ctypes.dep _ctypes.vcb _ctypes.vcl + _ctypes.vcn _ctypes.vco + _ctypes_test.dep + _ctypes_test.vcb _ctypes_test.vcl + _ctypes_test.vcn + _ctypes_test.vco |
From: Thomas H. <th...@us...> - 2006-03-01 19:38:14
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10019 Modified Files: Tag: branch_1_0 setup.py Added Files: Tag: branch_1_0 MANIFEST.in Log Message: Use the same MANIFEST.in file on all platforms. Index: setup.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/setup.py,v retrieving revision 1.122.2.15 retrieving revision 1.122.2.16 diff -C2 -d -r1.122.2.15 -r1.122.2.16 *** setup.py 14 Feb 2006 19:02:39 -0000 1.122.2.15 --- setup.py 1 Mar 2006 19:38:11 -0000 1.122.2.16 *************** *** 269,290 **** # the ctypes package # ! packages = ["ctypes", "ctypes.wrap", "ctypes.macholib", "ctypes.test"] ! package_dir = {} ! ! ################################################################ ! # options for distutils ! # ! setup_options = {} ! ! if sys.platform == 'win32': ! # Use different MANIFEST templates, to minimize the distribution ! # size. Also, the MANIFEST templates behave differently on ! # Windows and Linux (distutils bug?). ! # Finally, force rebuilding the MANIFEST file ! ! setup_options["sdist"] = {"template": "MANIFEST.windows.in", "force_manifest": 1} ! else: ! setup_options["sdist"] = {"template": "MANIFEST.other.in", "force_manifest": 1} ! data_files = [] ################################################################ --- 269,275 ---- # the ctypes package # ! packages = ["ctypes", "ctypes.macholib", ! "ctypes.wrap", ! "ctypes.test"] ################################################################ *************** *** 307,310 **** --- 292,297 ---- # main section # + ##from ce import ce_install_lib + if __name__ == '__main__': setup(name="ctypes", *************** *** 312,318 **** ## "h2xml = ctypes.wrap.h2xml:main"]}, ext_modules = extensions, - package_dir = package_dir, packages = packages, - data_files = data_files, classifiers = classifiers, --- 299,303 ---- *************** *** 328,333 **** cmdclass = {'test': test, 'build_py': my_build_py, 'build_ext': my_build_ext, ! 'clean': my_clean, 'install_data': my_install_data}, ! options = setup_options ) --- 313,320 ---- cmdclass = {'test': test, 'build_py': my_build_py, 'build_ext': my_build_ext, ! 'clean': my_clean, 'install_data': my_install_data, ! ## 'ce_install_lib': ce_install_lib ! }, ! ) --- NEW FILE: MANIFEST.in --- # standard files include ACKS ANNOUNCE ChangeLog MANIFEST MANIFEST.in LICENSE.txt NEWS.txt README* # support files for development include ctypes-dev.el include ctypes/.CTYPES_DEVEL include setup.py include test-cf.py include setup.cfg # libffi build files include source/libffi/aclocal.m4 include source/libffi/config.guess include source/libffi/config.sub include source/libffi/configure include source/libffi/configure.ac include source/libffi/fficonfig.h.in include source/libffi/fficonfig.py.in include source/libffi/install-sh include source/libffi/LICENSE include source/libffi/README # all source files recursive-include source *.c *.h *.S *.asm *.in # windows CE project files include wince/_ctypes.vcw wince/_ctypes.vcp wince/_ctypes_test.vcp # docs/manual include docs/manual/*.txt include docs/manual/*.html |
From: Thomas H. <th...@us...> - 2006-03-01 19:36:19
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7803 Modified Files: Tag: branch_1_0 ChangeLog Log Message: *** empty log message *** Index: ChangeLog =================================================================== RCS file: /cvsroot/ctypes/ctypes/ChangeLog,v retrieving revision 1.86.2.45 retrieving revision 1.86.2.46 diff -C2 -d -r1.86.2.45 -r1.86.2.46 *** ChangeLog 1 Mar 2006 19:35:27 -0000 1.86.2.45 --- ChangeLog 1 Mar 2006 19:36:12 -0000 1.86.2.46 *************** *** 1,4 **** --- 1,7 ---- 2006-03-01 Thomas Heller <th...@py...> + * (Repository): Removed the samples subdirectory completely, + because it has become out of sync. + * (Repository): Moved the ctypes.wintypes module into the ctypes/ directory, got rid of the platform specific modules magic in setup.py |
From: Thomas H. <th...@us...> - 2006-03-01 19:35:30
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7140 Modified Files: Tag: branch_1_0 ChangeLog Log Message: *** empty log message *** Index: ChangeLog =================================================================== RCS file: /cvsroot/ctypes/ctypes/ChangeLog,v retrieving revision 1.86.2.44 retrieving revision 1.86.2.45 diff -C2 -d -r1.86.2.44 -r1.86.2.45 *** ChangeLog 28 Feb 2006 21:08:16 -0000 1.86.2.44 --- ChangeLog 1 Mar 2006 19:35:27 -0000 1.86.2.45 *************** *** 1,2 **** --- 1,10 ---- + 2006-03-01 Thomas Heller <th...@py...> + + * (Repository): Moved the ctypes.wintypes module into the ctypes/ + directory, got rid of the platform specific modules magic in setup.py + and the .CTYPES_DEVEL file. + + * source\callbacks.c: Checked the return value of PyErr_Warn(). + 2006-02-28 Thomas Heller <th...@py...> |
From: Thomas H. <th...@us...> - 2006-03-01 19:31:38
|
Update of /cvsroot/ctypes/ctypes/win32 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2553 Removed Files: Tag: branch_1_0 wintypes.py .cvsignore Log Message: Cleanup: the ctypes.wintypes module is now in the ctypes/wintypes subdirectory, and it is included independend of the platform. --- .cvsignore DELETED --- --- wintypes.py DELETED --- |
From: Thomas H. <th...@us...> - 2006-03-01 19:31:30
|
Update of /cvsroot/ctypes/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2374 Modified Files: Tag: branch_1_0 .CTYPES_DEVEL Added Files: Tag: branch_1_0 wintypes.py Log Message: Cleanup: the ctypes.wintypes module is now in the ctypes/wintypes subdirectory, and it is included independend of the platform. Index: .CTYPES_DEVEL =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/.CTYPES_DEVEL,v retrieving revision 1.4 retrieving revision 1.4.4.1 diff -C2 -d -r1.4 -r1.4.4.1 *** .CTYPES_DEVEL 21 Sep 2004 14:24:12 -0000 1.4 --- .CTYPES_DEVEL 1 Mar 2006 19:31:27 -0000 1.4.4.1 *************** *** 3,13 **** import sys, os - p = os.path.abspath( - os.path.join(os.path.dirname(__file__), "..", sys.platform)) - try: - __path__.insert(0, p) - except NameError: - pass # when ctypes/__init__.py is imported *not* as package - from distutils.util import get_platform plat_specifier = ".%s-%s" % (get_platform(), sys.version[0:3]) --- 3,6 ---- --- NEW FILE: wintypes.py --- 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): _fields_ = [("left", c_long), ("top", c_long), ("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): return red + (green << 8) + (blue << 16) class FILETIME(Structure): _fields_ = [("dwLowDateTime", DWORD), ("dwHighDateTime", DWORD)] class MSG(Structure): _fields_ = [("hWnd", HWND), ("message", c_uint), ("wParam", WPARAM), ("lParam", LPARAM), ("time", DWORD), ("pt", POINT)] MAX_PATH = 260 class WIN32_FIND_DATAA(Structure): _fields_ = [("dwFileAttributes", DWORD), ("ftCreationTime", FILETIME), ("ftLastAccessTime", FILETIME), ("ftLastWriteTime", FILETIME), ("nFileSizeHigh", DWORD), ("nFileSizeLow", DWORD), ("dwReserved0", DWORD), ("dwReserved1", DWORD), ("cFileName", c_char * MAX_PATH), ("cAlternameFileName", c_char * 14)] class WIN32_FIND_DATAW(Structure): _fields_ = [("dwFileAttributes", DWORD), ("ftCreationTime", FILETIME), ("ftLastAccessTime", FILETIME), ("ftLastWriteTime", FILETIME), ("nFileSizeHigh", DWORD), ("nFileSizeLow", DWORD), ("dwReserved0", DWORD), ("dwReserved1", DWORD), ("cFileName", c_wchar * MAX_PATH), ("cAlternameFileName", c_wchar * 14)] |
From: Thomas H. <th...@us...> - 2006-03-01 19:22:21
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26194 Modified Files: Tag: branch_1_0 callbacks.c Log Message: Check the return value of PyErr_Warn (it can raise an exception!). Index: callbacks.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/callbacks.c,v retrieving revision 1.71.2.9 retrieving revision 1.71.2.10 diff -C2 -d -r1.71.2.9 -r1.71.2.10 *** callbacks.c 22 Feb 2006 21:06:01 -0000 1.71.2.9 --- callbacks.c 1 Mar 2006 19:22:17 -0000 1.71.2.10 *************** *** 252,257 **** else if (keep == Py_None) /* Nothing to keep */ Py_DECREF(keep); ! else if (setfunc != getentry("O")->setfunc) ! PyErr_Warn(PyExc_RuntimeWarning, "memory leak in callback function."); } Py_XDECREF(result); --- 252,260 ---- else if (keep == Py_None) /* Nothing to keep */ Py_DECREF(keep); ! else if (setfunc != getentry("O")->setfunc) { ! if (-1 == PyErr_Warn(PyExc_RuntimeWarning, ! "memory leak in callback function.")) ! PyErr_WriteUnraisable(Py_None); ! } } Py_XDECREF(result); |
From: Thomas H. <th...@us...> - 2006-02-22 21:22:29
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11661 Modified Files: Tag: branch_1_0 cfield.c callproc.c Log Message: Fix the refcounts for py_object instances as far as I currently understand them. Index: callproc.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/callproc.c,v retrieving revision 1.127.2.27 retrieving revision 1.127.2.28 diff -C2 -d -r1.127.2.27 -r1.127.2.28 *** callproc.c 16 Feb 2006 00:17:25 -0000 1.127.2.27 --- callproc.c 22 Feb 2006 21:22:25 -0000 1.127.2.28 *************** *** 716,722 **** return PyObject_CallFunction(restype, "i", *(int *)result); ! if (dict->getfunc && !IsSimpleSubType(restype)) retval = dict->getfunc(result, dict->size); ! else retval = CData_FromBaseObj(restype, NULL, 0, result); --- 716,728 ---- return PyObject_CallFunction(restype, "i", *(int *)result); ! if (dict->getfunc && !IsSimpleSubType(restype)) { retval = dict->getfunc(result, dict->size); ! /* If restype is py_object (detected by comparing getfunc with ! O_get), we have to call Py_DECREF because O_get has already ! called Py_INCREF. ! */ ! if (dict->getfunc == getentry("O")->getfunc) ! Py_DECREF(retval); ! } else retval = CData_FromBaseObj(restype, NULL, 0, result); Index: cfield.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/cfield.c,v retrieving revision 1.74.2.18 retrieving revision 1.74.2.19 diff -C2 -d -r1.74.2.18 -r1.74.2.19 *** cfield.c 21 Feb 2006 21:03:24 -0000 1.74.2.18 --- cfield.c 22 Feb 2006 21:22:25 -0000 1.74.2.19 *************** *** 991,1010 **** /* ! XXX ! ! Hm, what about py_object refcounts? 1. If we have a py_object instance, O_get must Py_INCREF the returned object, of course. If O_get is called from a function result, no py_object ! instance is created - and a Py_INCREF in O_get would leak a refcount. 2. The memory block in py_object owns a refcount. So, py_object must call Py_DECREF on destruction. Maybe only when b_needsfree is non-zero. - - The above problem also occurs in other simple data types containing 'system - resources' when they are returned from functions: BSTR, VARIANT. - Fortunately, we don't use functions returning these types. The - SysAllocString calls that we have return only an address, and we feed that - into BSTR instances. XXX Have to check if this is really true. */ static PyObject * --- 991,1002 ---- /* ! py_object refcounts: 1. If we have a py_object instance, O_get must Py_INCREF the returned object, of course. If O_get is called from a function result, no py_object ! instance is created - so callproc.c::GetResult has to call Py_DECREF. 2. The memory block in py_object owns a refcount. So, py_object must call Py_DECREF on destruction. Maybe only when b_needsfree is non-zero. */ static PyObject * *************** *** 1019,1024 **** return NULL; } ! /* XXX See above */ ! // Py_INCREF(ob); return ob; } --- 1011,1015 ---- return NULL; } ! Py_INCREF(ob); return ob; } *************** *** 1027,1030 **** --- 1018,1022 ---- O_set(void *ptr, PyObject *value, unsigned size) { + /* Hm, does the memory block need it's own refcount or not? */ *(PyObject **)ptr = value; Py_INCREF(value); |
From: Thomas H. <th...@us...> - 2006-02-22 21:21:14
|
Update of /cvsroot/ctypes/ctypes/ctypes/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10634 Modified Files: Tag: branch_1_0 test_callbacks.py Log Message: Comment out a test that will leak memory - it will also raise a RuntimeWarning, so that's ok. Add another test that I don't yet understand - it leaks one single refcount, independend from how often it is run. Index: test_callbacks.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/test/Attic/test_callbacks.py,v retrieving revision 1.1.2.3 retrieving revision 1.1.2.4 diff -C2 -d -r1.1.2.3 -r1.1.2.4 *** test_callbacks.py 22 Feb 2006 19:57:48 -0000 1.1.2.3 --- test_callbacks.py 22 Feb 2006 21:21:08 -0000 1.1.2.4 *************** *** 82,97 **** self.check_type(c_char, "a") ! def test_char_p(self): ! self.check_type(c_char_p, "abc") ! self.check_type(c_char_p, "def") ! ## def test_pyobject(self): ! ## o = () ! ## from sys import getrefcount as grc ! ## for o in (), [], object(): ! ## before = grc(o) ! ## self.check_type(py_object, o) ! ## after = grc(o) ! ## self.failUnlessEqual((after, o), (before, o)) try: --- 82,104 ---- self.check_type(c_char, "a") ! # disabled: would now (correctly) raise a RuntimeWarning about ! # a memory leak. A callback function cannot return a non-integral ! # C type without causing a memory leak. ! ## def test_char_p(self): ! ## self.check_type(c_char_p, "abc") ! ## self.check_type(c_char_p, "def") ! def test_pyobject(self): ! o = () ! from sys import getrefcount as grc ! for o in (), [], object(): ! initial = grc(o) ! # This call leaks a reference to 'o'... ! self.check_type(py_object, o) ! before = grc(o) ! # ...but this call doesn't leak any more. Where is the refcount? ! self.check_type(py_object, o) ! after = grc(o) ! self.failUnlessEqual((after, o), (before, o)) try: |
From: Thomas H. <th...@us...> - 2006-02-22 21:06:59
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3189 Modified Files: Tag: branch_1_0 ChangeLog Log Message: Index: ChangeLog =================================================================== RCS file: /cvsroot/ctypes/ctypes/ChangeLog,v retrieving revision 1.86.2.42 retrieving revision 1.86.2.43 diff -C2 -d -r1.86.2.42 -r1.86.2.43 *** ChangeLog 21 Feb 2006 19:40:36 -0000 1.86.2.42 --- ChangeLog 22 Feb 2006 21:06:50 -0000 1.86.2.43 *************** *** 1,2 **** --- 1,14 ---- + 2006-02-22 Thomas Heller <th...@py...> + + * source/callbacks.c: Discovered and hacked around a problem with callback functions. + + If the callback function has a return type other than void, + py_object, or an integral C type, it is impossible to either avoid + a memory leak or return a possibly invalid result. Previously, + the possibly invalid result has been returned, now the memory leak + will appear but a "RuntimeWarning: memory leak in callback + function" will be emitted. + + 2006-02-21 Thomas Heller <th...@py...> |
From: Thomas H. <th...@us...> - 2006-02-22 21:06:19
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2755 Modified Files: Tag: branch_1_0 callbacks.c Log Message: Discovered and hacked around a problem with callback functions. If the callback function has a return type other than void, py_object, or an integral C type, it is impossible to either avoid a memory leak or return a possibly invalid result. Previously, the possibly invalid result has been returned, now the memory leak will appear but a "RuntimeWarning: memory leak in callback function" will be emitted. Index: callbacks.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/callbacks.c,v retrieving revision 1.71.2.8 retrieving revision 1.71.2.9 diff -C2 -d -r1.71.2.8 -r1.71.2.9 *** callbacks.c 2 Jan 2006 19:02:52 -0000 1.71.2.8 --- callbacks.c 22 Feb 2006 21:06:01 -0000 1.71.2.9 *************** *** 239,246 **** break; } ! /* assert (keep == Py_None); */ ! /* XXX We have no way to keep the needed reference XXX */ ! /* Should we emit a warning? */ ! Py_XDECREF(keep); } Py_XDECREF(result); --- 239,257 ---- break; } ! /* keep is an object we have to keep alive so that the result ! stays valid. If there is no such object, the setfunc will ! have returned Py_None. ! ! If there is such an object, we have no choice than to keep ! it alive forever - but a refcount and/or memory leak will ! be the result. EXCEPT when restype is py_object - Python ! itself knows how to manage the refcount of these objects. ! */ ! if (keep == NULL) /* Could not convert callback result. */ ! PyErr_WriteUnraisable(Py_None); ! else if (keep == Py_None) /* Nothing to keep */ ! Py_DECREF(keep); ! else if (setfunc != getentry("O")->setfunc) ! PyErr_Warn(PyExc_RuntimeWarning, "memory leak in callback function."); } Py_XDECREF(result); |
Update of /cvsroot/ctypes/ctypes/samples In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12325 Removed Files: Tag: branch_1_0 test_time.py test_strchr.py test_clib.py test_argcount.py rt23.bat rt.bat rt README.txt .cvsignore Log Message: Remove the samples. --- .cvsignore DELETED --- --- rt DELETED --- --- test_time.py DELETED --- --- test_strchr.py DELETED --- --- test_argcount.py DELETED --- --- test_clib.py DELETED --- --- rt23.bat DELETED --- --- README.txt DELETED --- --- rt.bat DELETED --- |
From: Thomas H. <th...@us...> - 2006-02-21 21:03:27
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4672 Modified Files: Tag: branch_1_0 cfield.c Log Message: Add to-do style comment. Index: cfield.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/cfield.c,v retrieving revision 1.74.2.17 retrieving revision 1.74.2.18 diff -C2 -d -r1.74.2.17 -r1.74.2.18 *** cfield.c 1 Feb 2006 20:52:50 -0000 1.74.2.17 --- cfield.c 21 Feb 2006 21:03:24 -0000 1.74.2.18 *************** *** 990,993 **** --- 990,1011 ---- } + /* + XXX + + Hm, what about py_object refcounts? + + 1. If we have a py_object instance, O_get must Py_INCREF the returned + object, of course. If O_get is called from a function result, no py_object + instance is created - and a Py_INCREF in O_get would leak a refcount. + + 2. The memory block in py_object owns a refcount. So, py_object must call + Py_DECREF on destruction. Maybe only when b_needsfree is non-zero. + + The above problem also occurs in other simple data types containing 'system + resources' when they are returned from functions: BSTR, VARIANT. + Fortunately, we don't use functions returning these types. The + SysAllocString calls that we have return only an address, and we feed that + into BSTR instances. XXX Have to check if this is really true. + */ static PyObject * O_get(void *ptr, unsigned size) *************** *** 1001,1004 **** --- 1019,1024 ---- return NULL; } + /* XXX See above */ + // Py_INCREF(ob); return ob; } |
From: Thomas H. <th...@us...> - 2006-02-21 19:40:40
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28612 Modified Files: Tag: branch_1_0 ChangeLog Log Message: Index: ChangeLog =================================================================== RCS file: /cvsroot/ctypes/ctypes/ChangeLog,v retrieving revision 1.86.2.41 retrieving revision 1.86.2.42 diff -C2 -d -r1.86.2.41 -r1.86.2.42 *** ChangeLog 16 Feb 2006 00:17:25 -0000 1.86.2.41 --- ChangeLog 21 Feb 2006 19:40:36 -0000 1.86.2.42 *************** *** 1,2 **** --- 1,15 ---- + 2006-02-21 Thomas Heller <th...@py...> + + * source/_ctypes.c: The _b_needsfree_ member is now always 1 if + the object 'owns' it's memory buffer (even if it uses it's small + builtin buffer, instead of mallocing a new one). This is useful + to determine whether resources in the buffer need to be freed when + the object is destroyed. + + * source/_ctypes.c: Finally fix this nasty 'set array through + pointer' bug. See ctypes.test.test_array_in_pointer + + * source/malloc_closure.c: Fix compilation on Windows. + 2006-02-15 Bob Ippolito <bo...@re...> |
From: Thomas H. <th...@us...> - 2006-02-21 19:39:11
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27736 Modified Files: Tag: branch_1_0 _ctypes.c Log Message: The _b_needsfree_ member is now always 1 if the object 'owns' it's memory buffer (even if it uses it's small builtin buffer, instead of mallocing a new one). Index: _ctypes.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes.c,v retrieving revision 1.226.2.53 retrieving revision 1.226.2.54 diff -C2 -d -r1.226.2.53 -r1.226.2.54 *** _ctypes.c 21 Feb 2006 19:05:51 -0000 1.226.2.53 --- _ctypes.c 21 Feb 2006 19:39:04 -0000 1.226.2.54 *************** *** 1846,1851 **** CData_clear(CDataObject *self) { Py_CLEAR(self->b_objects); ! if (self->b_needsfree) PyMem_Free(self->b_ptr); self->b_ptr = NULL; --- 1846,1853 ---- CData_clear(CDataObject *self) { + StgDictObject *dict = PyObject_stgdict((PyObject *)self); Py_CLEAR(self->b_objects); ! if ((self->b_needsfree) ! && (dict->size > sizeof(self->b_value))) PyMem_Free(self->b_ptr); self->b_ptr = NULL; *************** *** 1971,1975 **** /* No need to call malloc, can use the default buffer */ obj->b_ptr = (char *)&obj->b_value; ! obj->b_needsfree = 0; } else { /* In python 2.4, and ctypes 0.9.6, the malloc call took about --- 1973,1977 ---- /* No need to call malloc, can use the default buffer */ obj->b_ptr = (char *)&obj->b_value; ! obj->b_needsfree = 1; } else { /* In python 2.4, and ctypes 0.9.6, the malloc call took about *************** *** 3146,3153 **** Py_CLEAR(self->paramflags); - if (self->b_needsfree) - PyMem_Free(self->b_ptr); - self->b_ptr = NULL; - if (self->thunk) FreeCallback(self->thunk); --- 3148,3151 ---- |
From: Thomas H. <th...@us...> - 2006-02-18 20:31:02
|
Update of /cvsroot/ctypes/ctypes/comtypes/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32496 Modified Files: Tag: branch_1_0 test_variant.py Log Message: This test deomstrates the 'set values through pointer' bug. Requires "buggy" now. Index: test_variant.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/test/Attic/test_variant.py,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -C2 -d -r1.1.2.1 -r1.1.2.2 *** test_variant.py 16 Feb 2006 20:35:42 -0000 1.1.2.1 --- test_variant.py 18 Feb 2006 20:30:57 -0000 1.1.2.2 *************** *** 4,7 **** --- 4,8 ---- from comtypes.automation import VARIANT, DISPPARAMS from comtypes.typeinfo import LoadTypeLibEx, LoadRegTypeLib + from ctypes.test import is_resource_enabled def get_refcnt(comptr): *************** *** 48,61 **** v = VARIANT(p) self.failUnlessEqual(get_refcnt(p), 0) ! ! def test_dispparams(self): ! # DISPPARAMS is a complex structure, well worth testing. ! d = DISPPARAMS() ! d.rgvarg = (VARIANT * 3)() ! # XXX The following line fails, which is a real bug in ctypes: ! # SystemError: ...\Objects\listobject.c:105: bad argument to internal function ! # ! # Update: this bug is fixed, now I have to rememeber what I wanted to test here. ! d.rgvarg[0].value = 1 def test_pythonobjects(self): --- 49,63 ---- v = VARIANT(p) self.failUnlessEqual(get_refcnt(p), 0) ! ! if is_resource_enabled("buggy"): ! def test_dispparams(self): ! # DISPPARAMS is a complex structure, well worth testing. ! d = DISPPARAMS() ! d.rgvarg = (VARIANT * 3)() ! values = [1, 5, 7] ! for i, v in enumerate(values): ! d.rgvarg[i].value = v ! result = [d.rgvarg[i].value for i in range(3)] ! self.failUnlessEqual(result, values) def test_pythonobjects(self): |
From: Thomas H. <th...@us...> - 2006-02-17 21:21:52
|
Update of /cvsroot/ctypes/ctypes/docs/manual In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28728 Modified Files: Tag: branch_1_0 simple_types.txt manual.html Log Message: _type_ is a class attribute, not an instance attribute of simple types. Index: manual.html =================================================================== RCS file: /cvsroot/ctypes/ctypes/docs/manual/Attic/manual.html,v retrieving revision 1.1.2.11 retrieving revision 1.1.2.12 diff -C2 -d -r1.1.2.11 -r1.1.2.12 *** manual.html 17 Feb 2006 21:18:16 -0000 1.1.2.11 --- manual.html 17 Feb 2006 21:21:48 -0000 1.1.2.12 *************** *** 448,461 **** <div class="section"> <h2><a class="toc-backref" href="#id4" id="library-objects" name="library-objects">Library objects</a></h2> ! <p>The library loaders return instances of <tt class="docutils literal"><span class="pre">CDLL</span></tt>, <tt class="docutils literal"><span class="pre">WinDLL</span></tt>, <tt class="docutils literal"><span class="pre">OleDLL</span></tt>, or <tt class="docutils literal"><span class="pre">PyDLL</span></tt> classes. You can, however, also load a library by constructing one of these classes by calling the constructor with the pathname of the library and an optional <tt class="docutils literal"><span class="pre">mode</span></tt> argument as described in the previous section.</p> ! <p>These classes implement <tt class="docutils literal"><span class="pre">__getattr__</span></tt> and <tt class="docutils literal"><span class="pre">__getitem__</span></tt> methods ! that allow to access foreign functions by attribute access or indexing. ! The latter is useful if the name of the function is not a valid Python ! identifier, or clashes with special Python method names that start and ! end with two underscore characters.</p> <p>Library objects have two private attributes: <tt class="docutils literal"><span class="pre">_name</span></tt> is the pathname of the library, <tt class="docutils literal"><span class="pre">_handle</span></tt> is the handle to the library that --- 448,461 ---- <div class="section"> <h2><a class="toc-backref" href="#id4" id="library-objects" name="library-objects">Library objects</a></h2> ! <p>The library loaders create instances of <tt class="docutils literal"><span class="pre">CDLL</span></tt>, <tt class="docutils literal"><span class="pre">WinDLL</span></tt>, <tt class="docutils literal"><span class="pre">OleDLL</span></tt>, or <tt class="docutils literal"><span class="pre">PyDLL</span></tt> classes. You can, however, also load a library by constructing one of these classes by calling the constructor with the pathname of the library and an optional <tt class="docutils literal"><span class="pre">mode</span></tt> argument as described in the previous section.</p> ! <p>Library objects implement <tt class="docutils literal"><span class="pre">__getattr__</span></tt> and <tt class="docutils literal"><span class="pre">__getitem__</span></tt> methods ! that allow to access foreign functions by attribute access or ! indexing. The latter is useful if the name of the function is not a ! valid Python identifier, or clashes with special Python method names ! that start and end with two underscore characters.</p> <p>Library objects have two private attributes: <tt class="docutils literal"><span class="pre">_name</span></tt> is the pathname of the library, <tt class="docutils literal"><span class="pre">_handle</span></tt> is the handle to the library that *************** *** 471,475 **** --- 471,478 ---- libc = cdll.find("c") # posix libc = cdll.msvcrt # windows + # attribute access atoi = libc.atoi + # alternative indexing notation + atoi = libc["atoi"] </pre> <p>This creates an instance of a foreign function object, using the *************** *** 623,626 **** --- 626,635 ---- <tt class="docutils literal"><span class="pre">c_int.__ctype_be__</span></tt> is an integer type with the memory block in big endian byte order.</blockquote> + <p><tt class="docutils literal"><span class="pre">_type_</span></tt></p> + <blockquote> + Implementation artifact: the typecode for this type, a single + character string code compatible to what the <tt class="docutils literal"><span class="pre">struct</span></tt> module uses. + Additional characters are used for types that the <tt class="docutils literal"><span class="pre">struct</span></tt> module + does not support.</blockquote> </div> <div class="section"> *************** *** 660,669 **** <div class="section"> <h2><a class="toc-backref" href="#id13" id="instance-attributes-of-simple-types" name="instance-attributes-of-simple-types">Instance attributes of simple types</a></h2> - <p><tt class="docutils literal"><span class="pre">_type_</span></tt></p> - <blockquote> - Implementation artifact: the typecode for this type, a single - character string code compatible to what the struct module uses. - Additional characters are used for types that the struct module - does not support.</blockquote> <p><tt class="docutils literal"><span class="pre">_objects</span></tt> (never modify this)</p> <blockquote> --- 669,672 ---- Index: simple_types.txt =================================================================== RCS file: /cvsroot/ctypes/ctypes/docs/manual/Attic/simple_types.txt,v retrieving revision 1.1.2.4 retrieving revision 1.1.2.5 diff -C2 -d -r1.1.2.4 -r1.1.2.5 *** simple_types.txt 17 Feb 2006 20:38:04 -0000 1.1.2.4 --- simple_types.txt 17 Feb 2006 21:21:48 -0000 1.1.2.5 *************** *** 23,26 **** --- 23,34 ---- big endian byte order. + ``_type_`` + + Implementation artifact: the typecode for this type, a single + character string code compatible to what the ``struct`` module uses. + Additional characters are used for types that the ``struct`` module + does not support. + + Class methods of simple types ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ *************** *** 67,77 **** ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ``_type_`` - - Implementation artifact: the typecode for this type, a single - character string code compatible to what the struct module uses. - Additional characters are used for types that the struct module - does not support. - ``_objects`` (never modify this) --- 75,78 ---- |
From: Thomas H. <th...@us...> - 2006-02-17 21:18:21
|
Update of /cvsroot/ctypes/ctypes/docs/manual In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26915 Modified Files: Tag: branch_1_0 manual.html libraries.txt functions.txt Log Message: Shortly document the CDLL, WinDLL, OleDLL, and PyDLL types. Mention that functions can be accessed by indexing with the function name also. Rgenerate the html file. Index: functions.txt =================================================================== RCS file: /cvsroot/ctypes/ctypes/docs/manual/Attic/functions.txt,v retrieving revision 1.1.2.5 retrieving revision 1.1.2.6 diff -C2 -d -r1.1.2.5 -r1.1.2.6 *** functions.txt 17 Feb 2006 07:07:34 -0000 1.1.2.5 --- functions.txt 17 Feb 2006 21:18:16 -0000 1.1.2.6 *************** *** 9,13 **** --- 9,16 ---- libc = cdll.find("c") # posix libc = cdll.msvcrt # windows + # attribute access atoi = libc.atoi + # alternative indexing notation + atoi = libc["atoi"] This creates an instance of a foreign function object, using the Index: libraries.txt =================================================================== RCS file: /cvsroot/ctypes/ctypes/docs/manual/Attic/libraries.txt,v retrieving revision 1.1.2.4 retrieving revision 1.1.2.5 diff -C2 -d -r1.1.2.4 -r1.1.2.5 *** libraries.txt 16 Feb 2006 19:47:30 -0000 1.1.2.4 --- libraries.txt 17 Feb 2006 21:18:16 -0000 1.1.2.5 *************** *** 129,130 **** --- 129,150 ---- Python C api as the ``pythonapi`` symbol, you should however make sure to set the correct ``restype`` for the functions you use. + + Library objects + ~~~~~~~~~~~~~~~ + + The library loaders create instances of ``CDLL``, ``WinDLL``, + ``OleDLL``, or ``PyDLL`` classes. You can, however, also load a + library by constructing one of these classes by calling the + constructor with the pathname of the library and an optional ``mode`` + argument as described in the previous section. + + Library objects implement ``__getattr__`` and ``__getitem__`` methods + that allow to access foreign functions by attribute access or + indexing. The latter is useful if the name of the function is not a + valid Python identifier, or clashes with special Python method names + that start and end with two underscore characters. + + Library objects have two private attributes: ``_name`` is the pathname + of the library, ``_handle`` is the handle to the library that + ``dlopen`` has returned. + Index: manual.html =================================================================== RCS file: /cvsroot/ctypes/ctypes/docs/manual/Attic/manual.html,v retrieving revision 1.1.2.10 retrieving revision 1.1.2.11 diff -C2 -d -r1.1.2.10 -r1.1.2.11 *** manual.html 17 Feb 2006 20:42:03 -0000 1.1.2.10 --- manual.html 17 Feb 2006 21:18:16 -0000 1.1.2.11 *************** *** 300,332 **** <li><a class="reference" href="#class-libraryloader" id="id2" name="id2">class LibraryLoader</a></li> <li><a class="reference" href="#predefined-library-loaders" id="id3" name="id3">Predefined library loaders</a></li> </ul> </li> ! <li><a class="reference" href="#foreign-functions" id="id4" name="id4">Foreign functions</a><ul> ! <li><a class="reference" href="#function-prototypes" id="id5" name="id5">Function prototypes</a></li> ! <li><a class="reference" href="#parameter-flags" id="id6" name="id6">Parameter flags</a></li> ! <li><a class="reference" href="#com-methods-windows-only" id="id7" name="id7">COM methods (Windows only)</a></li> ! <li><a class="reference" href="#callback-functions" id="id8" name="id8">Callback functions</a></li> </ul> </li> ! <li><a class="reference" href="#simple-types" id="id9" name="id9">Simple types</a><ul> ! <li><a class="reference" href="#class-attributes-of-simple-types" id="id10" name="id10">Class attributes of simple types</a></li> ! <li><a class="reference" href="#class-methods-of-simple-types" id="id11" name="id11">Class methods of simple types</a></li> ! <li><a class="reference" href="#instance-attributes-of-simple-types" id="id12" name="id12">Instance attributes of simple types</a></li> ! <li><a class="reference" href="#numeric-types" id="id13" name="id13">Numeric types</a></li> ! <li><a class="reference" href="#character-types" id="id14" name="id14">Character types</a></li> ! <li><a class="reference" href="#pointer-types" id="id15" name="id15">Pointer types</a></li> ! <li><a class="reference" href="#string-types" id="id16" name="id16">String types</a></li> </ul> </li> ! <li><a class="reference" href="#structure-and-union-types" id="id17" name="id17">Structure and union types</a><ul> ! <li><a class="reference" href="#defining-field-names-and-types" id="id18" name="id18">Defining field names and types</a></li> ! <li><a class="reference" href="#packing-fields" id="id19" name="id19">Packing fields</a></li> ! <li><a class="reference" href="#bit-fields" id="id20" name="id20">Bit fields</a></li> ! <li><a class="reference" href="#recursive-data-types" id="id21" name="id21">Recursive data types</a></li> ! <li><a class="reference" href="#byte-order" id="id22" name="id22">Byte order</a></li> </ul> </li> ! <li><a class="reference" href="#builtin-functions" id="id23" name="id23">Builtin functions</a><ul> ! <li><a class="reference" href="#deprecated-functions" id="id24" name="id24">Deprecated functions</a></li> </ul> </li> --- 300,333 ---- <li><a class="reference" href="#class-libraryloader" id="id2" name="id2">class LibraryLoader</a></li> <li><a class="reference" href="#predefined-library-loaders" id="id3" name="id3">Predefined library loaders</a></li> + <li><a class="reference" href="#library-objects" id="id4" name="id4">Library objects</a></li> </ul> </li> ! <li><a class="reference" href="#foreign-functions" id="id5" name="id5">Foreign functions</a><ul> ! <li><a class="reference" href="#function-prototypes" id="id6" name="id6">Function prototypes</a></li> ! <li><a class="reference" href="#parameter-flags" id="id7" name="id7">Parameter flags</a></li> ! <li><a class="reference" href="#com-methods-windows-only" id="id8" name="id8">COM methods (Windows only)</a></li> ! <li><a class="reference" href="#callback-functions" id="id9" name="id9">Callback functions</a></li> </ul> </li> ! <li><a class="reference" href="#simple-types" id="id10" name="id10">Simple types</a><ul> ! <li><a class="reference" href="#class-attributes-of-simple-types" id="id11" name="id11">Class attributes of simple types</a></li> ! <li><a class="reference" href="#class-methods-of-simple-types" id="id12" name="id12">Class methods of simple types</a></li> ! <li><a class="reference" href="#instance-attributes-of-simple-types" id="id13" name="id13">Instance attributes of simple types</a></li> ! <li><a class="reference" href="#numeric-types" id="id14" name="id14">Numeric types</a></li> ! <li><a class="reference" href="#character-types" id="id15" name="id15">Character types</a></li> ! <li><a class="reference" href="#pointer-types" id="id16" name="id16">Pointer types</a></li> ! <li><a class="reference" href="#string-types" id="id17" name="id17">String types</a></li> </ul> </li> ! <li><a class="reference" href="#structure-and-union-types" id="id18" name="id18">Structure and union types</a><ul> ! <li><a class="reference" href="#defining-field-names-and-types" id="id19" name="id19">Defining field names and types</a></li> ! <li><a class="reference" href="#packing-fields" id="id20" name="id20">Packing fields</a></li> ! <li><a class="reference" href="#bit-fields" id="id21" name="id21">Bit fields</a></li> ! <li><a class="reference" href="#recursive-data-types" id="id22" name="id22">Recursive data types</a></li> ! <li><a class="reference" href="#byte-order" id="id23" name="id23">Byte order</a></li> </ul> </li> ! <li><a class="reference" href="#builtin-functions" id="id24" name="id24">Builtin functions</a><ul> ! <li><a class="reference" href="#deprecated-functions" id="id25" name="id25">Deprecated functions</a></li> </ul> </li> *************** *** 445,451 **** </blockquote> </div> </div> <div class="section"> ! <h1><a class="toc-backref" href="#id4" id="foreign-functions" name="foreign-functions">Foreign functions</a></h1> <p>Functions exported from loaded shared libraries (foreign functions) can be accessed in two ways. The easiest way is to retrieve them as --- 446,468 ---- </blockquote> </div> + <div class="section"> + <h2><a class="toc-backref" href="#id4" id="library-objects" name="library-objects">Library objects</a></h2> + <p>The library loaders return instances of <tt class="docutils literal"><span class="pre">CDLL</span></tt>, <tt class="docutils literal"><span class="pre">WinDLL</span></tt>, + <tt class="docutils literal"><span class="pre">OleDLL</span></tt>, or <tt class="docutils literal"><span class="pre">PyDLL</span></tt> classes. You can, however, also load a + library by constructing one of these classes by calling the + constructor with the pathname of the library and an optional <tt class="docutils literal"><span class="pre">mode</span></tt> + argument as described in the previous section.</p> + <p>These classes implement <tt class="docutils literal"><span class="pre">__getattr__</span></tt> and <tt class="docutils literal"><span class="pre">__getitem__</span></tt> methods + that allow to access foreign functions by attribute access or indexing. + The latter is useful if the name of the function is not a valid Python + identifier, or clashes with special Python method names that start and + end with two underscore characters.</p> + <p>Library objects have two private attributes: <tt class="docutils literal"><span class="pre">_name</span></tt> is the pathname + of the library, <tt class="docutils literal"><span class="pre">_handle</span></tt> is the handle to the library that + <tt class="docutils literal"><span class="pre">dlopen</span></tt> has returned.</p> + </div> </div> <div class="section"> ! <h1><a class="toc-backref" href="#id5" id="foreign-functions" name="foreign-functions">Foreign functions</a></h1> <p>Functions exported from loaded shared libraries (foreign functions) can be accessed in two ways. The easiest way is to retrieve them as *************** *** 482,486 **** detects a failure, or return the needed return value otherwise.</p> <div class="section"> ! <h2><a class="toc-backref" href="#id5" id="function-prototypes" name="function-prototypes">Function prototypes</a></h2> <p>Another way to access a function exported from shared libraries is to first create a prototype by calling a factory function, specifying the --- 499,503 ---- detects a failure, or return the needed return value otherwise.</p> <div class="section"> ! <h2><a class="toc-backref" href="#id6" id="function-prototypes" name="function-prototypes">Function prototypes</a></h2> <p>Another way to access a function exported from shared libraries is to first create a prototype by calling a factory function, specifying the *************** *** 506,510 **** </div> <div class="section"> ! <h2><a class="toc-backref" href="#id6" id="parameter-flags" name="parameter-flags">Parameter flags</a></h2> <p>It is possible to specify a third argument <tt class="docutils literal"><span class="pre">paramflags</span></tt> when calling the prototype. This is used to specify additional information for --- 523,527 ---- </div> <div class="section"> ! <h2><a class="toc-backref" href="#id7" id="parameter-flags" name="parameter-flags">Parameter flags</a></h2> <p>It is possible to specify a third argument <tt class="docutils literal"><span class="pre">paramflags</span></tt> when calling the prototype. This is used to specify additional information for *************** *** 543,547 **** </div> <div class="section"> ! <h2><a class="toc-backref" href="#id7" id="com-methods-windows-only" name="com-methods-windows-only">COM methods (Windows only)</a></h2> <p>XXX Should this be left undocumented? Mentioned for completeness.</p> <p>The prototypes created by <tt class="docutils literal"><span class="pre">WINFUNCTYPE</span></tt> can be called with a --- 560,564 ---- </div> <div class="section"> ! <h2><a class="toc-backref" href="#id8" id="com-methods-windows-only" name="com-methods-windows-only">COM methods (Windows only)</a></h2> <p>XXX Should this be left undocumented? Mentioned for completeness.</p> <p>The prototypes created by <tt class="docutils literal"><span class="pre">WINFUNCTYPE</span></tt> can be called with a *************** *** 560,564 **** </div> <div class="section"> ! <h2><a class="toc-backref" href="#id8" id="callback-functions" name="callback-functions">Callback functions</a></h2> <p>ctypes is able to create C callable functions from Python callables. This is useful because sometimes library functions need a callback --- 577,581 ---- </div> <div class="section"> ! <h2><a class="toc-backref" href="#id9" id="callback-functions" name="callback-functions">Callback functions</a></h2> <p>ctypes is able to create C callable functions from Python callables. This is useful because sometimes library functions need a callback *************** *** 588,592 **** </div> <div class="section"> ! <h1><a class="toc-backref" href="#id9" id="simple-types" name="simple-types">Simple types</a></h1> <p>Simple types have some special behaviour: When they are accessed as structure or union fields, items of array instances, or as foreign --- 605,609 ---- </div> <div class="section"> ! <h1><a class="toc-backref" href="#id10" id="simple-types" name="simple-types">Simple types</a></h1> <p>Simple types have some special behaviour: When they are accessed as structure or union fields, items of array instances, or as foreign *************** *** 598,602 **** allows you to define new behaviour almost completely.</p> <div class="section"> ! <h2><a class="toc-backref" href="#id10" id="class-attributes-of-simple-types" name="class-attributes-of-simple-types">Class attributes of simple types</a></h2> <p><tt class="docutils literal"><span class="pre">__ctype__be__</span></tt>, <tt class="docutils literal"><span class="pre">__ctype_le__</span></tt></p> <blockquote> --- 615,619 ---- allows you to define new behaviour almost completely.</p> <div class="section"> ! <h2><a class="toc-backref" href="#id11" id="class-attributes-of-simple-types" name="class-attributes-of-simple-types">Class attributes of simple types</a></h2> <p><tt class="docutils literal"><span class="pre">__ctype__be__</span></tt>, <tt class="docutils literal"><span class="pre">__ctype_le__</span></tt></p> <blockquote> *************** *** 608,612 **** </div> <div class="section"> ! <h2><a class="toc-backref" href="#id11" id="class-methods-of-simple-types" name="class-methods-of-simple-types">Class methods of simple types</a></h2> <p>(To be exact, these are not class methods, instead these are methods of the metaclass. The most prominent difference to classmethods is --- 625,629 ---- </div> <div class="section"> ! <h2><a class="toc-backref" href="#id12" id="class-methods-of-simple-types" name="class-methods-of-simple-types">Class methods of simple types</a></h2> <p>(To be exact, these are not class methods, instead these are methods of the metaclass. The most prominent difference to classmethods is *************** *** 642,646 **** </div> <div class="section"> ! <h2><a class="toc-backref" href="#id12" id="instance-attributes-of-simple-types" name="instance-attributes-of-simple-types">Instance attributes of simple types</a></h2> <p><tt class="docutils literal"><span class="pre">_type_</span></tt></p> <blockquote> --- 659,663 ---- </div> <div class="section"> ! <h2><a class="toc-backref" href="#id13" id="instance-attributes-of-simple-types" name="instance-attributes-of-simple-types">Instance attributes of simple types</a></h2> <p><tt class="docutils literal"><span class="pre">_type_</span></tt></p> <blockquote> *************** *** 673,677 **** </div> <div class="section"> ! <h2><a class="toc-backref" href="#id13" id="numeric-types" name="numeric-types">Numeric types</a></h2> <p>Integer types are <tt class="docutils literal"><span class="pre">c_byte</span></tt>, <tt class="docutils literal"><span class="pre">c_short</span></tt>, <tt class="docutils literal"><span class="pre">c_int</span></tt>, <tt class="docutils literal"><span class="pre">c_long</span></tt>, <tt class="docutils literal"><span class="pre">c_longlong</span></tt> and their unsigned variants <tt class="docutils literal"><span class="pre">c_ubyte</span></tt>, <tt class="docutils literal"><span class="pre">c_ushort</span></tt>, --- 690,694 ---- </div> <div class="section"> ! <h2><a class="toc-backref" href="#id14" id="numeric-types" name="numeric-types">Numeric types</a></h2> <p>Integer types are <tt class="docutils literal"><span class="pre">c_byte</span></tt>, <tt class="docutils literal"><span class="pre">c_short</span></tt>, <tt class="docutils literal"><span class="pre">c_int</span></tt>, <tt class="docutils literal"><span class="pre">c_long</span></tt>, <tt class="docutils literal"><span class="pre">c_longlong</span></tt> and their unsigned variants <tt class="docutils literal"><span class="pre">c_ubyte</span></tt>, <tt class="docutils literal"><span class="pre">c_ushort</span></tt>, *************** *** 685,689 **** </div> <div class="section"> ! <h2><a class="toc-backref" href="#id14" id="character-types" name="character-types">Character types</a></h2> <p>Character types are <tt class="docutils literal"><span class="pre">c_char</span></tt> and <tt class="docutils literal"><span class="pre">c_wchar</span></tt>, representing the C <tt class="docutils literal"><span class="pre">char</span></tt> and <tt class="docutils literal"><span class="pre">wchar_t</span></tt> types.</p> --- 702,706 ---- </div> <div class="section"> ! <h2><a class="toc-backref" href="#id15" id="character-types" name="character-types">Character types</a></h2> <p>Character types are <tt class="docutils literal"><span class="pre">c_char</span></tt> and <tt class="docutils literal"><span class="pre">c_wchar</span></tt>, representing the C <tt class="docutils literal"><span class="pre">char</span></tt> and <tt class="docutils literal"><span class="pre">wchar_t</span></tt> types.</p> *************** *** 694,698 **** </div> <div class="section"> ! <h2><a class="toc-backref" href="#id15" id="pointer-types" name="pointer-types">Pointer types</a></h2> <p>The only simple pointer type is <tt class="docutils literal"><span class="pre">c_void_p</span></tt>, which represents the C <tt class="docutils literal"><span class="pre">void</span> <span class="pre">*</span></tt> data type. <tt class="docutils literal"><span class="pre">c_void_p</span></tt> can also be written as --- 711,715 ---- </div> <div class="section"> ! <h2><a class="toc-backref" href="#id16" id="pointer-types" name="pointer-types">Pointer types</a></h2> <p>The only simple pointer type is <tt class="docutils literal"><span class="pre">c_void_p</span></tt>, which represents the C <tt class="docutils literal"><span class="pre">void</span> <span class="pre">*</span></tt> data type. <tt class="docutils literal"><span class="pre">c_void_p</span></tt> can also be written as *************** *** 707,711 **** </div> <div class="section"> ! <h2><a class="toc-backref" href="#id16" id="string-types" name="string-types">String types</a></h2> <p>ctypes has the <tt class="docutils literal"><span class="pre">c_char_p</span></tt> and <tt class="docutils literal"><span class="pre">c_wchar_p</span></tt> types which represent const pointers to zero terminated strings in C: <tt class="docutils literal"><span class="pre">const</span> <span class="pre">char</span> <span class="pre">*</span></tt> and --- 724,728 ---- </div> <div class="section"> ! <h2><a class="toc-backref" href="#id17" id="string-types" name="string-types">String types</a></h2> <p>ctypes has the <tt class="docutils literal"><span class="pre">c_char_p</span></tt> and <tt class="docutils literal"><span class="pre">c_wchar_p</span></tt> types which represent const pointers to zero terminated strings in C: <tt class="docutils literal"><span class="pre">const</span> <span class="pre">char</span> <span class="pre">*</span></tt> and *************** *** 722,731 **** </div> <div class="section"> ! <h1><a class="toc-backref" href="#id17" id="structure-and-union-types" name="structure-and-union-types">Structure and union types</a></h1> <p>ctypes provides the abstract base classes <tt class="docutils literal"><span class="pre">Structure</span></tt> and <tt class="docutils literal"><span class="pre">Union</span></tt> to define structure and union types. Subclasses must at least define a <tt class="docutils literal"><span class="pre">_fields_</span></tt> attribute.</p> <div class="section"> ! <h2><a class="toc-backref" href="#id18" id="defining-field-names-and-types" name="defining-field-names-and-types">Defining field names and types</a></h2> <p><tt class="docutils literal"><span class="pre">_fields_</span></tt> must be a sequence of tuples. The first item of each tuple is a string specifying the name of the structure/union field. --- 739,748 ---- </div> <div class="section"> ! <h1><a class="toc-backref" href="#id18" id="structure-and-union-types" name="structure-and-union-types">Structure and union types</a></h1> <p>ctypes provides the abstract base classes <tt class="docutils literal"><span class="pre">Structure</span></tt> and <tt class="docutils literal"><span class="pre">Union</span></tt> to define structure and union types. Subclasses must at least define a <tt class="docutils literal"><span class="pre">_fields_</span></tt> attribute.</p> <div class="section"> ! <h2><a class="toc-backref" href="#id19" id="defining-field-names-and-types" name="defining-field-names-and-types">Defining field names and types</a></h2> <p><tt class="docutils literal"><span class="pre">_fields_</span></tt> must be a sequence of tuples. The first item of each tuple is a string specifying the name of the structure/union field. *************** *** 745,749 **** </div> <div class="section"> ! <h2><a class="toc-backref" href="#id19" id="packing-fields" name="packing-fields">Packing fields</a></h2> <p>Normally fields are aligned in the same way as the host's C compiler. The native alignment can be overridden by setting a <tt class="docutils literal"><span class="pre">_pack_</span></tt> --- 762,766 ---- </div> <div class="section"> ! <h2><a class="toc-backref" href="#id20" id="packing-fields" name="packing-fields">Packing fields</a></h2> <p>Normally fields are aligned in the same way as the host's C compiler. The native alignment can be overridden by setting a <tt class="docutils literal"><span class="pre">_pack_</span></tt> *************** *** 752,756 **** </div> <div class="section"> ! <h2><a class="toc-backref" href="#id20" id="bit-fields" name="bit-fields">Bit fields</a></h2> <p>Integer fields support bit sizes. The bit-size must be specified as the third item of the <tt class="docutils literal"><span class="pre">_fields_</span></tt> tuple. Bit fields are constructed --- 769,773 ---- </div> <div class="section"> ! <h2><a class="toc-backref" href="#id21" id="bit-fields" name="bit-fields">Bit fields</a></h2> <p>Integer fields support bit sizes. The bit-size must be specified as the third item of the <tt class="docutils literal"><span class="pre">_fields_</span></tt> tuple. Bit fields are constructed *************** *** 761,765 **** </div> <div class="section"> ! <h2><a class="toc-backref" href="#id21" id="recursive-data-types" name="recursive-data-types">Recursive data types</a></h2> <p>To support recursive type definitions, it is possible to assign the <tt class="docutils literal"><span class="pre">_fields_</span></tt> value after the class statement. Here is an example of a --- 778,782 ---- </div> <div class="section"> ! <h2><a class="toc-backref" href="#id22" id="recursive-data-types" name="recursive-data-types">Recursive data types</a></h2> <p>To support recursive type definitions, it is possible to assign the <tt class="docutils literal"><span class="pre">_fields_</span></tt> value after the class statement. Here is an example of a *************** *** 775,779 **** </div> <div class="section"> ! <h2><a class="toc-backref" href="#id22" id="byte-order" name="byte-order">Byte order</a></h2> <p>It is possible to create Structure and Union types using non-native byte order by using the <tt class="docutils literal"><span class="pre">BigEndianStructure</span></tt>, --- 792,796 ---- </div> <div class="section"> ! <h2><a class="toc-backref" href="#id23" id="byte-order" name="byte-order">Byte order</a></h2> <p>It is possible to create Structure and Union types using non-native byte order by using the <tt class="docutils literal"><span class="pre">BigEndianStructure</span></tt>, *************** *** 784,788 **** </div> <div class="section"> ! <h1><a class="toc-backref" href="#id23" id="builtin-functions" name="builtin-functions">Builtin functions</a></h1> <p>XXX Change to alphabetical order!</p> <p><tt class="docutils literal"><span class="pre">CFUNCTYPE(restype,</span> <span class="pre">*argtypes)</span></tt></p> --- 801,805 ---- </div> <div class="section"> ! <h1><a class="toc-backref" href="#id24" id="builtin-functions" name="builtin-functions">Builtin functions</a></h1> <p>XXX Change to alphabetical order!</p> <p><tt class="docutils literal"><span class="pre">CFUNCTYPE(restype,</span> <span class="pre">*argtypes)</span></tt></p> *************** *** 881,885 **** Returns the last error code set by Windows.</blockquote> <div class="section"> ! <h2><a class="toc-backref" href="#id24" id="deprecated-functions" name="deprecated-functions">Deprecated functions</a></h2> <p><tt class="docutils literal"><span class="pre">c_buffer(init,</span> <span class="pre">size=None)</span></tt></p> <blockquote> --- 898,902 ---- Returns the last error code set by Windows.</blockquote> <div class="section"> ! <h2><a class="toc-backref" href="#id25" id="deprecated-functions" name="deprecated-functions">Deprecated functions</a></h2> <p><tt class="docutils literal"><span class="pre">c_buffer(init,</span> <span class="pre">size=None)</span></tt></p> <blockquote> |
From: Thomas H. <th...@us...> - 2006-02-17 20:42:08
|
Update of /cvsroot/ctypes/ctypes/docs/manual In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9298 Modified Files: Tag: branch_1_0 manual.html Log Message: Regenerated. Index: manual.html =================================================================== RCS file: /cvsroot/ctypes/ctypes/docs/manual/Attic/manual.html,v retrieving revision 1.1.2.9 retrieving revision 1.1.2.10 diff -C2 -d -r1.1.2.9 -r1.1.2.10 *** manual.html 16 Feb 2006 20:00:47 -0000 1.1.2.9 --- manual.html 17 Feb 2006 20:42:03 -0000 1.1.2.10 *************** *** 463,467 **** <p>If the library function returns a type different from <tt class="docutils literal"><span class="pre">int</span></tt>, the <tt class="docutils literal"><span class="pre">restype</span></tt> attribute can be set to a ctypes type that describes the ! return type, or to <tt class="docutils literal"><span class="pre">`None</span></tt> meaning no return value (<tt class="docutils literal"><span class="pre">void</span></tt>).</p> <p>The optional <tt class="docutils literal"><span class="pre">argtypes</span></tt> attribute can be set to a sequence of ctypes types that the function expects.</p> --- 463,467 ---- <p>If the library function returns a type different from <tt class="docutils literal"><span class="pre">int</span></tt>, the <tt class="docutils literal"><span class="pre">restype</span></tt> attribute can be set to a ctypes type that describes the ! return type, or to <tt class="docutils literal"><span class="pre">None</span></tt> meaning no return value (<tt class="docutils literal"><span class="pre">void</span></tt>).</p> <p>The optional <tt class="docutils literal"><span class="pre">argtypes</span></tt> attribute can be set to a sequence of ctypes types that the function expects.</p> *************** *** 469,473 **** than the length of the argtypes sequence.</p> <p>The optional <tt class="docutils literal"><span class="pre">errcheck</span></tt> attribute can be set to a Python callable, ! it can be used to validate and/or process the library functions return value. <tt class="docutils literal"><span class="pre">errcheck</span></tt> will be called with three arguments, after the library function has returned:</p> --- 469,473 ---- than the length of the argtypes sequence.</p> <p>The optional <tt class="docutils literal"><span class="pre">errcheck</span></tt> attribute can be set to a Python callable, ! which can be used to validate and/or process the library function's return value. <tt class="docutils literal"><span class="pre">errcheck</span></tt> will be called with three arguments, after the library function has returned:</p> *************** *** 529,533 **** below for how it can be retrieved).</p> <p>If <tt class="docutils literal"><span class="pre">paramflags</span></tt> have been used in the prototype call, and an ! <tt class="docutils literal"><span class="pre">errcheck</span></tt> attribuet is also present, the <tt class="docutils literal"><span class="pre">errcheck</span></tt> callable will be called with a fourth parameter <tt class="docutils literal"><span class="pre">outargs</span></tt>:</p> <pre class="literal-block"> --- 529,533 ---- below for how it can be retrieved).</p> <p>If <tt class="docutils literal"><span class="pre">paramflags</span></tt> have been used in the prototype call, and an ! <tt class="docutils literal"><span class="pre">errcheck</span></tt> attribute is also present, the <tt class="docutils literal"><span class="pre">errcheck</span></tt> callable will be called with a fourth parameter <tt class="docutils literal"><span class="pre">outargs</span></tt>:</p> <pre class="literal-block"> *************** *** 552,558 **** the name of the COM method (only useful for debugging), <tt class="docutils literal"><span class="pre">paramflags</span></tt> has the same meaning as for normal function objects, and <tt class="docutils literal"><span class="pre">iid</span></tt> is a ! string or buffer containing the interface iid of the COM interface this method belongs to. <tt class="docutils literal"><span class="pre">iid</span></tt> is used to get extended COM error ! information in case the method returns a FAILED HRESULT value.</p> <p>Note that COM methods expect an additional first argument that is NOT listed in the prototypes <tt class="docutils literal"><span class="pre">argtypes</span></tt> when they are called: this must --- 552,558 ---- the name of the COM method (only useful for debugging), <tt class="docutils literal"><span class="pre">paramflags</span></tt> has the same meaning as for normal function objects, and <tt class="docutils literal"><span class="pre">iid</span></tt> is a ! string or buffer containing the interface id of the COM interface this method belongs to. <tt class="docutils literal"><span class="pre">iid</span></tt> is used to get extended COM error ! information in case the method returns a FAILED ''HRESULT`` value.</p> <p>Note that COM methods expect an additional first argument that is NOT listed in the prototypes <tt class="docutils literal"><span class="pre">argtypes</span></tt> when they are called: this must *************** *** 563,572 **** <p>ctypes is able to create C callable functions from Python callables. This is useful because sometimes library functions need a callback ! function parameter, the <tt class="docutils literal"><span class="pre">qsort</span></tt> C function is such an example.</p> <p>Callback functions are created by first creating a function prototype with a call to <tt class="docutils literal"><span class="pre">CFUNCTYPE</span></tt> or <tt class="docutils literal"><span class="pre">WINFUNCTYPE</span></tt>, specifying the return type and the argument types that the callback function will receive.</p> <p>Calling the prototype with a single Python callable will create and ! return a C callable function pointer or callback function. Note that this allows using prototypes as decorators creating callback functions (Windows example):</p> --- 563,572 ---- <p>ctypes is able to create C callable functions from Python callables. This is useful because sometimes library functions need a callback ! function parameter; the <tt class="docutils literal"><span class="pre">qsort</span></tt> C function is such an example.</p> <p>Callback functions are created by first creating a function prototype with a call to <tt class="docutils literal"><span class="pre">CFUNCTYPE</span></tt> or <tt class="docutils literal"><span class="pre">WINFUNCTYPE</span></tt>, specifying the return type and the argument types that the callback function will receive.</p> <p>Calling the prototype with a single Python callable will create and ! return a C-callable function pointer or callback function. Note that this allows using prototypes as decorators creating callback functions (Windows example):</p> *************** *** 581,586 **** <p>Important note: You must keep a reference to the callback AS LONG as foreign code will call it! Segfaults will result if the callback is ! cleaned up by Python's garbage collector and external code will still ! try to call it.</p> <p>Callback objects can also be called from Python - this may be useful for debugging.</p> --- 581,586 ---- <p>Important note: You must keep a reference to the callback AS LONG as foreign code will call it! Segfaults will result if the callback is ! cleaned up by Python's garbage collector and external code then ! tries to call it.</p> <p>Callback objects can also be called from Python - this may be useful for debugging.</p> *************** *** 593,600 **** function return values, they are transparently converted from and to the native Python types int, long, string, and unicode.</p> ! <p>This is <em>not</em> the case for subclasses of simply data types, so while a <tt class="docutils literal"><span class="pre">c_void_p</span></tt> type is transparently converted from and to Python integer or long, a subclass of c_void_p is <em>not</em> converted. This ! allows to almost completely define new behaviour.</p> <div class="section"> <h2><a class="toc-backref" href="#id10" id="class-attributes-of-simple-types" name="class-attributes-of-simple-types">Class attributes of simple types</a></h2> --- 593,600 ---- function return values, they are transparently converted from and to the native Python types int, long, string, and unicode.</p> ! <p>This is <em>not</em> the case for subclasses of simple data types, so while a <tt class="docutils literal"><span class="pre">c_void_p</span></tt> type is transparently converted from and to Python integer or long, a subclass of c_void_p is <em>not</em> converted. This ! allows you to define new behaviour almost completely.</p> <div class="section"> <h2><a class="toc-backref" href="#id10" id="class-attributes-of-simple-types" name="class-attributes-of-simple-types">Class attributes of simple types</a></h2> *************** *** 622,635 **** <blockquote> <p>This is a class method (an instance method of the metaclass, to be ! exact) that will be used to adapt function parameters. If a ! <tt class="docutils literal"><span class="pre">c_int</span></tt> type is specified in a functions argtypes sequence, <tt class="docutils literal"><span class="pre">c_int.from_param(arg)</span></tt> will be called by ctypes and the result ! will be passed to the foreign function call as parameter.</p> <p><tt class="docutils literal"><span class="pre">from_param</span></tt> usually returns an internal object that you cannot ! use on Python code - it makes only sense to pass this to foreign functions.</p> <p>On one hand, <tt class="docutils literal"><span class="pre">from_param</span></tt> is a performance optimization - it ! allows to pass Python integers to function calls expecting a ! <tt class="docutils literal"><span class="pre">c_int</span></tt> argument type, without having to create a full-features <tt class="docutils literal"><span class="pre">c_int</span></tt> instance.</p> <p>On the other hand, <tt class="docutils literal"><span class="pre">from_param</span></tt> can adapt other objects to --- 622,635 ---- <blockquote> <p>This is a class method (an instance method of the metaclass, to be ! exact) that is used to adapt function parameters. If a ! <tt class="docutils literal"><span class="pre">c_int</span></tt> type is specified in a function's argtypes sequence, <tt class="docutils literal"><span class="pre">c_int.from_param(arg)</span></tt> will be called by ctypes and the result ! will be passed to the foreign function call as a parameter.</p> <p><tt class="docutils literal"><span class="pre">from_param</span></tt> usually returns an internal object that you cannot ! use in Python code - it only makes sense to pass this to foreign functions.</p> <p>On one hand, <tt class="docutils literal"><span class="pre">from_param</span></tt> is a performance optimization - it ! allows you to pass Python integers to function calls expecting a ! <tt class="docutils literal"><span class="pre">c_int</span></tt> argument type, without having to create a full-featured <tt class="docutils literal"><span class="pre">c_int</span></tt> instance.</p> <p>On the other hand, <tt class="docutils literal"><span class="pre">from_param</span></tt> can adapt other objects to *************** *** 660,664 **** <p><tt class="docutils literal"><span class="pre">_b_needsfree_</span></tt> (readonly)</p> <blockquote> ! Implementation artifact: does this object have to free it's memory block on destruction.</blockquote> <p><tt class="docutils literal"><span class="pre">value</span></tt></p> --- 660,664 ---- <p><tt class="docutils literal"><span class="pre">_b_needsfree_</span></tt> (readonly)</p> <blockquote> ! Implementation artifact: does this object have to free its memory block on destruction.</blockquote> <p><tt class="docutils literal"><span class="pre">value</span></tt></p> *************** *** 669,673 **** <p><tt class="docutils literal"><span class="pre">_as_parameter_</span></tt> (readonly)</p> <blockquote> ! Implementation artifact (?): how to pass this object as function parameter.</blockquote> </div> --- 669,673 ---- <p><tt class="docutils literal"><span class="pre">_as_parameter_</span></tt> (readonly)</p> <blockquote> ! Implementation artifact (?): how to pass this object as a function parameter.</blockquote> </div> *************** *** 676,680 **** <p>Integer types are <tt class="docutils literal"><span class="pre">c_byte</span></tt>, <tt class="docutils literal"><span class="pre">c_short</span></tt>, <tt class="docutils literal"><span class="pre">c_int</span></tt>, <tt class="docutils literal"><span class="pre">c_long</span></tt>, <tt class="docutils literal"><span class="pre">c_longlong</span></tt> and their unsigned variants <tt class="docutils literal"><span class="pre">c_ubyte</span></tt>, <tt class="docutils literal"><span class="pre">c_ushort</span></tt>, ! <tt class="docutils literal"><span class="pre">c_uint</span></tt>, <tt class="docutils literal"><span class="pre">c_ulong</span></tt> and <tt class="docutils literal"><span class="pre">c_longlong</span></tt>, floating point types are <tt class="docutils literal"><span class="pre">c_float</span></tt> and <tt class="docutils literal"><span class="pre">c_double</span></tt>.</p> <p>The constructor and the <tt class="docutils literal"><span class="pre">from_param</span></tt> class method accept a Python --- 676,680 ---- <p>Integer types are <tt class="docutils literal"><span class="pre">c_byte</span></tt>, <tt class="docutils literal"><span class="pre">c_short</span></tt>, <tt class="docutils literal"><span class="pre">c_int</span></tt>, <tt class="docutils literal"><span class="pre">c_long</span></tt>, <tt class="docutils literal"><span class="pre">c_longlong</span></tt> and their unsigned variants <tt class="docutils literal"><span class="pre">c_ubyte</span></tt>, <tt class="docutils literal"><span class="pre">c_ushort</span></tt>, ! <tt class="docutils literal"><span class="pre">c_uint</span></tt>, <tt class="docutils literal"><span class="pre">c_ulong</span></tt> and <tt class="docutils literal"><span class="pre">c_ulonglong</span></tt>, floating point types are <tt class="docutils literal"><span class="pre">c_float</span></tt> and <tt class="docutils literal"><span class="pre">c_double</span></tt>.</p> <p>The constructor and the <tt class="docutils literal"><span class="pre">from_param</span></tt> class method accept a Python *************** *** 696,708 **** <h2><a class="toc-backref" href="#id15" id="pointer-types" name="pointer-types">Pointer types</a></h2> <p>The only simple pointer type is <tt class="docutils literal"><span class="pre">c_void_p</span></tt>, which represents the C ! <tt class="docutils literal"><span class="pre">void</span> <span class="pre">*</span></tt> datra type. <tt class="docutils literal"><span class="pre">c_void_p</span></tt> can also be written as <tt class="docutils literal"><span class="pre">POINTER(None)</span></tt>.</p> <p>The constructor accepts one optional argument, which must be an ! integer or long interpreted as address, or <tt class="docutils literal"><span class="pre">None</span></tt>.</p> <p>The <tt class="docutils literal"><span class="pre">from_param</span></tt> class method accepts everything that could be used as a pointer. XXX Should accept objects using the buffer interface as well.</p> <p>The <tt class="docutils literal"><span class="pre">value</span></tt> attribute accepts and returns None or integer.</p> ! <p>XXX Shouldn't the constructor accept the same types than from_param?</p> </div> <div class="section"> --- 696,708 ---- <h2><a class="toc-backref" href="#id15" id="pointer-types" name="pointer-types">Pointer types</a></h2> <p>The only simple pointer type is <tt class="docutils literal"><span class="pre">c_void_p</span></tt>, which represents the C ! <tt class="docutils literal"><span class="pre">void</span> <span class="pre">*</span></tt> data type. <tt class="docutils literal"><span class="pre">c_void_p</span></tt> can also be written as <tt class="docutils literal"><span class="pre">POINTER(None)</span></tt>.</p> <p>The constructor accepts one optional argument, which must be an ! integer or long (interpreted as an address), or <tt class="docutils literal"><span class="pre">None</span></tt>.</p> <p>The <tt class="docutils literal"><span class="pre">from_param</span></tt> class method accepts everything that could be used as a pointer. XXX Should accept objects using the buffer interface as well.</p> <p>The <tt class="docutils literal"><span class="pre">value</span></tt> attribute accepts and returns None or integer.</p> ! <p>XXX Shouldn't the constructor accept the same types as from_param?</p> </div> <div class="section"> *************** *** 710,721 **** <p>ctypes has the <tt class="docutils literal"><span class="pre">c_char_p</span></tt> and <tt class="docutils literal"><span class="pre">c_wchar_p</span></tt> types which represent const pointers to zero terminated strings in C: <tt class="docutils literal"><span class="pre">const</span> <span class="pre">char</span> <span class="pre">*</span></tt> and ! <tt class="docutils literal"><span class="pre">const</span> <span class="pre">wchar_t</span> <span class="pre">*</span></tt>. Since Python strings and unicode instances are immutable, these types should be considered readonly: do not pass them to functions that write into the buffer.</p> <p>The constructor accepts one optional argument, which must be a Python ! string or unicode string, an integer, or <tt class="docutils literal"><span class="pre">None</span></tt>.</p> ! <p>The <tt class="docutils literal"><span class="pre">from_param</span></tt> class method accepts Python strings or unicode ! strings, as well as <tt class="docutils literal"><span class="pre">None</span></tt>. Conversion between string and unicode, ! if needed, is done according to the ctypes encoding/decoding rules.</p> <p>XXX Why does the constructor accept an integer, and from_param doesn't?</p> </div> --- 710,721 ---- <p>ctypes has the <tt class="docutils literal"><span class="pre">c_char_p</span></tt> and <tt class="docutils literal"><span class="pre">c_wchar_p</span></tt> types which represent const pointers to zero terminated strings in C: <tt class="docutils literal"><span class="pre">const</span> <span class="pre">char</span> <span class="pre">*</span></tt> and ! <tt class="docutils literal"><span class="pre">const</span> <span class="pre">wchar_t</span> <span class="pre">*</span></tt>. Since strings and Unicode instances are immutable, these types should be considered readonly: do not pass them to functions that write into the buffer.</p> <p>The constructor accepts one optional argument, which must be a Python ! or unicode string, an integer, or <tt class="docutils literal"><span class="pre">None</span></tt>.</p> ! <p>The <tt class="docutils literal"><span class="pre">from_param</span></tt> class method accepts a string or a Unicode string, ! as well as <tt class="docutils literal"><span class="pre">None</span></tt>. Conversion between string and Unicode, if ! needed, is done according to the ctypes encoding/decoding rules.</p> <p>XXX Why does the constructor accept an integer, and from_param doesn't?</p> </div> *************** *** 731,736 **** tuple is a string specifying the name of the structure/union field. The second item must by a ctypes type.</p> ! <p>A descriptor will be created for each field, it allows to access the ! fields contents from instances. Accessed from the class, the fields expose readonly <tt class="docutils literal"><span class="pre">.offset</span></tt> and <tt class="docutils literal"><span class="pre">.size</span></tt> attributes. <tt class="docutils literal"><span class="pre">offset</span></tt> is the byte-offset of the field from the beginning of the --- 731,736 ---- tuple is a string specifying the name of the structure/union field. The second item must by a ctypes type.</p> ! <p>A descriptor will be created for each field, allowing you to access the ! field's contents from instances. Accessed from the class, the fields expose readonly <tt class="docutils literal"><span class="pre">.offset</span></tt> and <tt class="docutils literal"><span class="pre">.size</span></tt> attributes. <tt class="docutils literal"><span class="pre">offset</span></tt> is the byte-offset of the field from the beginning of the *************** *** 746,750 **** <div class="section"> <h2><a class="toc-backref" href="#id19" id="packing-fields" name="packing-fields">Packing fields</a></h2> ! <p>Normally fields are aligned in the same way as the hosts C compiler. The native alignment can be overridden by setting a <tt class="docutils literal"><span class="pre">_pack_</span></tt> attribute in the type. This must be a small positive integer which is --- 746,750 ---- <div class="section"> <h2><a class="toc-backref" href="#id19" id="packing-fields" name="packing-fields">Packing fields</a></h2> ! <p>Normally fields are aligned in the same way as the host's C compiler. The native alignment can be overridden by setting a <tt class="docutils literal"><span class="pre">_pack_</span></tt> attribute in the type. This must be a small positive integer which is *************** *** 755,761 **** <p>Integer fields support bit sizes. The bit-size must be specified as the third item of the <tt class="docutils literal"><span class="pre">_fields_</span></tt> tuple. Bit fields are constructed ! in the same way the hosts C compiler does it. For bit fields, the ! field descriptors <tt class="docutils literal"><span class="pre">.size</span></tt> attribute contains the number of bits in ! the high word, the bit offset from the beginning of the structure in the low word. XXX is that correct?</p> </div> --- 755,761 ---- <p>Integer fields support bit sizes. The bit-size must be specified as the third item of the <tt class="docutils literal"><span class="pre">_fields_</span></tt> tuple. Bit fields are constructed ! in the same way the host's C compiler does it. For bit fields, the ! field descriptor's <tt class="docutils literal"><span class="pre">.size</span></tt> attribute contains the number of bits in ! the high word, and the bit offset from the beginning of the structure in the low word. XXX is that correct?</p> </div> *************** *** 777,781 **** <h2><a class="toc-backref" href="#id22" id="byte-order" name="byte-order">Byte order</a></h2> <p>It is possible to create Structure and Union types using non-native ! byte order by using the <tt class="docutils literal"><span class="pre">BugEndianStructure</span></tt>, <tt class="docutils literal"><span class="pre">LittleEndianStructure</span></tt>, <tt class="docutils literal"><span class="pre">BigEndianUnion</span></tt>, and <tt class="docutils literal"><span class="pre">LittleEndianUnion</span></tt> base classes. Structures and Unions with --- 777,781 ---- <h2><a class="toc-backref" href="#id22" id="byte-order" name="byte-order">Byte order</a></h2> <p>It is possible to create Structure and Union types using non-native ! byte order by using the <tt class="docutils literal"><span class="pre">BigEndianStructure</span></tt>, <tt class="docutils literal"><span class="pre">LittleEndianStructure</span></tt>, <tt class="docutils literal"><span class="pre">BigEndianUnion</span></tt>, and <tt class="docutils literal"><span class="pre">LittleEndianUnion</span></tt> base classes. Structures and Unions with *************** *** 785,788 **** --- 785,789 ---- <div class="section"> <h1><a class="toc-backref" href="#id23" id="builtin-functions" name="builtin-functions">Builtin functions</a></h1> + <p>XXX Change to alphabetical order!</p> <p><tt class="docutils literal"><span class="pre">CFUNCTYPE(restype,</span> <span class="pre">*argtypes)</span></tt></p> <blockquote> *************** *** 794,798 **** <p><tt class="docutils literal"><span class="pre">addressof(object)</span></tt></p> <blockquote> ! Returns the address of a ctypes instance as integer.</blockquote> <p><tt class="docutils literal"><span class="pre">alignment(type_or_object)</span></tt></p> <blockquote> --- 795,799 ---- <p><tt class="docutils literal"><span class="pre">addressof(object)</span></tt></p> <blockquote> ! Returns the address of a ctypes instance as an integer.</blockquote> <p><tt class="docutils literal"><span class="pre">alignment(type_or_object)</span></tt></p> <blockquote> *************** *** 801,805 **** <p><tt class="docutils literal"><span class="pre">sizeof(type_or_object)</span></tt></p> <blockquote> ! Returns the size in bytes for a ctypes type or instance. Same as the C sizeof() function.</blockquote> <p><tt class="docutils literal"><span class="pre">byref(object)</span></tt></p> --- 802,806 ---- <p><tt class="docutils literal"><span class="pre">sizeof(type_or_object)</span></tt></p> <blockquote> ! Returns the size in bytes of a ctypes type or instance. Same as the C sizeof() function.</blockquote> <p><tt class="docutils literal"><span class="pre">byref(object)</span></tt></p> *************** *** 819,823 **** <blockquote> <p>This factory function creates and returns a new ctypes type. ! Pointer types are cashed, so calling this function is cheap.</p> <p>To create a <tt class="docutils literal"><span class="pre">NULL</span></tt> pointer instance, use this recipe:</p> <pre class="literal-block"> --- 820,824 ---- <blockquote> <p>This factory function creates and returns a new ctypes type. ! Pointer types are cached, so calling this function is cheap.</p> <p>To create a <tt class="docutils literal"><span class="pre">NULL</span></tt> pointer instance, use this recipe:</p> <pre class="literal-block"> *************** *** 834,842 **** <p><tt class="docutils literal"><span class="pre">string_at(addr[,</span> <span class="pre">size])</span></tt></p> <blockquote> ! This function does the same as the Python PyString_FromString / ! PyString_FromStringAndSize C api functions.</blockquote> <p><tt class="docutils literal"><span class="pre">wstring_at(addr[,</span> <span class="pre">size])</span></tt></p> <blockquote> ! This function does the same as the Python PyUnicode_FromWideString C api function. If <tt class="docutils literal"><span class="pre">size</span></tt> is not specified, <tt class="docutils literal"><span class="pre">wcslen</span></tt> is used to determine the string length.</blockquote> --- 835,843 ---- <p><tt class="docutils literal"><span class="pre">string_at(addr[,</span> <span class="pre">size])</span></tt></p> <blockquote> ! This function does the same as the Python <tt class="docutils literal"><span class="pre">PyString_FromString</span></tt> / ! <tt class="docutils literal"><span class="pre">PyString_FromStringAndSize</span></tt> C api functions.</blockquote> <p><tt class="docutils literal"><span class="pre">wstring_at(addr[,</span> <span class="pre">size])</span></tt></p> <blockquote> ! This function does the same as the Python <tt class="docutils literal"><span class="pre">PyUnicode_FromWideString</span></tt> C api function. If <tt class="docutils literal"><span class="pre">size</span></tt> is not specified, <tt class="docutils literal"><span class="pre">wcslen</span></tt> is used to determine the string length.</blockquote> *************** *** 854,858 **** <p><tt class="docutils literal"><span class="pre">memset(dst,</span> <span class="pre">c,</span> <span class="pre">count)</span></tt></p> <blockquote> ! Same as the standard C <tt class="docutils literal"><span class="pre">memset</span></tt> function. Fill the memory block at address <tt class="docutils literal"><span class="pre">dst</span></tt> with <tt class="docutils literal"><span class="pre">count</span></tt> bytes of value <tt class="docutils literal"><span class="pre">c</span></tt>.</blockquote> <p><tt class="docutils literal"><span class="pre">set_conversion_mode(encoding,</span> <span class="pre">errors)</span></tt></p> --- 855,859 ---- <p><tt class="docutils literal"><span class="pre">memset(dst,</span> <span class="pre">c,</span> <span class="pre">count)</span></tt></p> <blockquote> ! Same as the standard C <tt class="docutils literal"><span class="pre">memset</span></tt> function. Fills the memory block at address <tt class="docutils literal"><span class="pre">dst</span></tt> with <tt class="docutils literal"><span class="pre">count</span></tt> bytes of value <tt class="docutils literal"><span class="pre">c</span></tt>.</blockquote> <p><tt class="docutils literal"><span class="pre">set_conversion_mode(encoding,</span> <span class="pre">errors)</span></tt></p> *************** *** 860,864 **** This function sets the encoding/decoding rules when ctypes has to convert between unicode and byte strings. It returns the previous ! encoding, errors tuple.</blockquote> <p><tt class="docutils literal"><span class="pre">DllCanUnloadNow()</span></tt>, <tt class="docutils literal"><span class="pre">DllGetClassObject(rclsid,</span> <span class="pre">riid,</span> <span class="pre">ppv)</span></tt> (Windows only)</p> <blockquote> --- 861,865 ---- This function sets the encoding/decoding rules when ctypes has to convert between unicode and byte strings. It returns the previous ! encoding, as well as a tuple of any errors.</blockquote> <p><tt class="docutils literal"><span class="pre">DllCanUnloadNow()</span></tt>, <tt class="docutils literal"><span class="pre">DllGetClassObject(rclsid,</span> <span class="pre">riid,</span> <span class="pre">ppv)</span></tt> (Windows only)</p> <blockquote> *************** *** 874,887 **** <p><tt class="docutils literal"><span class="pre">FormatError([code])</span></tt> (Windows only)</p> <blockquote> ! Return a textual description of the error code, or the last error code set by Windows.</blockquote> <p><tt class="docutils literal"><span class="pre">GetLastError()</span></tt> (Windows only)</p> <blockquote> ! Return the last error code set by Windows.</blockquote> <div class="section"> <h2><a class="toc-backref" href="#id24" id="deprecated-functions" name="deprecated-functions">Deprecated functions</a></h2> <p><tt class="docutils literal"><span class="pre">c_buffer(init,</span> <span class="pre">size=None)</span></tt></p> <blockquote> ! Deprecated. Use <tt class="docutils literal"><span class="pre">create_string_buffer</span></tt> instead.</blockquote> <p><tt class="docutils literal"><span class="pre">ARRAY(cls,</span> <span class="pre">len)</span></tt></p> <blockquote> --- 875,888 ---- <p><tt class="docutils literal"><span class="pre">FormatError([code])</span></tt> (Windows only)</p> <blockquote> ! Returns a textual description of the error code, or the last error code set by Windows.</blockquote> <p><tt class="docutils literal"><span class="pre">GetLastError()</span></tt> (Windows only)</p> <blockquote> ! Returns the last error code set by Windows.</blockquote> <div class="section"> <h2><a class="toc-backref" href="#id24" id="deprecated-functions" name="deprecated-functions">Deprecated functions</a></h2> <p><tt class="docutils literal"><span class="pre">c_buffer(init,</span> <span class="pre">size=None)</span></tt></p> <blockquote> ! Deprecated. Use <tt class="docutils literal"><span class="pre">create_string_buffer()</span></tt> instead.</blockquote> <p><tt class="docutils literal"><span class="pre">ARRAY(cls,</span> <span class="pre">len)</span></tt></p> <blockquote> |
From: Thomas H. <th...@us...> - 2006-02-17 20:38:13
|
Update of /cvsroot/ctypes/ctypes/docs/manual In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7673 Modified Files: Tag: branch_1_0 simple_types.txt Log Message: Correction by Shi Sherebrin, slightly adjusted by me. Index: simple_types.txt =================================================================== RCS file: /cvsroot/ctypes/ctypes/docs/manual/Attic/simple_types.txt,v retrieving revision 1.1.2.3 retrieving revision 1.1.2.4 diff -C2 -d -r1.1.2.3 -r1.1.2.4 *** simple_types.txt 13 Feb 2006 21:39:24 -0000 1.1.2.3 --- simple_types.txt 17 Feb 2006 20:38:04 -0000 1.1.2.4 *************** *** 7,14 **** the native Python types int, long, string, and unicode. ! This is *not* the case for subclasses of simply data types, so while a ``c_void_p`` type is transparently converted from and to Python integer or long, a subclass of c_void_p is *not* converted. This ! allows to almost completely define new behaviour. Class attributes of simple types --- 7,14 ---- the native Python types int, long, string, and unicode. ! This is *not* the case for subclasses of simple data types, so while a ``c_void_p`` type is transparently converted from and to Python integer or long, a subclass of c_void_p is *not* converted. This ! allows you to define new behaviour almost completely. Class attributes of simple types *************** *** 42,57 **** This is a class method (an instance method of the metaclass, to be ! exact) that will be used to adapt function parameters. If a ! ``c_int`` type is specified in a functions argtypes sequence, ``c_int.from_param(arg)`` will be called by ctypes and the result ! will be passed to the foreign function call as parameter. ``from_param`` usually returns an internal object that you cannot ! use on Python code - it makes only sense to pass this to foreign functions. On one hand, ``from_param`` is a performance optimization - it ! allows to pass Python integers to function calls expecting a ! ``c_int`` argument type, without having to create a full-features ``c_int`` instance. --- 42,57 ---- This is a class method (an instance method of the metaclass, to be ! exact) that is used to adapt function parameters. If a ! ``c_int`` type is specified in a function's argtypes sequence, ``c_int.from_param(arg)`` will be called by ctypes and the result ! will be passed to the foreign function call as a parameter. ``from_param`` usually returns an internal object that you cannot ! use in Python code - it only makes sense to pass this to foreign functions. On one hand, ``from_param`` is a performance optimization - it ! allows you to pass Python integers to function calls expecting a ! ``c_int`` argument type, without having to create a full-featured ``c_int`` instance. *************** *** 87,91 **** ``_b_needsfree_`` (readonly) ! Implementation artifact: does this object have to free it's memory block on destruction. --- 87,91 ---- ``_b_needsfree_`` (readonly) ! Implementation artifact: does this object have to free its memory block on destruction. *************** *** 98,102 **** ``_as_parameter_`` (readonly) ! Implementation artifact (?): how to pass this object as function parameter. --- 98,102 ---- ``_as_parameter_`` (readonly) ! Implementation artifact (?): how to pass this object as a function parameter. *************** *** 107,111 **** Integer types are ``c_byte``, ``c_short``, ``c_int``, ``c_long``, ``c_longlong`` and their unsigned variants ``c_ubyte``, ``c_ushort``, ! ``c_uint``, ``c_ulong`` and ``c_longlong``, floating point types are ``c_float`` and ``c_double``. --- 107,111 ---- Integer types are ``c_byte``, ``c_short``, ``c_int``, ``c_long``, ``c_longlong`` and their unsigned variants ``c_ubyte``, ``c_ushort``, ! ``c_uint``, ``c_ulong`` and ``c_ulonglong``, floating point types are ``c_float`` and ``c_double``. *************** *** 133,141 **** The only simple pointer type is ``c_void_p``, which represents the C ! ``void *`` datra type. ``c_void_p`` can also be written as ``POINTER(None)``. The constructor accepts one optional argument, which must be an ! integer or long interpreted as address, or ``None``. The ``from_param`` class method accepts everything that could be used --- 133,141 ---- The only simple pointer type is ``c_void_p``, which represents the C ! ``void *`` data type. ``c_void_p`` can also be written as ``POINTER(None)``. The constructor accepts one optional argument, which must be an ! integer or long (interpreted as an address), or ``None``. The ``from_param`` class method accepts everything that could be used *************** *** 145,149 **** The ``value`` attribute accepts and returns None or integer. ! XXX Shouldn't the constructor accept the same types than from_param? --- 145,149 ---- The ``value`` attribute accepts and returns None or integer. ! XXX Shouldn't the constructor accept the same types as from_param? *************** *** 153,166 **** ctypes has the ``c_char_p`` and ``c_wchar_p`` types which represent const pointers to zero terminated strings in C: ``const char *`` and ! ``const wchar_t *``. Since Python strings and unicode instances are immutable, these types should be considered readonly: do not pass them to functions that write into the buffer. The constructor accepts one optional argument, which must be a Python ! string or unicode string, an integer, or ``None``. ! The ``from_param`` class method accepts Python strings or unicode ! strings, as well as ``None``. Conversion between string and unicode, ! if needed, is done according to the ctypes encoding/decoding rules. XXX Why does the constructor accept an integer, and from_param doesn't? \ No newline at end of file --- 153,166 ---- ctypes has the ``c_char_p`` and ``c_wchar_p`` types which represent const pointers to zero terminated strings in C: ``const char *`` and ! ``const wchar_t *``. Since strings and Unicode instances are immutable, these types should be considered readonly: do not pass them to functions that write into the buffer. The constructor accepts one optional argument, which must be a Python ! or unicode string, an integer, or ``None``. ! The ``from_param`` class method accepts a string or a Unicode string, ! as well as ``None``. Conversion between string and Unicode, if ! needed, is done according to the ctypes encoding/decoding rules. XXX Why does the constructor accept an integer, and from_param doesn't? \ No newline at end of file |
From: Thomas H. <th...@us...> - 2006-02-16 20:35:51
|
Update of /cvsroot/ctypes/ctypes/comtypes/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12048 Added Files: Tag: branch_1_0 test_variant.py Log Message: Ported test_variant.py from ctypes.com. --- NEW FILE: test_variant.py --- import unittest, os from ctypes import * from comtypes import IUnknown, GUID from comtypes.automation import VARIANT, DISPPARAMS from comtypes.typeinfo import LoadTypeLibEx, LoadRegTypeLib def get_refcnt(comptr): # return the COM reference count of a COM interface pointer if not comptr: return 0 comptr.AddRef() return comptr.Release() class VariantTestCase(unittest.TestCase): def test_com_refcounts(self): # typelib for Internet Explorer tlb = LoadRegTypeLib(GUID("{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}"), 1, 1, 0) self.failUnlessEqual(get_refcnt(tlb), 1) p = tlb.QueryInterface(IUnknown) self.failUnlessEqual(get_refcnt(tlb), 2) del p self.failUnlessEqual(get_refcnt(tlb), 1) def test_com_pointers(self): # Storing a COM interface pointer in a VARIANT increments the refcount, # changing the variant to contain something else decrements it tlb = LoadRegTypeLib(GUID("{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}"), 1, 1, 0) self.failUnlessEqual(get_refcnt(tlb), 1) v = VARIANT(tlb) self.failUnlessEqual(get_refcnt(tlb), 2) p = v.value self.failUnlessEqual(get_refcnt(tlb), 3) del p self.failUnlessEqual(get_refcnt(tlb), 2) v.value = None self.failUnlessEqual(get_refcnt(tlb), 1) def test_null_com_pointers(self): p = POINTER(IUnknown)() self.failUnlessEqual(get_refcnt(p), 0) v = VARIANT(p) self.failUnlessEqual(get_refcnt(p), 0) def test_dispparams(self): # DISPPARAMS is a complex structure, well worth testing. d = DISPPARAMS() d.rgvarg = (VARIANT * 3)() # XXX The following line fails, which is a real bug in ctypes: # SystemError: ...\Objects\listobject.c:105: bad argument to internal function # # Update: this bug is fixed, now I have to rememeber what I wanted to test here. d.rgvarg[0].value = 1 def test_pythonobjects(self): objects = [None, 42, 3.14, True, False, "abc", u"abc", 7L] for x in objects: v = VARIANT(x) self.failUnlessEqual(x, v.value) def test_integers(self): import sys v = VARIANT() v.value = sys.maxint self.failUnlessEqual(v.value, sys.maxint) self.failUnlessEqual(type(v.value), int) v.value += 1 self.failUnlessEqual(v.value, sys.maxint+1) self.failUnlessEqual(type(v.value), long) v.value = 1L self.failUnlessEqual(v.value, 1) self.failUnlessEqual(type(v.value), int) def test_datetime(self): import datetime now = datetime.datetime.now() v = VARIANT() v.value = now from ctypes.com.automation import VT_DATE self.failUnlessEqual(v.vt, VT_DATE) self.failUnlessEqual(v.value, now) def test_BSTR(self): from ctypes.com.automation import BSTR, VT_BSTR v = VARIANT() v.value = u"abc\x00123\x00" self.failUnlessEqual(v.value, "abc\x00123\x00") v.value = None # manually clear the variant v._.VT_I4 = 0 # NULL pointer BSTR should be handled as empty string v.vt = VT_BSTR self.failUnlessEqual(v.value, "") class ArrayTest(unittest.TestCase): def test_double(self): import array for typecode in "df": # because of FLOAT rounding errors, whi will only work for # certain values! a = array.array(typecode, (1.0, 2.0, 3.0, 4.5)) v = VARIANT() v.value = a self.failUnlessEqual(v.value, (1.0, 2.0, 3.0, 4.5)) def test_int(self): import array for typecode in "bhiBHIlL": a = array.array(typecode, (1, 1, 1, 1)) v = VARIANT() v.value = a self.failUnlessEqual(v.value, (1, 1, 1, 1)) ################################################################ if __name__ == '__main__': unittest.main() |
From: Thomas H. <th...@us...> - 2006-02-16 20:02:57
|
Update of /cvsroot/ctypes/ctypes/docs/manual In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29395 Modified Files: Tag: branch_1_0 tutorial.txt Log Message: Add warning that it is out-of-date. Index: tutorial.txt =================================================================== RCS file: /cvsroot/ctypes/ctypes/docs/manual/Attic/tutorial.txt,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -C2 -d -r1.1.2.1 -r1.1.2.2 *** tutorial.txt 16 Feb 2006 19:56:41 -0000 1.1.2.1 --- tutorial.txt 16 Feb 2006 20:02:45 -0000 1.1.2.2 *************** *** 5,8 **** --- 5,10 ---- .. contents:: + Warning: The contents of the tutorial is severly out of date! + This tutorial describes version 0.6.3 of ``ctypes``. There have been quite some changes to version 0.4.x, the most important are |