ctypes-commit Mailing List for ctypes (Page 92)
Brought to you by:
theller
You can subscribe to this list here.
2004 |
Jan
|
Feb
|
Mar
|
Apr
(8) |
May
(90) |
Jun
(143) |
Jul
(106) |
Aug
(94) |
Sep
(84) |
Oct
(163) |
Nov
(60) |
Dec
(58) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2005 |
Jan
(128) |
Feb
(79) |
Mar
(227) |
Apr
(192) |
May
(179) |
Jun
(41) |
Jul
(53) |
Aug
(103) |
Sep
(28) |
Oct
(38) |
Nov
(81) |
Dec
(17) |
2006 |
Jan
(184) |
Feb
(111) |
Mar
(188) |
Apr
(67) |
May
(58) |
Jun
(123) |
Jul
(73) |
Aug
|
Sep
|
Oct
(1) |
Nov
|
Dec
|
From: Thomas H. <th...@us...> - 2004-09-16 20:21:16
|
Update of /cvsroot/ctypes/ctypes/unittests/com In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25267 Modified Files: test_sysalloc.py Log Message: Changes in the setUp/tearDown logic to leave com initialized after the tests have been run. Index: test_sysalloc.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/com/test_sysalloc.py,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** test_sysalloc.py 18 Aug 2004 12:20:09 -0000 1.4 --- test_sysalloc.py 16 Sep 2004 20:21:07 -0000 1.5 *************** *** 5,12 **** from ctypes.com.automation import BSTR, VARIANT - # We init COM before each test, and uninit afterwards. - # So we must start UN-initialized! - ole32.CoUninitialize() - def find_test_dll(): import sys, os --- 5,8 ---- *************** *** 22,25 **** --- 18,24 ---- class MallocSpyTest(unittest.TestCase): def setUp(self): + # ctypes.com has called CoInitialize, but we must install the spy + # in uninitialized state. + ole32.CoUninitialize() self.expect = None self.mallocspy = mallocspy.MallocSpy() *************** *** 29,48 **** def tearDown(self): try: ! # Even if tests fail or crash, we have to make sure we can ! # shutdown safely. The problem is that mallocspy cannot be ! # revoked completely while there are still unfreed memory ! # blocks which have been allocated while it was registered. ! # ! # So, we must delete *all* COM objects we still have anywhere, ! # even if an error occurred somewhere, and then shutdown COM, ! # BEFORE Python exits. ! try: 1/0 ! except: pass ! ole32.CoUninitialize() ! # Now, check the desired test outcome: ! self.failUnlessEqual(len(self.mallocspy.active_blocks()), self.expect) finally: ! self.mallocspy.revoke(warn=0) ################ --- 28,51 ---- def tearDown(self): try: ! try: ! # Even if tests fail or crash, we have to make sure we can ! # shutdown safely. The problem is that mallocspy cannot be ! # revoked completely while there are still unfreed memory ! # blocks which have been allocated while it was registered. ! # ! # So, we must delete *all* COM objects we still have anywhere, ! # even if an error occurred somewhere, and then shutdown COM, ! # BEFORE Python exits. ! try: 1/0 ! except: pass ! ole32.CoUninitialize() ! # Now, check the desired test outcome: ! self.failUnlessEqual(len(self.mallocspy.active_blocks()), self.expect) ! finally: ! self.mallocspy.revoke(warn=0) finally: ! # we must restore the environment to the state we found it! ! ole32.CoInitialize(None) ################ |
From: Thomas H. <th...@us...> - 2004-09-16 19:55:40
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19165 Modified Files: ChangeLog Log Message: Released ctypes 0.9.1. Index: ChangeLog =================================================================== RCS file: /cvsroot/ctypes/ctypes/ChangeLog,v retrieving revision 1.59 retrieving revision 1.60 diff -C2 -d -r1.59 -r1.60 *** ChangeLog 16 Sep 2004 14:34:05 -0000 1.59 --- ChangeLog 16 Sep 2004 19:55:31 -0000 1.60 *************** *** 1,4 **** --- 1,6 ---- 2004-09-16 Thomas Heller <th...@py...> + * (Message): ctypes 0.9.1 released. + * (Message): The internal conversions that ctypes does between unicode and strings can now use a specified encoding and error |
From: Thomas H. <th...@us...> - 2004-09-16 14:34:14
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12574 Modified Files: NEWS.txt ChangeLog ANNOUNCE Log Message: Record changes. Index: ANNOUNCE =================================================================== RCS file: /cvsroot/ctypes/ctypes/ANNOUNCE,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** ANNOUNCE 15 Sep 2004 22:00:18 -0000 1.15 --- ANNOUNCE 16 Sep 2004 14:34:05 -0000 1.16 *************** *** 28,31 **** --- 28,40 ---- ctypes changes + The internal conversions that ctypes does between unicode and + strings can now use a specified encoding and error handling. A + set_conversion_mode() function allows to set them, it returns the + previous values. The inital values are ('mbcs', 'ignore') on + Windows, and ('ascii', 'strict') on other systems. + + When internal processing of an argument for a function call fails, + the new ctypes.ArgumentError is raised. + CDLL and its subclasses now accept an optional second handle parameter. If this is supplied, it is used instead of calling Index: NEWS.txt =================================================================== RCS file: /cvsroot/ctypes/ctypes/NEWS.txt,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** NEWS.txt 15 Sep 2004 22:00:18 -0000 1.9 --- NEWS.txt 16 Sep 2004 14:34:05 -0000 1.10 *************** *** 9,12 **** --- 9,21 ---- ctypes changes + The internal conversions that ctypes does between unicode and + strings can now use a specified encoding and error handling. A + set_conversion_mode() function allows to set them, it returns the + previous values. The inital values are ('mbcs', 'ignore') on + Windows, and ('ascii', 'strict') on other systems. + + When internal processing of an argument for a function call fails, + the new ctypes.ArgumentError is raised. + CDLL and its subclasses now accept an optional second handle parameter. If this is supplied, it is used instead of calling Index: ChangeLog =================================================================== RCS file: /cvsroot/ctypes/ctypes/ChangeLog,v retrieving revision 1.58 retrieving revision 1.59 diff -C2 -d -r1.58 -r1.59 *** ChangeLog 15 Sep 2004 22:00:18 -0000 1.58 --- ChangeLog 16 Sep 2004 14:34:05 -0000 1.59 *************** *** 1,2 **** --- 1,19 ---- + 2004-09-16 Thomas Heller <th...@py...> + + * (Message): The internal conversions that ctypes does between + unicode and strings can now use a specified encoding and error + handling. A set_conversion_mode() function allows to set them, it + returns the previous values. The inital values are ('mbcs', + 'ignore') on Windows, and ('ascii', 'strist') on other systems. + + (source\callproc.c): The Extend_Error_Info() function has been + fixed - sometimes is displayed weird error messages like + 'TypeError: function takes 5 arguments (1 given)' when an + UnicodeEncodingError was raised. + + When internal processing of an argument for a function call fails, + the new ctypes.ArgumentError exception is raised. + + 2004-09-15 Thomas Heller <th...@py...> |
From: Thomas H. <th...@us...> - 2004-09-16 14:18:58
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10015 Modified Files: test_random_things.py Log Message: Index: test_random_things.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_random_things.py,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** test_random_things.py 16 Sep 2004 10:30:28 -0000 1.7 --- test_random_things.py 16 Sep 2004 14:18:48 -0000 1.8 *************** *** 48,53 **** out = self.capture_stderr(cb, 0) self.failUnlessEqual(out.splitlines()[-1], ! "RuntimeError: (in callback) " ! "exceptions.ZeroDivisionError: integer division or modulo by zero") def test_FloatDivisionError(self): --- 48,53 ---- out = self.capture_stderr(cb, 0) self.failUnlessEqual(out.splitlines()[-1], ! "RuntimeError: (in callback) exceptions.ZeroDivisionError: " ! "integer division or modulo by zero") def test_FloatDivisionError(self): *************** *** 55,60 **** out = self.capture_stderr(cb, 0.0) self.failUnlessEqual(out.splitlines()[-1], ! "RuntimeError: (in callback) " ! "exceptions.ZeroDivisionError: float division") def test_TypeErrorDivisionError(self): --- 55,60 ---- out = self.capture_stderr(cb, 0.0) self.failUnlessEqual(out.splitlines()[-1], ! "RuntimeError: (in callback) exceptions.ZeroDivisionError: " ! "float division") def test_TypeErrorDivisionError(self): *************** *** 62,67 **** out = self.capture_stderr(cb, "spam") self.failUnlessEqual(out.splitlines()[-1], ! "RuntimeError: (in callback) " ! "exceptions.TypeError: unsupported operand type(s) for /: 'int' and 'str'") if __name__ == '__main__': --- 62,67 ---- out = self.capture_stderr(cb, "spam") self.failUnlessEqual(out.splitlines()[-1], ! "RuntimeError: (in callback) exceptions.TypeError: " ! "unsupported operand type(s) for /: 'int' and 'str'") if __name__ == '__main__': |
From: Thomas H. <th...@us...> - 2004-09-16 14:18:15
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9922 Modified Files: test_parameters.py Log Message: change and restore the ctypes conversion mode, so that this test works again. Index: test_parameters.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_parameters.py,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** test_parameters.py 27 Aug 2004 12:04:50 -0000 1.24 --- test_parameters.py 16 Sep 2004 14:18:04 -0000 1.25 *************** *** 3,6 **** --- 3,24 ---- class SimpleTypesTestCase(unittest.TestCase): + def setUp(self): + import ctypes + try: + from _ctypes import set_conversion_mode + except ImportError: + pass + else: + self.prev_conv_mode = set_conversion_mode("ascii", "strict") + + def tearDown(self): + try: + from _ctypes import set_conversion_mode + except ImportError: + pass + else: + set_conversion_mode(*self.prev_conv_mode) + + # XXX Replace by c_char_p tests def test_cstrings(self): |
From: Thomas H. <th...@us...> - 2004-09-16 14:17:20
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9598 Modified Files: ctypes.h cfield.c callproc.c _ctypes.c Log Message: Make the Extend_Error_Info function more robust. Rename two global variables, and declare them in ctypes.h. Index: ctypes.h =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/ctypes.h,v retrieving revision 1.49 retrieving revision 1.50 diff -C2 -d -r1.49 -r1.50 *** ctypes.h 16 Sep 2004 10:26:36 -0000 1.49 --- ctypes.h 16 Sep 2004 14:17:11 -0000 1.50 *************** *** 258,261 **** --- 258,264 ---- extern PyObject *PyExc_ArgError; + extern char *conversion_mode_encoding; + extern char *conversion_mode_errors; + /* Local Variables: Index: callproc.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/callproc.c,v retrieving revision 1.103 retrieving revision 1.104 diff -C2 -d -r1.103 -r1.104 *** callproc.c 16 Sep 2004 10:26:36 -0000 1.103 --- callproc.c 16 Sep 2004 14:17:11 -0000 1.104 *************** *** 781,784 **** --- 781,788 ---- } + /* + * Raise a new exception 'exc_class', adding additional text to the original + * exception string. + */ void Extend_Error_Info(PyObject *exc_class, char *fmt, ...) { *************** *** 795,805 **** PyErr_NormalizeException(&tp, &v, &tb); cls_str = PyObject_Str(tp); ! msg_str = PyObject_Str(v); ! if (cls_str) { PyString_ConcatAndDel(&s, cls_str); PyString_ConcatAndDel(&s, PyString_FromString(": ")); ! } if (msg_str) PyString_ConcatAndDel(&s, msg_str); PyErr_SetObject(exc_class, s); Py_XDECREF(tp); --- 799,814 ---- PyErr_NormalizeException(&tp, &v, &tb); cls_str = PyObject_Str(tp); ! if (cls_str) { PyString_ConcatAndDel(&s, cls_str); PyString_ConcatAndDel(&s, PyString_FromString(": ")); ! } else ! PyErr_Clear(); ! msg_str = PyObject_Str(v); if (msg_str) PyString_ConcatAndDel(&s, msg_str); + else { + PyErr_Clear(); + PyString_ConcatAndDel(&s, PyString_FromString("???")); + } PyErr_SetObject(exc_class, s); Py_XDECREF(tp); *************** *** 809,812 **** --- 818,822 ---- } + #ifdef MS_WIN32 #define alloca _alloca *************** *** 1215,1219 **** --- 1225,1263 ---- } + #ifdef HAVE_USABLE_WCHAR_T + + static PyObject * + set_conversion_mode(PyObject *self, PyObject *args) + { + char *coding, *mode; + PyObject *result; + + if (!PyArg_ParseTuple(args, "zs", &coding, &mode)) + return NULL; + result = Py_BuildValue("(zz)", conversion_mode_encoding, conversion_mode_errors); + if (coding) { + PyMem_Free(conversion_mode_encoding); + conversion_mode_encoding = PyMem_Malloc(strlen(coding) + 1); + strcpy(conversion_mode_encoding, coding); + } else { + conversion_mode_encoding = NULL; + } + PyMem_Free(conversion_mode_errors); + conversion_mode_errors = PyMem_Malloc(strlen(mode) + 1); + strcpy(conversion_mode_errors, mode); + return result; + } + + static char set_conversion_mode_doc[] = + "FormatError(encoding, errors) -> (previous-encoding, previous-errors)\n\ + \n\ + Set the encoding and error handling ctypes uses when converting\n\ + between unicode and strings. Returns the previous values.\n"; + #endif + PyMethodDef module_methods[] = { + #ifdef HAVE_USABLE_WCHAR_T + {"set_conversion_mode", set_conversion_mode, METH_VARARGS, set_conversion_mode_doc}, + #endif #ifdef MS_WIN32 {"CopyComPointer", copy_com_pointer, METH_VARARGS, copy_com_pointer_doc}, Index: cfield.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/cfield.c,v retrieving revision 1.42 retrieving revision 1.43 diff -C2 -d -r1.42 -r1.43 *** cfield.c 14 Sep 2004 18:33:39 -0000 1.42 --- cfield.c 16 Sep 2004 14:17:11 -0000 1.43 *************** *** 553,557 **** if (PyString_Check(value)) { ! value = PyUnicode_FromObject(value); if (!value) return NULL; --- 553,559 ---- if (PyString_Check(value)) { ! value = PyUnicode_FromEncodedObject(value, ! conversion_mode_encoding, ! conversion_mode_errors); if (!value) return NULL; *************** *** 623,627 **** if (PyString_Check(value)) { ! value = PyUnicode_FromObject(value); if (!value) return NULL; --- 625,631 ---- if (PyString_Check(value)) { ! value = PyUnicode_FromEncodedObject(value, ! conversion_mode_encoding, ! conversion_mode_errors); if (!value) return NULL; *************** *** 710,714 **** return value; } else if (PyUnicode_Check(value)) { ! PyObject *str = PyUnicode_AsASCIIString(value); if (str == NULL) return NULL; --- 714,720 ---- return value; } else if (PyUnicode_Check(value)) { ! PyObject *str = PyUnicode_AsEncodedString(value, ! conversion_mode_encoding, ! conversion_mode_errors); if (str == NULL) return NULL; *************** *** 748,752 **** } if (PyString_Check(value)) { ! value = PyUnicode_FromObject(value); if (!value) return NULL; --- 754,760 ---- } if (PyString_Check(value)) { ! value = PyUnicode_FromEncodedObject(value, ! conversion_mode_encoding, ! conversion_mode_errors); if (!value) return NULL; *************** *** 790,794 **** value = NULL; } else if (PyString_Check(value)) { ! value = PyUnicode_FromObject(value); if (!value) return NULL; --- 798,804 ---- value = NULL; } else if (PyString_Check(value)) { ! value = PyUnicode_FromEncodedObject(value, ! conversion_mode_encoding, ! conversion_mode_errors); if (!value) return NULL; Index: _ctypes.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes.c,v retrieving revision 1.157 retrieving revision 1.158 diff -C2 -d -r1.157 -r1.158 *** _ctypes.c 16 Sep 2004 10:26:36 -0000 1.157 --- _ctypes.c 16 Sep 2004 14:17:11 -0000 1.158 *************** *** 99,102 **** --- 99,105 ---- PyObject *PyExc_ArgError; + char *conversion_mode_encoding = NULL; + char *conversion_mode_errors = NULL; + /******************************************************************/ *************** *** 689,693 **** if (PyString_Check(value)) { ! value = PyUnicode_FromObject(value); if (!value) return -1; --- 692,698 ---- if (PyString_Check(value)) { ! value = PyUnicode_FromEncodedObject(value, ! conversion_mode_encoding, ! conversion_mode_errors); if (!value) return -1; |
From: Thomas H. <th...@us...> - 2004-09-16 13:00:04
|
Update of /cvsroot/ctypes/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23916 Modified Files: __init__.py Log Message: Set the default ctypes conversion mode ("mbcs", "ignore") on Windows, ("ascii", "strict") else. Index: __init__.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/__init__.py,v retrieving revision 1.34 retrieving revision 1.35 diff -C2 -d -r1.34 -r1.35 *** __init__.py 16 Sep 2004 10:26:26 -0000 1.34 --- __init__.py 16 Sep 2004 12:59:47 -0000 1.35 *************** *** 369,370 **** --- 369,379 ---- return WindowsError(code, descr) + try: + from _ctypes import set_conversion_mode + except ImportError: + pass + else: + if _os.name == "nt": + set_conversion_mode("mbcs", "ignore") + else: + set_coversion_mode("ascii", "strict") |
From: Thomas H. <th...@us...> - 2004-09-16 10:41:26
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26438 Modified Files: test_structures.py Log Message: The exceptions raised by Extend_Error_Info look different now - make the tests work again. Index: test_structures.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_structures.py,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** test_structures.py 16 Sep 2004 10:30:28 -0000 1.20 --- test_structures.py 16 Sep 2004 10:41:15 -0000 1.21 *************** *** 219,224 **** cls, msg = self.get_except(Person, "Someone", ("a", "b", "c")) ! self.failUnlessEqual(cls, ValueError) ! self.failUnlessEqual(msg, "(Phone) too many initializers") --- 219,224 ---- cls, msg = self.get_except(Person, "Someone", ("a", "b", "c")) ! self.failUnlessEqual(cls, RuntimeError) ! self.failUnlessEqual(msg, "(Phone) exceptions.ValueError: too many initializers") |
From: Thomas H. <th...@us...> - 2004-09-16 10:30:41
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24293 Modified Files: test_structures.py test_returnfuncptrs.py test_random_things.py test_prototypes.py test_functions.py Log Message: The exceptions raised by Extend_Error_Info look different now - make the tests work again. Index: test_random_things.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_random_things.py,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** test_random_things.py 19 Aug 2004 11:31:56 -0000 1.6 --- test_random_things.py 16 Sep 2004 10:30:28 -0000 1.7 *************** *** 42,46 **** out = self.capture_stderr(cb, 42) self.failUnlessEqual(out.splitlines()[-1], ! "ValueError: (in callback) 42") def test_IntegerDivisionError(self): --- 42,46 ---- out = self.capture_stderr(cb, 42) self.failUnlessEqual(out.splitlines()[-1], ! "RuntimeError: (in callback) exceptions.ValueError: 42") def test_IntegerDivisionError(self): *************** *** 48,52 **** out = self.capture_stderr(cb, 0) self.failUnlessEqual(out.splitlines()[-1], ! "ZeroDivisionError: (in callback) integer division or modulo by zero") def test_FloatDivisionError(self): --- 48,53 ---- out = self.capture_stderr(cb, 0) self.failUnlessEqual(out.splitlines()[-1], ! "RuntimeError: (in callback) " ! "exceptions.ZeroDivisionError: integer division or modulo by zero") def test_FloatDivisionError(self): *************** *** 54,58 **** out = self.capture_stderr(cb, 0.0) self.failUnlessEqual(out.splitlines()[-1], ! "ZeroDivisionError: (in callback) float division") def test_TypeErrorDivisionError(self): --- 55,60 ---- out = self.capture_stderr(cb, 0.0) self.failUnlessEqual(out.splitlines()[-1], ! "RuntimeError: (in callback) " ! "exceptions.ZeroDivisionError: float division") def test_TypeErrorDivisionError(self): *************** *** 60,64 **** out = self.capture_stderr(cb, "spam") self.failUnlessEqual(out.splitlines()[-1], ! "TypeError: (in callback) unsupported operand type(s) for /: 'int' and 'str'") if __name__ == '__main__': --- 62,67 ---- out = self.capture_stderr(cb, "spam") self.failUnlessEqual(out.splitlines()[-1], ! "RuntimeError: (in callback) " ! "exceptions.TypeError: unsupported operand type(s) for /: 'int' and 'str'") if __name__ == '__main__': Index: test_returnfuncptrs.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_returnfuncptrs.py,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** test_returnfuncptrs.py 28 Jul 2004 12:56:55 -0000 1.6 --- test_returnfuncptrs.py 16 Sep 2004 10:30:28 -0000 1.7 *************** *** 24,28 **** self.failUnlessEqual(strchr("abcdef", "b"), "bcdef") self.failUnlessEqual(strchr("abcdef", "x"), None) ! self.assertRaises(TypeError, strchr, "abcdef", 3) self.assertRaises(TypeError, strchr, "abcdef") --- 24,28 ---- self.failUnlessEqual(strchr("abcdef", "b"), "bcdef") self.failUnlessEqual(strchr("abcdef", "x"), None) ! self.assertRaises(ArgumentError, strchr, "abcdef", 3) self.assertRaises(TypeError, strchr, "abcdef") *************** *** 36,40 **** self.failUnless(strchr("abcdef", "b"), "bcdef") self.failUnlessEqual(strchr("abcdef", "x"), None) ! self.assertRaises(TypeError, strchr, "abcdef", 3) self.assertRaises(TypeError, strchr, "abcdef") --- 36,40 ---- self.failUnless(strchr("abcdef", "b"), "bcdef") self.failUnlessEqual(strchr("abcdef", "x"), None) ! self.assertRaises(ArgumentError, strchr, "abcdef", 3) self.assertRaises(TypeError, strchr, "abcdef") Index: test_functions.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_functions.py,v retrieving revision 1.36 retrieving revision 1.37 diff -C2 -d -r1.36 -r1.37 *** test_functions.py 28 Jul 2004 12:56:55 -0000 1.36 --- test_functions.py 16 Sep 2004 10:30:28 -0000 1.37 *************** *** 209,213 **** self.failIfEqual(result.contents, v.value) ! self.assertRaises(TypeError, f, byref(c_short(22))) # It is dangerous, however, because you don't control the lifetime --- 209,213 ---- self.failIfEqual(result.contents, v.value) ! self.assertRaises(ArgumentError, f, byref(c_short(22))) # It is dangerous, however, because you don't control the lifetime *************** *** 270,274 **** # argument types cb = AnotherCallback(callback) ! self.assertRaises(TypeError, f, -10, cb) --- 270,274 ---- # argument types cb = AnotherCallback(callback) ! self.assertRaises(ArgumentError, f, -10, cb) Index: test_structures.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_structures.py,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** test_structures.py 2 Sep 2004 19:59:19 -0000 1.19 --- test_structures.py 16 Sep 2004 10:30:28 -0000 1.20 *************** *** 213,218 **** cls, msg = self.get_except(Person, "Someone", (1, 2)) ! self.failUnlessEqual(cls, TypeError) ! self.failUnlessEqual(msg, "(Phone) expected string or Unicode object, int found") cls, msg = self.get_except(Person, "Someone", ("a", "b", "c")) --- 213,220 ---- cls, msg = self.get_except(Person, "Someone", (1, 2)) ! self.failUnlessEqual(cls, RuntimeError) ! self.failUnlessEqual(msg, ! "(Phone) exceptions.TypeError: " ! "expected string or Unicode object, int found") cls, msg = self.get_except(Person, "Someone", ("a", "b", "c")) Index: test_prototypes.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_prototypes.py,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** test_prototypes.py 28 Jul 2004 12:56:55 -0000 1.4 --- test_prototypes.py 16 Sep 2004 10:30:28 -0000 1.5 *************** *** 55,65 **** func.argtypes = c_char_p, ! self.assertRaises(TypeError, func, byref(ci)) func.argtypes = POINTER(c_short), ! self.assertRaises(TypeError, func, byref(ci)) func.argtypes = POINTER(c_double), ! self.assertRaises(TypeError, func, byref(ci)) def test_POINTER_c_char_arg(self): --- 55,65 ---- func.argtypes = c_char_p, ! self.assertRaises(ArgumentError, func, byref(ci)) func.argtypes = POINTER(c_short), ! self.assertRaises(ArgumentError, func, byref(ci)) func.argtypes = POINTER(c_double), ! self.assertRaises(ArgumentError, func, byref(ci)) def test_POINTER_c_char_arg(self): |
From: Thomas H. <th...@us...> - 2004-09-16 10:26:50
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23575 Modified Files: ctypes.h callproc.c callbacks.c _ctypes.c Log Message: ctypes now has a ArgumentError exception class. Extend_Error_Info now works differently: It takes an exception class to raise as first argument, then converts the original exception to a string, and raises the specified exception. Index: ctypes.h =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/ctypes.h,v retrieving revision 1.48 retrieving revision 1.49 diff -C2 -d -r1.48 -r1.49 *** ctypes.h 20 Aug 2004 14:28:46 -0000 1.48 --- ctypes.h 16 Sep 2004 10:26:36 -0000 1.49 *************** *** 243,247 **** int index, int size, char *ptr); ! extern void Extend_Error_Info(char *fmt, ...); struct basespec { --- 243,247 ---- int index, int size, char *ptr); ! extern void Extend_Error_Info(PyObject *exc_class, char *fmt, ...); struct basespec { *************** *** 255,258 **** --- 255,261 ---- extern ffi_type *GetType(PyObject *obj); + /* exception classes */ + extern PyObject *PyExc_ArgError; + /* Local Variables: Index: callbacks.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/callbacks.c,v retrieving revision 1.59 retrieving revision 1.60 diff -C2 -d -r1.59 -r1.60 *** callbacks.c 28 Jul 2004 12:46:41 -0000 1.59 --- callbacks.c 16 Sep 2004 10:26:36 -0000 1.60 *************** *** 170,174 **** result = PyObject_CallObject(callable, arglist); if (!result) { ! Extend_Error_Info("(in callback) "); PyErr_Print(); } else if (result != Py_None) { --- 170,174 ---- result = PyObject_CallObject(callable, arglist); if (!result) { ! Extend_Error_Info(PyExc_RuntimeError, "(in callback) "); PyErr_Print(); } else if (result != Py_None) { *************** *** 205,209 **** } if (keep == NULL) { ! Extend_Error_Info("(callback return type) "); PyErr_Print(); } else { --- 205,209 ---- } if (keep == NULL) { ! Extend_Error_Info(PyExc_RuntimeError, "(callback return type) "); PyErr_Print(); } else { Index: callproc.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/callproc.c,v retrieving revision 1.102 retrieving revision 1.103 diff -C2 -d -r1.102 -r1.103 *** callproc.c 15 Sep 2004 20:32:30 -0000 1.102 --- callproc.c 16 Sep 2004 10:26:36 -0000 1.103 *************** *** 781,788 **** } ! void Extend_Error_Info(char *fmt, ...) { va_list vargs; ! PyObject *tp, *v, *tb, *s, *msg; va_start(vargs, fmt); --- 781,788 ---- } ! void Extend_Error_Info(PyObject *exc_class, char *fmt, ...) { va_list vargs; ! PyObject *tp, *v, *tb, *s, *cls_str, *msg_str; va_start(vargs, fmt); *************** *** 794,806 **** PyErr_Fetch(&tp, &v, &tb); PyErr_NormalizeException(&tp, &v, &tb); ! msg = PyObject_Str(v); ! if (msg) { ! PyString_ConcatAndDel(&s, msg); ! Py_DECREF(v); ! PyErr_Restore(tp, s, tb); ! } else { ! PyErr_Clear(); ! PyErr_Restore(tp, v, tb); } } --- 794,810 ---- PyErr_Fetch(&tp, &v, &tb); PyErr_NormalizeException(&tp, &v, &tb); ! cls_str = PyObject_Str(tp); ! msg_str = PyObject_Str(v); ! if (cls_str) { ! PyString_ConcatAndDel(&s, cls_str); ! PyString_ConcatAndDel(&s, PyString_FromString(": ")); } + if (msg_str) + PyString_ConcatAndDel(&s, msg_str); + PyErr_SetObject(exc_class, s); + Py_XDECREF(tp); + Py_XDECREF(v); + Py_XDECREF(tb); + Py_DECREF(s); } *************** *** 865,869 **** NULL); if (v == NULL) { ! Extend_Error_Info("while constructing argument %d:\n", i+1); goto cleanup; } --- 869,873 ---- NULL); if (v == NULL) { ! Extend_Error_Info(PyExc_ArgError, "argument %d: ", i+1); goto cleanup; } *************** *** 872,876 **** Py_DECREF(v); if (-1 == err) { ! Extend_Error_Info("while constructing argument %d:\n", i+1); goto cleanup; } --- 876,880 ---- Py_DECREF(v); if (-1 == err) { ! Extend_Error_Info(PyExc_ArgError, "argument %d: ", i+1); goto cleanup; } *************** *** 878,882 **** err = ConvParam(arg, i+1, pa); if (-1 == err) { ! Extend_Error_Info("while constructing argument %d:\n", i+1); goto cleanup; /* leaking ? */ } --- 882,886 ---- err = ConvParam(arg, i+1, pa); if (-1 == err) { ! Extend_Error_Info(PyExc_ArgError, "argument %d: ", i+1); goto cleanup; /* leaking ? */ } Index: _ctypes.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes.c,v retrieving revision 1.156 retrieving revision 1.157 diff -C2 -d -r1.156 -r1.157 *** _ctypes.c 15 Sep 2004 21:38:45 -0000 1.156 --- _ctypes.c 16 Sep 2004 10:26:36 -0000 1.157 *************** *** 97,100 **** --- 97,101 ---- #endif + PyObject *PyExc_ArgError; *************** *** 1866,1870 **** ob = PyObject_CallObject(type, value); if (ob == NULL) { ! Extend_Error_Info("(%s) ", ((PyTypeObject *)type)->tp_name); return NULL; } --- 1867,1872 ---- ob = PyObject_CallObject(type, value); if (ob == NULL) { ! Extend_Error_Info(PyExc_RuntimeError, "(%s) ", ! ((PyTypeObject *)type)->tp_name); return NULL; } *************** *** 3735,3739 **** PyModule_AddObject(m, "FUNCFLAG_PYTHONAPI", PyInt_FromLong(FUNCFLAG_PYTHONAPI)); PyModule_AddStringConstant(m, "__version__", "0.9.1"); ! /************************************************* * --- 3737,3746 ---- PyModule_AddObject(m, "FUNCFLAG_PYTHONAPI", PyInt_FromLong(FUNCFLAG_PYTHONAPI)); PyModule_AddStringConstant(m, "__version__", "0.9.1"); ! ! PyExc_ArgError = PyErr_NewException("ctypes.ArgumentError", NULL, NULL); ! if (PyExc_ArgError) { ! Py_INCREF(PyExc_ArgError); ! PyModule_AddObject(m, "ArgumentError", PyExc_ArgError); ! } /************************************************* * |
From: Thomas H. <th...@us...> - 2004-09-16 10:26:37
|
Update of /cvsroot/ctypes/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23512 Modified Files: __init__.py Log Message: ctypes now has a ArgumentError exception class. Extend_Error_Info now works differently: It takes an exception class to raise as first argument, then converts the original exception to a string, and raises the specified exception. Index: __init__.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/__init__.py,v retrieving revision 1.33 retrieving revision 1.34 diff -C2 -d -r1.33 -r1.34 *** __init__.py 15 Sep 2004 22:00:52 -0000 1.33 --- __init__.py 16 Sep 2004 10:26:26 -0000 1.34 *************** *** 16,19 **** --- 16,21 ---- from _ctypes import __version__ as _ctypes_version + from _ctypes import ArgumentError + if __version__ != _ctypes_version: raise Exception, ("Version number mismatch", __version__, _ctypes_version) |
From: Thomas H. <th...@us...> - 2004-09-15 22:12:44
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28232 Modified Files: test_cfuncs.py Log Message: Use the debug version of _ctypes_test when running debug python. Index: test_cfuncs.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_cfuncs.py,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** test_cfuncs.py 27 Aug 2004 19:04:52 -0000 1.15 --- test_cfuncs.py 15 Sep 2004 22:12:23 -0000 1.16 *************** *** 5,20 **** from ctypes import * - def find_test_dll(): - import sys, os - if os.name == "nt": - name = "_ctypes_test.pyd" - else: - name = "_ctypes_test.so" - for p in sys.path: - f = os.path.join(p, name) - if os.path.isfile(f): - return f - return None - # These two functions report the argument in the last call to one of # the tf_? functions. --- 5,8 ---- *************** *** 24,27 **** --- 12,19 ---- get_last_tf_arg_u as U + def find_test_dll(): + import _ctypes_test + return _ctypes_test.__file__ + class CFunctions(unittest.TestCase): def __init__(self, *args): |
From: Thomas H. <th...@us...> - 2004-09-15 22:01:03
|
Update of /cvsroot/ctypes/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24989 Modified Files: __init__.py Log Message: CDLL and subclasses now accept an optional second handle parameter. If this is supplied, it is used instead of calling LoadLibrary() or dlopen() to get one. Index: __init__.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/__init__.py,v retrieving revision 1.32 retrieving revision 1.33 diff -C2 -d -r1.32 -r1.33 *** __init__.py 7 Sep 2004 06:37:36 -0000 1.32 --- __init__.py 15 Sep 2004 22:00:52 -0000 1.33 *************** *** 269,275 **** _handle = 0 ! def __init__(self, name, LoadLibrary=_LoadLibrary): self._name = name ! self._handle = LoadLibrary(self._name) def __repr__(self): --- 269,278 ---- _handle = 0 ! def __init__(self, name, handle=None): self._name = name ! if handle is None: ! self._handle = _LoadLibrary(self._name) ! else: ! self._handle = handle def __repr__(self): *************** *** 299,307 **** _restype_ = c_int # default, can be overridden in instances - if _os.name == "nt": - pythonapi = PyDLL("python%s%s" % sys.version_info[:2]) - else: - pythonapi = PyDLL(None) - if _os.name == "nt": --- 302,305 ---- *************** *** 349,352 **** --- 347,357 ---- cdll = _DLLS(CDLL) pydll = _DLLS(PyDLL) + + if _os.name == "nt": + pythonapi = PyDLL("python dll", sys.dllhandle) + else: + pythonapi = PyDLL(None) + + if _os.name == "nt": windll = _DLLS(WinDLL) |
From: Thomas H. <th...@us...> - 2004-09-15 22:00:33
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24830 Modified Files: NEWS.txt ChangeLog ANNOUNCE Log Message: CDLL and subclasses now accept an optional second handle parameter. If this is supplied, it is used instead of calling LoadLibrary() or dlopen() to get one. Index: ANNOUNCE =================================================================== RCS file: /cvsroot/ctypes/ctypes/ANNOUNCE,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** ANNOUNCE 15 Sep 2004 20:52:33 -0000 1.14 --- ANNOUNCE 15 Sep 2004 22:00:18 -0000 1.15 *************** *** 28,31 **** --- 28,35 ---- ctypes changes + CDLL and its subclasses now accept an optional second handle + parameter. If this is supplied, it is used instead of calling + LoadLibrary() or dlopen() to get one. + Sometimes objects have been freed too early when calling functions where argtypes have been set. Index: NEWS.txt =================================================================== RCS file: /cvsroot/ctypes/ctypes/NEWS.txt,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** NEWS.txt 15 Sep 2004 20:52:33 -0000 1.8 --- NEWS.txt 15 Sep 2004 22:00:18 -0000 1.9 *************** *** 9,12 **** --- 9,16 ---- ctypes changes + CDLL and its subclasses now accept an optional second handle + parameter. If this is supplied, it is used instead of calling + LoadLibrary() or dlopen() to get one. + Sometimes objects have been freed too early when calling functions where argtypes have been set. Index: ChangeLog =================================================================== RCS file: /cvsroot/ctypes/ctypes/ChangeLog,v retrieving revision 1.57 retrieving revision 1.58 diff -C2 -d -r1.57 -r1.58 *** ChangeLog 15 Sep 2004 20:52:33 -0000 1.57 --- ChangeLog 15 Sep 2004 22:00:18 -0000 1.58 *************** *** 1,4 **** --- 1,8 ---- 2004-09-15 Thomas Heller <th...@py...> + * ctypes\__init__.py: CDLL and subclasses now accept an optional + second handle parameter. If this is supplied, it is used instead + of calling LoadLibrary() or dlopen() to get one. + * source\callproc.c: Important fix - sometimes pointers to arguments in function call have been free'd too early, especially |
From: Thomas H. <th...@us...> - 2004-09-15 21:38:54
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17824 Modified Files: _ctypes.c Log Message: Add parens to avoid compiler warning. Index: _ctypes.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes.c,v retrieving revision 1.155 retrieving revision 1.156 diff -C2 -d -r1.155 -r1.156 *** _ctypes.c 1 Sep 2004 12:03:57 -0000 1.155 --- _ctypes.c 15 Sep 2004 21:38:45 -0000 1.156 *************** *** 2454,2458 **** required ++; #endif ! if (dict->flags & FUNCFLAG_CDECL == FUNCFLAG_CDECL) { /* For cdecl functions, we allow more actual arguments than the length of the argtypes tuple. --- 2454,2458 ---- required ++; #endif ! if ((dict->flags & FUNCFLAG_CDECL) == FUNCFLAG_CDECL) { /* For cdecl functions, we allow more actual arguments than the length of the argtypes tuple. |
From: Thomas H. <th...@us...> - 2004-09-15 20:52:46
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3783 Modified Files: NEWS.txt ChangeLog ANNOUNCE Log Message: Record changes. Index: ANNOUNCE =================================================================== RCS file: /cvsroot/ctypes/ctypes/ANNOUNCE,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** ANNOUNCE 14 Sep 2004 19:52:03 -0000 1.13 --- ANNOUNCE 15 Sep 2004 20:52:33 -0000 1.14 *************** *** 28,31 **** --- 28,34 ---- ctypes changes + Sometimes objects have been freed too early when calling functions + where argtypes have been set. + Fixed the create_unicode_buffer function - it was returning c_char arrays instead of c_wchar arrays. Index: NEWS.txt =================================================================== RCS file: /cvsroot/ctypes/ctypes/NEWS.txt,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** NEWS.txt 14 Sep 2004 19:53:14 -0000 1.7 --- NEWS.txt 15 Sep 2004 20:52:33 -0000 1.8 *************** *** 9,12 **** --- 9,15 ---- ctypes changes + Sometimes objects have been freed too early when calling functions + where argtypes have been set. + Fixed the create_unicode_buffer function - it was returning c_char arrays instead of c_wchar arrays. Index: ChangeLog =================================================================== RCS file: /cvsroot/ctypes/ctypes/ChangeLog,v retrieving revision 1.56 retrieving revision 1.57 diff -C2 -d -r1.56 -r1.57 *** ChangeLog 7 Sep 2004 06:39:43 -0000 1.56 --- ChangeLog 15 Sep 2004 20:52:33 -0000 1.57 *************** *** 1,2 **** --- 1,8 ---- + 2004-09-15 Thomas Heller <th...@py...> + + * source\callproc.c: Important fix - sometimes pointers to + arguments in function call have been free'd too early, especially + when argtypes have been specified for functions. + 2004-09-07 Thomas Heller <th...@py...> |
From: Thomas H. <th...@us...> - 2004-09-15 20:32:39
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30974 Modified Files: callproc.c Log Message: Important bug fix: ConvParam must keep a reference to the original object when it stores pointers in the PyCArgObject. Index: callproc.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/callproc.c,v retrieving revision 1.101 retrieving revision 1.102 diff -C2 -d -r1.101 -r1.102 *** callproc.c 1 Sep 2004 12:03:56 -0000 1.101 --- callproc.c 15 Sep 2004 20:32:30 -0000 1.102 *************** *** 459,462 **** --- 459,464 ---- PyCArgObject *carg = (PyCArgObject *)obj; pa->ffi_type = carg->pffi_type; + Py_INCREF(obj); + pa->keep = obj; memcpy(&pa->value, &carg->value, sizeof(pa->value)); return 0; *************** *** 494,497 **** --- 496,501 ---- pa->ffi_type = &ffi_type_pointer; pa->value.p = PyString_AS_STRING(obj); + Py_INCREF(obj); + pa->keep = obj; return 0; } *************** *** 501,504 **** --- 505,510 ---- pa->ffi_type = &ffi_type_pointer; pa->value.p = PyUnicode_AS_UNICODE(obj); + Py_INCREF(obj); + pa->keep = obj; return 0; } |
From: Thomas H. <th...@us...> - 2004-09-14 20:00:50
|
Update of /cvsroot/ctypes/ctypes/docs In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6719 Modified Files: index.stx Log Message: Update for the 0.9.1 release. Index: index.stx =================================================================== RCS file: /cvsroot/ctypes/ctypes/docs/index.stx,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** index.stx 23 Jul 2004 17:34:24 -0000 1.7 --- index.stx 14 Sep 2004 20:00:40 -0000 1.8 *************** *** 17,44 **** News ! **'ctypes' version 0.9.0 has been released.** ! ! 'ctypes' now requires Python 2.3 or higher, Python 2.2 is no longer ! supported. ! ! The big change is that 'ctypes' now uses the same code base on all ! platforms, many, many bug should have been fixed this way on ! non-windows systems. ! ! There have been lots of improvements and additions both to ctypes ! itself, and to the ctypes.com windows framework, too many to ! remember now and document here. ! ! Most prominent additions to ctypes.com are: ! A ctypes.com.client module supporting dynamic dispatch ! An internet explorer toolband sample ! Many improvements to the stoplite sample Detailed changelogs are in CVS (well, sometimes I forget to update them): "ChangeLog":http://cvs.sourceforge.net/viewcvs.py/ctypes/ctypes/ChangeLog?rev=HEAD --- 17,34 ---- News ! **'ctypes' version 0.9.1 has been released (Sept 14, 2004).** ! ctypes can now call Python API functions (without releasing the ! global interpreter lock). ! Slicing is now supported for array and pointer instances. ! Several bugfixes. Detailed changelogs are in CVS (well, sometimes I forget to update them): + "ANNOUNCE":http://cvs.sourceforge.net/viewcvs.py/ctypes/ctypes/ANNOUNCE?rev=release_0_9_1 + "ChangeLog":http://cvs.sourceforge.net/viewcvs.py/ctypes/ctypes/ChangeLog?rev=HEAD *************** *** 92,126 **** Old news ! 'ctypes' version 0.6.3 has been released. The changes are ! summarized "here":changes.html. ! ! Yasushi Masuda has translated the docs into ! "japanese":http://www.python.jp/pub/doc_jp/contrib/ctypes/. ! ! A 'ctypes' ! "Wiki":http://starship.python.net/crew/theller/moin.cgi/CtypesModule, ! and a mailing list which should be used to discuss the ! usage and further development of 'ctypes'. More info can be found ! on the "list info page":http://lists.sourceforge.net/lists/listinfo/ctypes-users. ! 'ctypes' version 0.6.0 has been released, and the ! documentation has been updated. ! There have been some (also incompatible) changes, but I'm quite ! pleased with the result: ctypes is much more consistent than before. ! A proof-of-concept COM framework has been implemented, and added ! to the package. It is in an early stage, and I would like ! experienced COM developers to look at it, and submit feedback. ! 'ctypes' now works on Windows, Linux and MacOSX. Thanks ! to *Robin Becker* and *Just van Rossum* for their help. ! 'ctypes' Development now takes place on sourceforge's "ctypes ! project page":http://sourceforge.net/projects/ctypes. ! I've started a "FAQ":faq.html which should be consulted ! in case of problems. Documentation --- 82,105 ---- Old news ! **'ctypes' 0.9.0:** + 'ctypes' now requires Python 2.3 or higher, Python 2.2 is no longer + supported. ! The big change is that 'ctypes' now uses the same code base on all ! platforms, many, many bug should have been fixed this way on ! non-windows systems. ! There have been lots of improvements and additions both to ctypes ! itself, and to the ctypes.com windows framework, too many to ! remember now and document here. ! Most prominent additions to ctypes.com are: ! A ctypes.com.client module supporting dynamic dispatch ! An internet explorer toolband sample ! Many improvements to the stoplite sample Documentation |
From: Thomas H. <th...@us...> - 2004-09-14 19:53:26
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5217 Modified Files: NEWS.txt Log Message: The NEWS.txt file now accumulates what is in ANNOUNCE for each release. Index: NEWS.txt =================================================================== RCS file: /cvsroot/ctypes/ctypes/NEWS.txt,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** NEWS.txt 27 Aug 2004 11:52:17 -0000 1.6 --- NEWS.txt 14 Sep 2004 19:53:14 -0000 1.7 *************** *** 1,5 **** ctypes News - http://starship.python.net/crew/theller/ctypes.html ! Version 0.9.1 Cache the types that WINFUNCTYPE and CFUNCTYPE creates, to avoid --- 1,79 ---- ctypes News - http://starship.python.net/crew/theller/ctypes.html ! Changes in 0.9.1 ! ================ ! ! ctypes 0.9.1 should be fully compatible again with Gary Bishop's ! readline module which is also used by IPython. ! ! ctypes changes ! ! Fixed the create_unicode_buffer function - it was returning c_char ! arrays instead of c_wchar arrays. ! ! Both create_string_buffer and create_unicode_buffer can now be ! called with string and unicode instances, they will do the needed ! conversions themselves. ! ! ctypes now allows calling Python C api functions. The 'pythonapi' ! symbol should be used to access these functions, this will ! automatically use the correct calling convention and exception ! handling. The 'py_object' type is the ctypes variant of 'PyObject *'. ! This feature should also work if you are using a static python ! build. ! ! It is now possible to call cdecl functions with more arguments ! than the length of the argtypes sequence specifies - this allows ! to provide functions like sprintf() with a proper prototype. ! ! It is now possible to create strings or unicode strings if you ! have the integer address by calling c_char_p(address) or ! c_wchar_p(address). Integers can also be assigned to structure ! fields of type c_char_p and c_wchar_p. ! ! c_char_p and c_wchar_p both accept strings and unicode strings - ! if needed they are encoded or decoded using 'strict' error ! handling. ! ! The _ctypes.call_function function, although private and ! deprecated, has been put back in - it is used by Gary Bishop's ! readline module. ! ! Array and pointer instances now support slicing, for pointers only ! getslice is implemented (setslice is too dangerous, probably). ! Slices are represented as lists of the elements, except ! for character and unicode character pointer and arrays, where ! strings resp. unicode strings are used instead. ! ! On windows, the include files were missing from the source ! distribution. ! ! The alignment function was not exported by the ctypes module. It ! returns the alignment requirements in bytes of a type or instance. ! ! ! ctypes.com changes ! ! Applied a patch from Bruce Dodson which fixes an infinite loop in ! readtlb.py if a typelib references types defined in another ! typelib. readtlb still generates bad code for such cases, but the ! results could be edited by hand if the dependencies can be sorted ! out. ! ! ctypes now caches the types that WINFUNCTYPE and CFUNCTYPE ! creates, to avoid unneeeded creation of classes. This ! makes importing files containing a lot of COM interfaces (like the ! ones that the readtlb tool generates) a lot (10 x) faster. ! ! COM servers now print a short usage message when they are run ! without the /regserver or /unregserver flag. ! ! VARIANT does now handle the COM DATE type (VT_DATE) as Python ! datetime. ! ! VARIANT now handles integers and longs correctly - if longs are ! too large they are stored as doubles (VT_R8). Integers are now ! stored as VT_I4 instead of VT_INT. ! Cache the types that WINFUNCTYPE and CFUNCTYPE creates, to avoid *************** *** 19,32 **** strings resp. unicode strings are used - much more convenient. - Experimatal change: ! It is now possibile to safely call Python C Api functions. ! Before, this was dangerous because ctypes releases and reaquires ! the threadstate before resp. after the call of C functions. Most ! Python API functions require a valid threadstate, especially in ! combination with the native windows handling this could lead to ! very strange effects. This functionality is experimental and will ! probably change in future releases, if you want to try it out you ! should ask on the ctypes-users mailing list. Other Versions: no news recorded in this file! Please see the CVS --- 93,120 ---- strings resp. unicode strings are used - much more convenient. ! Changes in 0.9.0 ! ================ ! ! ctypes now requires Python 2.3 or higher, Python 2.2 is no longer ! supported. ! ! The big change is that ctypes now uses the same code base on all ! platforms, many, many bug should have been fixed this way on ! non-windows systems. The destribution now contains libffi, no ! need to find, download, build and install a compatible version. ! ! There have been lots of improvements and additions both to ctypes ! itself, and to the ctypes.com windows framework, too many to ! remember now and document here. ! ! Most prominent additions to ctypes.com are: ! ! A ctypes.com.client module supporting dynamic dispatch ! ! An internet explorer toolband sample ! ! Many improvements to the stoplite sample ! Other Versions: no news recorded in this file! Please see the CVS |
From: Thomas H. <th...@us...> - 2004-09-14 19:52:13
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4948 Modified Files: ANNOUNCE Log Message: small nits. Index: ANNOUNCE =================================================================== RCS file: /cvsroot/ctypes/ctypes/ANNOUNCE,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** ANNOUNCE 7 Sep 2004 06:39:43 -0000 1.12 --- ANNOUNCE 14 Sep 2004 19:52:03 -0000 1.13 *************** *** 1,4 **** ! ctypes 0.9.1 released ! ===================== Overview --- 1,4 ---- ! ctypes 0.9.1 released - Sept 14, 2004 ! ===================================== Overview *************** *** 35,42 **** conversions themselves. ! ctypes now allows calling Python C api functions. The pythonapi symbol should be used to access these functions, this will automatically use the correct calling convention and exception ! handling. The py_object type is the ctypes variant of 'PyObject *'. This feature should also work if you are using a static python build. --- 35,42 ---- conversions themselves. ! ctypes now allows calling Python C api functions. The 'pythonapi' symbol should be used to access these functions, this will automatically use the correct calling convention and exception ! handling. The 'py_object' type is the ctypes variant of 'PyObject *'. This feature should also work if you are using a static python build. *************** *** 74,78 **** ctypes.com changes - Applied a patch from Bruce Dodson which fixes an infinite loop in readtlb.py if a typelib references types defined in another --- 74,77 ---- |
From: Thomas H. <th...@us...> - 2004-09-14 18:33:48
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20430 Modified Files: cfield.c Log Message: Fix two more compiler warnings. Index: cfield.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/cfield.c,v retrieving revision 1.41 retrieving revision 1.42 diff -C2 -d -r1.41 -r1.42 *** cfield.c 27 Aug 2004 12:02:54 -0000 1.41 --- cfield.c 14 Sep 2004 18:33:39 -0000 1.42 *************** *** 717,721 **** return str; } else if (PyInt_Check(value) || PyLong_Check(value)) { ! *(char **)ptr = PyInt_AsUnsignedLongMask(value); Py_INCREF(Py_None); return Py_None; --- 717,721 ---- return str; } else if (PyInt_Check(value) || PyLong_Check(value)) { ! *(char **)ptr = (char *)PyInt_AsUnsignedLongMask(value); Py_INCREF(Py_None); return Py_None; *************** *** 752,756 **** return NULL; } else if (PyInt_Check(value) || PyLong_Check(value)) { ! *(wchar_t **)ptr = PyInt_AsUnsignedLongMask(value); Py_INCREF(Py_None); return Py_None; --- 752,756 ---- return NULL; } else if (PyInt_Check(value) || PyLong_Check(value)) { ! *(wchar_t **)ptr = (wchar_t *)PyInt_AsUnsignedLongMask(value); Py_INCREF(Py_None); return Py_None; |
From: Thomas H. <th...@us...> - 2004-09-10 23:09:43
|
Update of /cvsroot/ctypes/ctypes/sandbox/tools/structures In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14373 Modified Files: gccxmltools.py Log Message: Change the Visitor interface. The objects to visit are no longer passed to the constructor, they are passed to the go method. Index: gccxmltools.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/sandbox/tools/structures/gccxmltools.py,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** gccxmltools.py 10 Sep 2004 09:36:46 -0000 1.2 --- gccxmltools.py 10 Sep 2004 11:39:46 -0000 1.3 *************** *** 392,397 **** class Visitor(object): - def __init__(self, objects): - self.__objects = objects def _visit(self, obj): --- 392,395 ---- *************** *** 403,408 **** ## warnings.warn(type(obj), Warning) ! def go(self): ! for o in self.__objects: self._visit(o) --- 401,406 ---- ## warnings.warn(type(obj), Warning) ! def go(self, objects): ! for o in objects: self._visit(o) |
From: Thomas H. <th...@us...> - 2004-09-10 22:02:11
|
Update of /cvsroot/ctypes/ctypes/sandbox/tools/structures In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1818 Added Files: gccxmltools.py Log Message: GCCXML runner and parser as a separate module. --- NEW FILE: gccxmltools.py --- """ Usage: gccxmltools.py [options] files... Command line flags: -c <value>, --compiler <value> Specifies the compiler that GCCXML should emulate. For Windows, typically use msvc6 or msvc71. -D <symbol> -D <symbol=value> -U <symbol> -I <directory> These flags are passed to GCCXML. -o <filename> Write the parsing results to <filename>. Using '-' as filename will write the results to standard output. -v Increases the verbosity. Verbosity 1 prints out what the program is doing, verbosity 2 additionally prints lines it could not parse. -h Display help, then quit. Sample command line (depends on the MSVC compiler you have): gccxmltools.py -D NONAMELESSUNION -D _WIN32_WINNT=0x500 -c msvc71 -o- windows.h """ import sys, os, tempfile from xml.sax import make_parser, parse, handler ################################################################ class CompilerError(Exception): pass # Create a C file containing #includes to the specified filenames. # Parse it with GCCXML into a XML file, and return the xml filename. def run_gccxml(options, verbose, *fnames): # options is a sequence of command line options for GCCXML # fnames is the sequence of include files # verbose - integer specifying the verbosity # returns the filename of the generated XML file options = " ".join(options) # write a temporary C file handle, c_file = tempfile.mkstemp(suffix=".c", text=True) os.write(handle, 'extern "C" {\n'); for fname in fnames: os.write(handle, '#include <%s>\n' % fname) os.write(handle, '}'); os.close(handle) ## handle, xml_file = tempfile.mkstemp(suffix=".xml", text=True) ## os.close(handle) xml_file = "~temp.xml" try: if verbose: print >> sys.stderr, r"gccxml.exe %s %s -fxml=%s" % (options, c_file, xml_file) i, o = os.popen4(r"gccxml.exe %s %s -fxml=%s" % (options, c_file, xml_file)) i.close() sys.stderr.write(o.read()) retval = o.close() if retval: raise CompilerError, "gccxml returned error %s" % retval return xml_file finally: if verbose: print >> sys.stderr, "Deleting temporary file %s" % c_file os.remove(c_file) ################################################################ # abstract base classes # class Base(object): def _resolve(self, find_typ): return def __repr__(self): return "%s(%s)" % (self.__class__.__name__, self.name) def depends(self): return [] class TypeContainer(Base): typ = None def _resolve(self, find_typ): if self.typ is not None: return self.typ = find_typ(self._typ) self.typ._resolve(find_typ) def depends(self): return [self.typ] ################################ # concrete classes class FundamentalType(Base): def __init__(self, name): self.name = name class Enumeration(Base): def __init__(self, name): self.name = name self.values = [] def add_value(self, name, value): self.values.append((name, value)) class PointerType(TypeContainer): def __init__(self, typ): self._typ = typ def __repr__(self): return "PointerType(%s)" % self.typ class Typedef(TypeContainer): def __init__(self, name, typ): self.name = name self._typ = typ def __repr__(self): return "Typedef(%s -> %s)" % (self.name, self.typ) class Field(TypeContainer): def __init__(self, name, typ, bits=None): self.name = name self._typ = typ self.bits = bits def __repr__(self): return "Field(%s -> %s)" % (self.name, self.typ) class ArrayType(TypeContainer): def __init__(self, typ, min, max): self._typ = typ self.min = int(min) if max == "": self.max = -1 elif max == "ffffffffffffffff": self.max = -99 ##0xFFFFFFFFFFFFFFFF else: self.max = int(max) def __repr__(self): return "Array(%s[%s:%s])" % (self.typ, self.min, self.max) class CvQualifiedType(TypeContainer): def __init__(self, typ, const): self._typ = typ self.const = const def __repr__(self): return "ConstQualifier(%s)" % (self.typ) class Union(Base): members = None def __init__(self, name, members): self.name = name self._members = members def _resolve(self, find_typ): if self.members is not None: return self.members = [] for id in self._members: f = find_typ(id) f._resolve(find_typ) if type(f) in (Field, Method): self.members.append(f) def depends(self): return [field.typ for field in self.members] class Structure(Union): bases = None def __init__(self, name, members, bases): self.name = name self._members = members self._bases = bases def _resolve(self, find_typ): super(Structure, self)._resolve(find_typ) if self.bases is not None: return self.bases = [] for id in self._bases.split(): b = find_typ(id) b._resolve(find_typ) self.bases.append(b) def isClass(self): for m in self.members: if type(m) is Method: return True return False def __repr__(self): return "Structure(%s)" % self.name def depends(self): return [field.typ for field in self.members if type(field) == Field] class Constructor(Base): def __init__(self, name): self.name = name class Method(Base): returns = None def __init__(self, name, returns): self.name = name self._returns = returns def _resolve(self, find_typ): if self.returns is not None: return self.returns = find_typ(self._returns) self.returns._resolve(find_typ) def depends(self): return [self.returns] class FunctionType(Base): def __repr__(self): return "FunctionType" class Function(Base): returns = None def __init__(self, name, returns): self.name = name self._returns = returns def _resolve(self, find_typ): if self.returns is None: r = find_typ(self._returns) self.returns = r r._resolve(find_typ) return def depends(self): return [self.returns] ################################################################ from sets import Set def D(attrs): result = {} for name, value in attrs._attrs.items(): result[str(name)] = value return result class GCCXML_Handler(handler.ContentHandler): has_values = Set(["Enumeration", "Function", "FunctionType", "Method"]) def __init__(self, *args): handler.ContentHandler.__init__(self, *args) self.context = [] self.all = {} def startElement(self, name, attrs): result = None mth = getattr(self, name, None) if mth is not None: result = mth(attrs) _id = attrs.get("id", None) if _id is not None: self.all[_id] = result else: import warnings warnings.warn(name, Warning) if name in self.has_values: self.context.append(result) def endElement(self, name): if name in self.has_values: self.context = self.context[:-1] def get_result(self): for item in self.all.values(): item._resolve(self.all.__getitem__) return self.all.values() ################ def Function(self, attrs): # name, returns, extern, attributes name = attrs["name"] returns = attrs["returns"] return Function(name, returns) def Field(self, attrs): # name, type name = attrs["name"] typ = attrs["type"] bits = attrs.get("bits", None) return Field(name, typ, bits) def Constructor(self, attrs): name = attrs["name"] return Constructor(name) def Typedef(self, attrs): name = attrs["name"] typ = attrs["type"] return Typedef(name, typ) def FundamentalType(self, attrs): name = attrs["name"] return FundamentalType(name) def PointerType(self, attrs): typ = attrs["type"] return PointerType(typ) def CvQualifiedType(self, attrs): # id, type, [const|volatile] typ = attrs["type"] ## const = attrs["const"] ## volatile = attrs["volatile"] return CvQualifiedType(typ, "xxx") def ArrayType(self, attrs): # type, min?, max? typ = attrs["type"] min = attrs["min"] max = attrs["max"] return ArrayType(typ, min, max) def Enumeration(self, attrs): # id, name name = attrs["name"] return Enumeration(name) def Struct(self, attrs): # id, name, members name = attrs["name"] bases = attrs.get("bases", "") members = attrs.get("members", "").split() return Structure(name, members, bases) def Union(self, attrs): name = attrs["name"] return Union(name, attrs.get("members", "").split()) def Method(self, attrs): # name, virtual, pure_virtual, returns name = attrs["name"] returns = attrs["returns"] return Method(name, returns) def FunctionType(self, attrs): # id, returns, attributes return FunctionType() ## def Variable(self, attrs): ## # Variable <Variable id="_652" name="IID_StdOle" type="_3925c" ## # context="_1" location="f4:30" file="f4" line="30" extern="1"/> ## name = attrs["name"] ## typ = attrs["type"] ## extern = attrs["extern"] ## return Variable(name, typ, extern) ## def Argument(self, attrs): ## pass def EnumValue(self, attrs): name = attrs["name"] value = attrs["init"] self.context[-1].add_value(name, value) # OperatorFunction # Ellipsis # ReferenceType # File ################################################################ class Visitor(object): def __init__(self, objects): self.__objects = objects def _visit(self, obj): mth = getattr(self, obj.__class__.__name__, None) if mth is not None: mth(obj) def go(self): for o in self.__objects: self._visit(o) ################################################################ def main(args=None): if args is None: args = sys.argv[1:] import getopt gccxml_options = [] verbose = 0 try: opts, files = getopt.getopt(args, "hvc:D:U:I:o:", ["compiler="]) except (getopt.GetoptError, ValueError): print >> sys.stderr, __doc__ return 1 py_file = None for o, a in opts: if o in ("-c", "--compiler"): gccxml_options.append("--gccxml-compiler %s" % a) elif o in ("-D", "-U", "-I"): gccxml_options.append("%s %s" % (o, a)) elif o == "-v": verbose += 1 elif o == "-h": print >> sys.stderr, __doc__ return 0 elif o == "-o": py_file = a if not files: print "Error: no files to process" print >> sys.stderr, __doc__ return 1 xml_file = run_gccxml(gccxml_options, verbose, *files) handler = GCCXML_Handler() parse(xml_file, handler) ## os.remove(xml_file) return handler.get_result() if __name__ == "__main__": if len(sys.argv) == 1: ## sys.argv.extend("-D NONAMELESSUNION -I. -D _WIN32_WINNT=0x500 -c msvc71 -o- windows.h richedit.h".split()) sys.argv.extend("-D NONAMELESSUNION -D _WIN32_WINNT=0x500 -c msvc6 -o- windows.h".split()) main() |
From: Thomas H. <th...@us...> - 2004-09-10 21:51:30
|
Update of /cvsroot/ctypes/ctypes/sandbox/tools/structures In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13971 Modified Files: genapi.py Log Message: Making progress. Index: genapi.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/sandbox/tools/structures/genapi.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** genapi.py 10 Sep 2004 07:45:20 -0000 1.1 --- genapi.py 10 Sep 2004 08:47:18 -0000 1.2 *************** *** 3,9 **** --- 3,27 ---- ctypes_names = { + "char": "c_char", + "unsigned char": "c_ubyte", + + "wchar_t": "c_wchar", + + "short int": "c_short", + "short unsigned int": "c_ushort", + "int": "c_int", "unsigned int": "c_uint", + + "long int": "c_long", + "long unsigned int": "c_ulong", + "long long int": "c_longlong", + "long long unsigned int": "c_ulonglong", + + "void": "void", + + "double": "c_double", + "float": "c_float", } *************** *** 13,16 **** --- 31,38 ---- def run(self): + # returns a tuple of two lists. The first one contains + # objects for which to generate code, the second contains + # objects with unresolved dependencies. + result = [] done = Set() remaining = Set() *************** *** 39,62 **** if not deps - done: resolved.add(o) ! print o ! print print "# resolved %d of %d -> %d" % (len(resolved), len(remaining), len(remaining) - len(resolved)) - print if not resolved: ! print "%d unresolved deps" % len(remaining) ! return remaining done = done | resolved remaining = remaining - resolved ! ## raw_input("Weiter?") if __name__ == "__main__": import sys if len(sys.argv) == 1: ! ## sys.argv.extend("-D NONAMELESSUNION -D _WIN32_WINNT=0x500 -c msvc6 -o- windef.h".split()) ! sys.argv.extend("-D NONAMELESSUNION -D _WIN32_WINNT=0x500 -c msvc6 -o- windows.h".split()) result = gccxmltools.main() p = DependencyResolver(result) ! p.run() --- 61,153 ---- if not deps - done: resolved.add(o) ! result.append(o) print "# resolved %d of %d -> %d" % (len(resolved), len(remaining), len(remaining) - len(resolved)) if not resolved: ! print "# %d unresolved deps" % len(remaining) ! return result, remaining done = done | resolved remaining = remaining - resolved ! return result, list(remaining) ! ! ################################################################ ! ! class CodeGenerator(gccxmltools.Visitor): + def __init__(self, *args, **kw): + super(CodeGenerator, self).__init__(*args, **kw) + self._env = {} + exec "from ctypes import *" in self._env + + def Enumeration(self, enum): + # generate the ctypes code for an enumeration. + code = ["class %s(c_int):" % enum.name] + code += [" %s = %s" % pair for pair in enum.values] + code = "\n".join(code) + exec code in self._env + print code + + def Typedef(self, td): + if type(td.typ) is gccxmltools.Structure and td.typ.isClass(): + return + code = "%s = %s" % (td.name, self.ctypes_name(td.typ)) + try: + exec code in self._env + except Exception: + print "#", code + else: + print code + + def Structure(self, struct): + if struct.name.startswith("$_"): + return + code = ["class %s(Structure):" % struct.name] + code += [" _fields_ = []"] + try: + exec "\n".join(code) in self._env + except Exception: + print "#", code[0] + else: + print "\n".join(code) + + Union = Structure + + def ctypes_name(self, obj): + if type(obj) is gccxmltools.FundamentalType: + return ctypes_names[obj.name] + elif type(obj) is gccxmltools.FunctionType: + return "c_void_p" # fixme + elif type(obj) is gccxmltools.PointerType: + name = self.ctypes_name(obj.typ) + if name == "void": + return "c_void_p" + return "POINTER(%s)" % name + elif type(obj) is gccxmltools.CvQualifiedType: + return self.ctypes_name(obj.typ) + elif type(obj) is gccxmltools.ArrayType: + assert obj.min == 0 + return "%s * %d" % (self.ctypes_name(obj.typ), obj.max + 1) + elif type(obj) in (gccxmltools.Typedef, gccxmltools.Enumeration, gccxmltools.Structure, gccxmltools.Union): + return obj.name + raise TypeError, type(obj) + + ################################################################ if __name__ == "__main__": import sys if len(sys.argv) == 1: ! sys.argv.extend("-D NONAMELESSUNION -D _WIN32_WINNT=0x500 -c msvc6 -o- windef.h".split()) ! ## sys.argv.extend("-D NONAMELESSUNION -D _WIN32_WINNT=0x500 -c msvc6 -o- windows.h".split()) result = gccxmltools.main() p = DependencyResolver(result) ! result, remaining = p.run() ! ! print "from ctypes import *" ! print ! ! cg = CodeGenerator(result) ! cg.go() ! ! for o in remaining: ! print "#", o |
From: Thomas H. <th...@us...> - 2004-09-10 21:51:05
|
Update of /cvsroot/ctypes/ctypes/sandbox/tools/structures In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1958 Modified Files: gen_structs.py Log Message: Obsolete. Index: gen_structs.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/sandbox/tools/structures/gen_structs.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** gen_structs.py 7 Sep 2004 09:47:59 -0000 1.1 --- gen_structs.py 10 Sep 2004 07:44:04 -0000 1.2 *************** *** 1,4 **** """ ! Usage: parse_structs [options] files... Command line flags: --- 1,4 ---- """ ! Usage: gen_structs [options] files... Command line flags: *************** *** 28,32 **** Sample command line (depends on the MSVC compiler you have): ! parse_structs -D _WIN32_WINNT=0x500 -c msvc71 -o- windows.h """ import sys, os, tempfile --- 28,32 ---- Sample command line (depends on the MSVC compiler you have): ! gen_structs -D NONAMELESSUNION -D _WIN32_WINNT=0x500 -c msvc71 -o- windows.h """ import sys, os, tempfile *************** *** 145,151 **** self.members = attrs["members"].split() ! def dump(self, stream, handler): print >> stream, "class %s(Structure):" % self.name ! print >> stream, " _fields_ = [" for m in self.members: try: --- 145,155 ---- self.members = attrs["members"].split() ! def dump_1(self, stream, handler): print >> stream, "class %s(Structure):" % self.name ! print >> stream, " pass" ! print >> stream ! ! def dump_2(self, stream, handler): ! print >> stream, "%s._fields_ = [" % self.name for m in self.members: try: *************** *** 154,159 **** pass else: ! print >> stream, " (%s, %s)," % (field.name, field.type) ! print >> stream, " ]" print >> stream --- 158,163 ---- pass else: ! print >> stream, " (%s, %s)," % (field.name, field.type) ! print >> stream, "]" print >> stream *************** *** 171,174 **** --- 175,217 ---- ################ + ctypes_names = { + "short int": "c_short", + "int": "c_int", + "long int": "c_long", + "long long int": "c_longlong", + + "short unsigned int": "c_ushort", + "unsigned int": "c_uint", + "long unsigned int": "c_ulong", + "long long unsigned int": "c_ulonglong", + + "float": "c_float", + "double": "c_double", + + "char": "c_char", + "signed char": "c_byte", + "unsigned char": "c_ubyte", + "wchar_t": "c_wchar", + "void": "void", # ? + } + + class FundamentalType(object): + def __init__(self, name): + self.name = ctypes_names[name] + + class PointerType(object): + # id, type + type = None + def __init__(self, attrs): + self.attrs = attrs + + def resolve(self): + if self.type is None: + return + self.type = find_type([self.attrs["type"]]) + self.type.resolve() + + ################ + class Enum_Handler(GCCXML_Handler_Base): has_values = Set() *************** *** 192,196 **** def Union(self, attrs): - print "UNION", attrs["name"] self.Struct(attrs) --- 235,238 ---- *************** *** 203,209 **** --- 245,253 ---- def FundamentalType(self, attrs): + f = FundamentalType(attrs["name"]) self.types[attrs["id"]] = attrs["name"] def PointerType(self, attrs): + # id, type self.types[attrs["id"]] = "POINTER" *************** *** 257,260 **** --- 301,306 ---- os.remove(xml_file) + sys.exit() + if py_file is None: return 0 *************** *** 265,272 **** for struct in handler.structs.values(): ! struct.dump(ofi, handler) return 0 if __name__ == "__main__": sys.exit(main()) --- 311,326 ---- for struct in handler.structs.values(): ! struct.dump_1(ofi, handler) ! ! ## for struct in handler.structs.values(): ! ## struct.dump_2(ofi, handler) ! ! ## for id in handler.structs.keys(): ! ## print handler.types[id] return 0 if __name__ == "__main__": + if len(sys.argv) == 1: + sys.argv.extend("-D NONAMELESSUNION -D _WIN32_WINNT=0x500 -c msvc71 -o- test.h".split()) sys.exit(main()) |