ctypes-commit Mailing List for ctypes (Page 37)
Brought to you by:
theller
You can subscribe to this list here.
2004 |
Jan
|
Feb
|
Mar
|
Apr
(8) |
May
(90) |
Jun
(143) |
Jul
(106) |
Aug
(94) |
Sep
(84) |
Oct
(163) |
Nov
(60) |
Dec
(58) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2005 |
Jan
(128) |
Feb
(79) |
Mar
(227) |
Apr
(192) |
May
(179) |
Jun
(41) |
Jul
(53) |
Aug
(103) |
Sep
(28) |
Oct
(38) |
Nov
(81) |
Dec
(17) |
2006 |
Jan
(184) |
Feb
(111) |
Mar
(188) |
Apr
(67) |
May
(58) |
Jun
(123) |
Jul
(73) |
Aug
|
Sep
|
Oct
(1) |
Nov
|
Dec
|
From: Thomas H. <th...@us...> - 2005-11-03 07:33:58
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23136 Modified Files: Tag: branch_1_0 callbacks.c Log Message: For callback functions with result type None ('void'), actually ignore the return value. Add some assert statements for easier debugging. Index: callbacks.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/callbacks.c,v retrieving revision 1.71.2.5 retrieving revision 1.71.2.6 diff -C2 -d -r1.71.2.5 -r1.71.2.6 *** callbacks.c 18 Oct 2005 19:18:28 -0000 1.71.2.5 --- callbacks.c 3 Nov 2005 07:33:51 -0000 1.71.2.6 *************** *** 200,204 **** result = PyObject_CallObject(callable, arglist); CHECK("'calling callback function'", result); ! if (result && result != Py_None) { /* XXX What is returned for Py_None ? */ /* another big endian hack */ union { --- 200,205 ---- result = PyObject_CallObject(callable, arglist); CHECK("'calling callback function'", result); ! if ((restype != &ffi_type_void) ! && result && result != Py_None) { /* XXX What is returned for Py_None ? */ /* another big endian hack */ union { *************** *** 209,212 **** --- 210,214 ---- } r; PyObject *keep; + assert(setfunc); switch (restype->size) { case 1: *************** *** 310,322 **** p->atypes[i] = NULL; ! { StgDictObject *dict = PyType_stgdict(restype); ! if (dict) { ! p->setfunc = dict->setfunc; ! p->restype = &dict->ffi_type; ! } else { ! p->setfunc = getentry("i")->setfunc; ! p->restype = &ffi_type_sint; } } --- 312,326 ---- p->atypes[i] = NULL; ! if (restype == Py_None) { ! p->setfunc = NULL; ! p->restype = &ffi_type_void; ! } else { StgDictObject *dict = PyType_stgdict(restype); ! if (dict == NULL) { ! PyMem_Free(p); ! return NULL; } + p->setfunc = dict->setfunc; + p->restype = &dict->ffi_type; } |
From: Thomas H. <th...@us...> - 2005-11-03 07:31:38
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22841 Modified Files: Tag: branch_1_0 _ctypes.c Log Message: Enable cycle GC on CFuncPtrType objects (does not seem to have a visible effect). Fix quite some refcount leaks, and a crash when outargs is NULL. Add some asserts for easier debugging. Index: _ctypes.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes.c,v retrieving revision 1.226.2.32 retrieving revision 1.226.2.33 diff -C2 -d -r1.226.2.32 -r1.226.2.33 *** _ctypes.c 28 Oct 2005 17:55:58 -0000 1.226.2.32 --- _ctypes.c 3 Nov 2005 07:31:28 -0000 1.226.2.33 *************** *** 550,555 **** since we are a metatype!) */ result = (PyTypeObject *)PyType_Type.tp_new(type, args, kwds); ! if (result == NULL) return NULL; /* replace the class dict by our updated spam dict */ --- 550,557 ---- since we are a metatype!) */ result = (PyTypeObject *)PyType_Type.tp_new(type, args, kwds); ! if (result == NULL) { ! Py_DECREF((PyObject *)stgdict); return NULL; + } /* replace the class dict by our updated spam dict */ *************** *** 1269,1272 **** --- 1271,1281 ---- stgdict->setfunc = fmt->setfunc; stgdict->getfunc = fmt->getfunc; + /* + if (result->tp_base != &Simple_Type) { + stgdict->setfunc = NULL; + stgdict->getfunc = NULL; + } + */ + /* This consumes the refcount on proto which we have */ stgdict->proto = proto; *************** *** 1615,1622 **** 0, /* tp_setattro */ 0, /* tp_as_buffer */ ! Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ "metatype for C function pointers", /* tp_doc */ ! 0, /* tp_traverse */ ! 0, /* tp_clear */ 0, /* tp_richcompare */ 0, /* tp_weaklistoffset */ --- 1624,1631 ---- 0, /* tp_setattro */ 0, /* tp_as_buffer */ ! Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /* tp_flags */ "metatype for C function pointers", /* tp_doc */ ! (traverseproc)CDataType_traverse, /* tp_traverse */ ! (inquiry)CDataType_clear, /* tp_clear */ 0, /* tp_richcompare */ 0, /* tp_weaklistoffset */ *************** *** 1939,1942 **** --- 1948,1952 ---- return CData_FromBaseObj(type, src, index, adr); } + assert (getfunc); return getfunc(adr, size); } *************** *** 2994,2998 **** Py_DECREF(result); Py_DECREF(callargs); ! Py_DECREF(outargs); return v; } --- 3004,3008 ---- Py_DECREF(result); Py_DECREF(callargs); ! Py_XDECREF(outargs); return v; } *************** *** 3015,3021 **** Py_VISIT(self->argtypes); Py_VISIT(self->converters); - Py_VISIT(self->b_objects); Py_VISIT(self->paramflags); ! return 0; } --- 3025,3030 ---- Py_VISIT(self->argtypes); Py_VISIT(self->converters); Py_VISIT(self->paramflags); ! return CData_traverse((CDataObject *)self, visit, arg); } *************** *** 3029,3033 **** Py_CLEAR(self->argtypes); Py_CLEAR(self->converters); - Py_CLEAR(self->b_objects); Py_CLEAR(self->paramflags); --- 3038,3041 ---- *************** *** 3040,3044 **** self->thunk = NULL; ! return 0; } --- 3048,3052 ---- self->thunk = NULL; ! return CData_clear((CDataObject *)self); } *************** *** 3186,3189 **** --- 3194,3198 ---- name = PySequence_GetItem(pair, 0); if (!name) { + Py_DECREF(pair); Py_DECREF(fields); return IBUG("_fields_[i][0] failed"); *************** *** 3192,3195 **** --- 3201,3206 ---- val = PyTuple_GET_ITEM(args, i); if (-1 == PyObject_SetAttr(self, name, val)) { + Py_DECREF(pair); + Py_DECREF(name); Py_DECREF(fields); return -1; *************** *** 3608,3611 **** --- 3619,3623 ---- StgDictObject *dict = PyObject_stgdict((PyObject *)self); + assert(dict->setfunc); result = dict->setfunc(self->b_ptr, value, dict->size); if (!result) *************** *** 3631,3634 **** --- 3643,3647 ---- { StgDictObject *dict = PyObject_stgdict((PyObject *)self); + assert(dict->getfunc); return dict->getfunc(self->b_ptr, self->b_size); } |
From: Thomas H. <th...@us...> - 2005-11-03 07:25:08
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21671 Modified Files: Tag: branch_1_0 stgdict.c Log Message: Fixed a very nasty bug: The dict portion of StgDict objects were never freed. Assigning a non-sequence to a Structure _fields_ raises TypeError, not AttributeError. Fix another refcount leak. Index: stgdict.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/stgdict.c,v retrieving revision 1.32.2.1 retrieving revision 1.32.2.2 diff -C2 -d -r1.32.2.1 -r1.32.2.2 *** stgdict.c 17 Aug 2005 15:54:24 -0000 1.32.2.1 --- stgdict.c 3 Nov 2005 07:24:55 -0000 1.32.2.2 *************** *** 40,44 **** StgDict_clear(self); PyMem_Free(self->ffi_type.elements); ! ((PyObject *)self)->ob_type->tp_free((PyObject *)self); } --- 40,44 ---- StgDict_clear(self); PyMem_Free(self->ffi_type.elements); ! PyDict_Type.tp_dealloc((PyObject *)self); } *************** *** 210,214 **** len = PySequence_Length(fields); if (len == -1) { ! PyErr_SetString(PyExc_AttributeError, "'_fields_' must be a sequence of pairs"); return -1; --- 210,214 ---- len = PySequence_Length(fields); if (len == -1) { ! PyErr_SetString(PyExc_TypeError, "'_fields_' must be a sequence of pairs"); return -1; *************** *** 223,226 **** --- 223,228 ---- return -1; } + /* XXX This should probably be moved to a point when all this + stuff is sucessfully finished. */ stgdict->flags |= DICTFLAG_FINAL; /* set final */ *************** *** 268,271 **** --- 270,274 ---- dict = PyType_stgdict(desc); if (dict == NULL) { + Py_DECREF(pair); PyErr_Format(PyExc_TypeError, "second item in _fields_ tuple (index %d) must be a C type", |
From: Thomas H. <th...@us...> - 2005-10-28 18:11:35
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27826 Modified Files: Tag: branch_1_0 setup.py Log Message: Remove comtypes from the list of packages to test. Index: setup.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/setup.py,v retrieving revision 1.122.2.4 retrieving revision 1.122.2.5 diff -C2 -d -r1.122.2.4 -r1.122.2.5 *** setup.py 28 Oct 2005 18:09:26 -0000 1.122.2.4 --- setup.py 28 Oct 2005 18:11:23 -0000 1.122.2.5 *************** *** 61,68 **** self.verbosity = 1 if sys.platform == "win32": ! if os.path.isdir(r"comtypes\unittests"): ! self.test_dirs = r"unittests,unittests\com,comtypes\unittests" ! else: ! self.test_dirs = r"unittests,unittests\com" else: self.test_dirs = "unittests" --- 61,65 ---- self.verbosity = 1 if sys.platform == "win32": ! self.test_dirs = r"unittests,unittests\com" else: self.test_dirs = "unittests" |
From: Thomas H. <th...@us...> - 2005-10-28 18:10:28
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27484 Modified Files: Tag: branch_1_0 ChangeLog Log Message: Index: ChangeLog =================================================================== RCS file: /cvsroot/ctypes/ctypes/ChangeLog,v retrieving revision 1.86.2.25 retrieving revision 1.86.2.26 diff -C2 -d -r1.86.2.25 -r1.86.2.26 *** ChangeLog 21 Oct 2005 18:19:52 -0000 1.86.2.25 --- ChangeLog 28 Oct 2005 18:10:18 -0000 1.86.2.26 *************** *** 1,2 **** --- 1,15 ---- + 2005-10-28 Thomas Heller <th...@py...> + + * setup.py: ctypes.macholib was missing in the packages list. + + * source\cfield.c: Fix a refcount leak when unicode is converted + to ascii. + + * source\_ctypes.c: Fix a refcount leak. And finally correct the + wrong static declaration of Pointer_Type, preventing compilation + with gcc4 (which I don't have). + + * source\callproc.c: Fix a refcount leak when COMError is raised. + 2005-10-21 Thomas Heller <th...@py...> |
From: Thomas H. <th...@us...> - 2005-10-28 18:09:34
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27246 Modified Files: Tag: branch_1_0 setup.py Log Message: ctypes.macholib was missing from the packages list. Index: setup.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/setup.py,v retrieving revision 1.122.2.3 retrieving revision 1.122.2.4 diff -C2 -d -r1.122.2.3 -r1.122.2.4 *** setup.py 29 Sep 2005 12:37:20 -0000 1.122.2.3 --- setup.py 28 Oct 2005 18:09:26 -0000 1.122.2.4 *************** *** 420,424 **** # the ctypes package # ! packages = ["ctypes", "ctypes.wrap"] package_dir = {} --- 420,424 ---- # the ctypes package # ! packages = ["ctypes", "ctypes.wrap", "ctypes.macholib"] package_dir = {} |
From: Thomas H. <th...@us...> - 2005-10-28 17:57:16
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23644 Modified Files: Tag: branch_1_0 cfield.c Log Message: Fix a refcount leak when a unicode is converted to ascii. Index: cfield.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/cfield.c,v retrieving revision 1.74.2.1 retrieving revision 1.74.2.2 diff -C2 -d -r1.74.2.1 -r1.74.2.2 *** cfield.c 17 Aug 2005 15:54:24 -0000 1.74.2.1 --- cfield.c 28 Oct 2005 17:57:07 -0000 1.74.2.2 *************** *** 928,932 **** return NULL; *(char **)ptr = PyString_AS_STRING(str); - Py_INCREF(str); return str; } else if (PyInt_Check(value) || PyLong_Check(value)) { --- 928,931 ---- |
From: Thomas H. <th...@us...> - 2005-10-28 17:56:46
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23524 Modified Files: Tag: branch_1_0 callproc.c Log Message: Fix a refcount leak when a COMError is raised. Index: callproc.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/callproc.c,v retrieving revision 1.127.2.14 retrieving revision 1.127.2.15 diff -C2 -d -r1.127.2.14 -r1.127.2.15 *** callproc.c 30 Sep 2005 10:09:32 -0000 1.127.2.14 --- callproc.c 28 Oct 2005 17:56:37 -0000 1.127.2.15 *************** *** 783,786 **** --- 783,787 ---- char *text; LPOLESTR progid; + PyObject *obj; hr = pIunk->lpVtbl->QueryInterface(pIunk, &IID_ISupportErrorInfo, (void **)&psei); *************** *** 812,821 **** /* XXX Is COMError derived from WindowsError or not? */ text = FormatError(errcode); ! PyErr_SetObject(ComError, ! Py_BuildValue("is(uuuiu)", ! errcode, ! FormatError(errcode), ! descr, source, helpfile, helpcontext, ! progid)); LocalFree(text); --- 813,825 ---- /* XXX Is COMError derived from WindowsError or not? */ text = FormatError(errcode); ! obj = Py_BuildValue("is(uuuiu)", ! errcode, ! FormatError(errcode), ! descr, source, helpfile, helpcontext, ! progid); ! if (obj) { ! PyErr_SetObject(ComError, obj); ! Py_DECREF(obj); ! } LocalFree(text); |
From: Thomas H. <th...@us...> - 2005-10-28 17:56:08
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23371 Modified Files: Tag: branch_1_0 _ctypes.c Log Message: Fix a refcount leak. And finally fix the wrong static declaration of Pointer_Type, which prevents building with gcc4 (that I don't have). Index: _ctypes.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes.c,v retrieving revision 1.226.2.31 retrieving revision 1.226.2.32 diff -C2 -d -r1.226.2.31 -r1.226.2.32 *** _ctypes.c 18 Oct 2005 07:36:01 -0000 1.226.2.31 --- _ctypes.c 28 Oct 2005 17:55:58 -0000 1.226.2.32 *************** *** 2994,2997 **** --- 2994,2998 ---- Py_DECREF(result); Py_DECREF(callargs); + Py_DECREF(outargs); return v; } *************** *** 3990,3994 **** }; ! static PyTypeObject Pointer_Type = { PyObject_HEAD_INIT(NULL) 0, --- 3991,3995 ---- }; ! PyTypeObject Pointer_Type = { PyObject_HEAD_INIT(NULL) 0, |
From: Thomas H. <th...@us...> - 2005-10-21 18:20:00
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22558 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.24 retrieving revision 1.86.2.25 diff -C2 -d -r1.86.2.24 -r1.86.2.25 *** ChangeLog 18 Oct 2005 19:49:21 -0000 1.86.2.24 --- ChangeLog 21 Oct 2005 18:19:52 -0000 1.86.2.25 *************** *** 1,2 **** --- 1,15 ---- + 2005-10-21 Thomas Heller <th...@py...> + + * ctypes\wrap\codegenerator.py: The codegenerator now by default + assumes 'char *' and 'wchar_t *' types are pointers to + zero-terminated strings. It generates + + STRING = c_char_p + WSTRING = c_wchar_p + + and STRING / WSTRING is used instead of POINTER(c_char) and + POINTER(c_wchar). This behaviour can be changed by setting the + global variable ASSUME_STRINGS to False. + 2005-10-18 Thomas Heller <th...@py...> |
From: Thomas H. <th...@us...> - 2005-10-21 18:18:08
|
Update of /cvsroot/ctypes/ctypes/ctypes/wrap In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22074 Modified Files: Tag: branch_1_0 codegenerator.py Log Message: The codegenerator now by default assumes 'char *' and 'wchar_t *' types are pointers to zero-terminated strings. It generates STRING = c_char_p WSTRING = c_wchar_p and STRING / WSTRING is used instead of POINTER(c_char) and POINTER(c_wchar). Index: codegenerator.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/wrap/codegenerator.py,v retrieving revision 1.6.2.4 retrieving revision 1.6.2.5 diff -C2 -d -r1.6.2.4 -r1.6.2.5 *** codegenerator.py 24 Aug 2005 08:16:35 -0000 1.6.2.4 --- codegenerator.py 21 Oct 2005 18:18:00 -0000 1.6.2.5 *************** *** 3,6 **** --- 3,16 ---- # $Log$ + # Revision 1.6.2.5 2005/10/21 18:18:00 theller + # The codegenerator now by default assumes 'char *' and 'wchar_t *' + # types are pointers to zero-terminated strings. It generates + # + # STRING = c_char_p + # WSTRING = c_wchar_p + # + # and STRING / WSTRING is used instead of POINTER(c_char) and + # POINTER(c_wchar). + # # Revision 1.6.2.4 2005/08/24 08:16:35 theller # Merged in changes from the CVS HEAD: *************** *** 55,58 **** --- 65,70 ---- import typedesc, sys, types + ASSUME_STRINGS = True + try: set *************** *** 182,185 **** --- 194,199 ---- if type(tp) is typedesc.Typedef: return get_real_type(tp.typ) + elif isinstance(tp, typedesc.CvQualifiedType): + return get_real_type(tp.typ) return tp *************** *** 254,260 **** def type_name(self, t, generate=True): ! # Return a string, containing an expression which can be used to ! # refer to the type. Assumes the * namespace is available. if isinstance(t, typedesc.PointerType): result = "POINTER(%s)" % self.type_name(t.typ, generate) # XXX Better to inspect t.typ! --- 268,287 ---- def type_name(self, t, generate=True): ! # Return a string containing an expression that can be used to ! # refer to the type. Assumes the 'from ctypes import *' ! # namespace is available. ! if isinstance(t, typedesc.Typedef): ! return t.name if isinstance(t, typedesc.PointerType): + if ASSUME_STRINGS: + x = get_real_type(t.typ) + if isinstance(x, typedesc.FundamentalType): + if x.name == "char": + self.need_STRING() + return "STRING" + elif x.name == "wchar_t": + self.need_WSTRING() + return "WSTRING" + result = "POINTER(%s)" % self.type_name(t.typ, generate) # XXX Better to inspect t.typ! *************** *** 597,600 **** --- 624,641 ---- return name + _STRING_defined = False + def need_STRING(self): + if self._STRING_defined: + return + print >> self.imports, "STRING = c_char_p" + self._STRING_defined = True + + _WSTRING_defined = False + def need_WSTRING(self): + if self._WSTRING_defined: + return + print >> self.imports, "WSTRING = c_wchar_p" + self._WSTRING_defined = True + _STDMETHOD_defined = False def need_STDMETHOD(self): |
From: Thomas H. <th...@us...> - 2005-10-20 17:27:49
|
Update of /cvsroot/ctypes/ctypes/comtypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv314 Modified Files: Tag: branch_1_0 ChangeLog Log Message: Index: ChangeLog =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/Attic/ChangeLog,v retrieving revision 1.1.2.4 retrieving revision 1.1.2.5 diff -C2 -d -r1.1.2.4 -r1.1.2.5 *** ChangeLog 11 Oct 2005 13:11:27 -0000 1.1.2.4 --- ChangeLog 20 Oct 2005 17:27:42 -0000 1.1.2.5 *************** *** 1,16 **** 2005-10-11 Thomas Heller <th...@py...> ! * client\__init__.py: Renamed CreateModule() into GetModule(). ! Removed the 'modulename' parameter from all the function calls - ! the typelib wrapper alias name is now taken from the typelib ! library name. ! Suggestions from Bruce Dodson. 2005-09-29 Thomas Heller <th...@py...> ! * GUID.py: Rename the GUID.progid() classmethod into GUID.as_progid(). 2005-09-02 Thomas Heller <th...@py...> ! * comtypes/client/__init__.py: Can now receive events from custom, non-dispatch interfaces. --- 1,39 ---- + 2005-10-20 Thomas Heller <th...@py...> + + * comtypes\__init__.py: Add logging for easier debugging. Add + COINIT_... flags. Use the value of sys.coinit_flags (when + defined) in the call to CoInitializeEx, this allows to use + multithreaded appartments. + + Clean up the lifetime management of implemented COM objects. Make + COM attribute access case insensitive (has a large impact on the + performance, unfortunately). + + Move the COMObject definition in a separate module + comtypes\_comobject.py. + + * comtypes\tools\codegenerator.py: Don't generate dispid() for + non-dispatch based interfaces. + + * comtypes\client\__init__.py: Add logging for easier debugging. + + * comtypes\persist.py: Remove dispid() from non-dispatch based + interfaces. Correct the Read method. Hack around the + POINTER(c_wchar) <-> c_wchar_p problem. + 2005-10-11 Thomas Heller <th...@py...> ! * comtypes\client\__init__.py: Renamed CreateModule() into ! GetModule(). Removed the 'modulename' parameter from all the ! function calls - the typelib wrapper alias name is now taken from ! the typelib library name. Suggestions from Bruce Dodson. 2005-09-29 Thomas Heller <th...@py...> ! * comtypes\GUID.py: Rename the GUID.progid() classmethod into ! GUID.as_progid(). 2005-09-02 Thomas Heller <th...@py...> ! * comtypes\client\__init__.py: Can now receive events from custom, non-dispatch interfaces. |
From: Thomas H. <th...@us...> - 2005-10-20 17:25:38
|
Update of /cvsroot/ctypes/ctypes/comtypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32238 Modified Files: Tag: branch_1_0 test_ie.py Log Message: Fix broken syntax. Index: test_ie.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/unittests/Attic/test_ie.py,v retrieving revision 1.1.2.6 retrieving revision 1.1.2.7 diff -C2 -d -r1.1.2.6 -r1.1.2.7 *** test_ie.py 11 Oct 2005 13:09:59 -0000 1.1.2.6 --- test_ie.py 20 Oct 2005 17:25:29 -0000 1.1.2.7 *************** *** 65,70 **** def test_default_eventinterface(self): sink = EventSink() ! ie = CreateObject("InternetExplorer.Application") ! sink=sink) ie.Visible = True ie.Navigate2(URL="http://www.python.org/", Flags=0) --- 65,69 ---- def test_default_eventinterface(self): sink = EventSink() ! ie = CreateObject("InternetExplorer.Application", sink=sink) ie.Visible = True ie.Navigate2(URL="http://www.python.org/", Flags=0) |
From: Thomas H. <th...@us...> - 2005-10-20 17:25:01
|
Update of /cvsroot/ctypes/ctypes/comtypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32117 Modified Files: Tag: branch_1_0 __init__.py Log Message: Cleanup. Index: __init__.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/__init__.py,v retrieving revision 1.25.2.33 retrieving revision 1.25.2.34 diff -C2 -d -r1.25.2.33 -r1.25.2.34 *** __init__.py 20 Oct 2005 17:21:57 -0000 1.25.2.33 --- __init__.py 20 Oct 2005 17:24:53 -0000 1.25.2.34 *************** *** 851,898 **** ################################################################ - - if __name__ == "__main__": - import logging - logging.basicConfig(level=logging.DEBUG) - # a helper function. Not sure if it is needed, except for testing. - - def _get_interface(comobj, interface): - # return a com interface pointer from a ComObj instance. - p = POINTER(interface)() - # It would be nice if the object return by byref() would have a - # __getitem__ method so that __getitem__(0) returned the contained - hr = comobj.IUnknown_QueryInterface(None, - pointer(interface._iid_), - byref(p)) - if hr < 0: - raise WinError(hr) - return p - - from comtypes.persist import IPersistPropertyBag2, IPersist, IPersistPropertyBag - class MyObj(COMObject): - _com_interfaces_ = [IUnknown, IPersistPropertyBag2, IPersistPropertyBag] - - ## try: - ## _get_interface(POINTER(MyObj)(), IUnknown) - ## except AttributeError: - ## pass - ## else: - ## raise RuntimeError, "this should have failed" - - ptr = _get_interface(MyObj(), IUnknown) - - ## print ptr.AddRef(), ptr.Release() - ## print ptr.QueryInterface(IUnknown) - ## print ptr.QueryInterface(IPersist) - ## print ptr.QueryInterface(IPersistPropertyBag2) - ## try: - ## print ptr.QueryInterface(IPersistPropertyBag) - ## except COMError, detail: - ## if detail.hresult != E_NOINTERFACE: - ## raise - ## # clean the traceback - ## sys.exc_clear() - - ## del ptr - - print COMObject._instances_ --- 851,852 ---- |
From: Thomas H. <th...@us...> - 2005-10-20 17:23:18
|
Update of /cvsroot/ctypes/ctypes/comtypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31821 Added Files: Tag: branch_1_0 _comobject.py Log Message: Move the COMObject definition in a separate module comtypes\_comobject.py. --- NEW FILE: _comobject.py --- from ctypes import * from comtypes.hresult import * import logging ################################################################ # COM object implementation from _ctypes import CopyComPointer def _not_impl(*args): return -2147467263 # E_NOTIMPL, 0x80004001L def prepare_comobject(inst): # When a CoClass instance is created, COM pointers to all # interfaces are created. Also, the CoClass must be kept alive as # until the COM reference count drops to zero, even if no Python # code keeps a reference to the object. # # The _com_pointers_ instance variable maps string interface iids # to C compatible COM pointers. inst._com_pointers_ = {} # COM refcount starts at zero. inst._refcnt = c_long(0) for itf in inst._com_interfaces_[::-1]: make_interface_pointer(inst, itf) def make_interface_pointer(inst, itf, _debug=logging.getLogger("comtypes.impl").debug): methods = [] # method implementations fields = [] # (name, prototype) for virtual function table iids = [] # hashcode for interface identifiers. # iterate over interface inheritance in reverse order to build the # virtual function table, and leave out the 'object' base class. for interface in itf.__mro__[-2::-1]: iids.append(interface._iid_.hashcode()) for m in interface._methods_: restype, mthname, argtypes, paramflags, idlflags, helptext = m proto = WINFUNCTYPE(restype, c_void_p, *argtypes) fields.append((mthname, proto)) # try the simple name, like 'QueryInterface' mth = getattr(inst, mthname, None) if mth is None: # qualified name, like 'IUnknown_QueryInterface' mth = getattr(inst, "%s_%s" % (interface.__name__, mthname), _not_impl) if mth is _not_impl: _debug("%r: %s.%s not implemented", inst, interface.__name__, mthname) methods.append(proto(mth)) class Vtbl(Structure): _fields_ = fields Vtbl.__name__ = "Vtbl_%s" % itf.__name__ vtbl = Vtbl(*methods) for hashcode in iids: inst._com_pointers_[hashcode] = pointer(pointer(vtbl)) ################################################################ _InterlockedIncrement = windll.kernel32.InterlockedIncrement _InterlockedDecrement = windll.kernel32.InterlockedDecrement class COMObject(object): _instances_ = {} _factory = None def __new__(cls, *args, **kw): self = super(COMObject, cls).__new__(cls, *args, **kw) if isinstance(self, c_void_p): # We build the VTables only for direct instances of # CoClass, not for POINTERs to CoClass. return self if hasattr(self, "_com_interfaces_"): prepare_comobject(self) return self ######################################################### # IUnknown methods implementations def IUnknown_AddRef(self, this, _debug=logging.getLogger("comtypes.refcount").debug): result = _InterlockedIncrement(byref(self._refcnt)) if result == 1: # keep reference to the object in a class variable. COMObject._instances_[self] = None _debug("%d active COM objects: Added %r", len(COMObject._instances_), self) _debug("%r.AddRef() -> %s", self, result) return result def IUnknown_Release(self, this, _InterlockedDecrement=_InterlockedDecrement, _byref=byref, _debug=logging.getLogger("comtypes.refcount").debug): # If this is called at COM shutdown, byref() and # _InterlockedDecrement() must still be available, although # module level variables may have been deleted already - so we # supply them as default arguments. result = _InterlockedDecrement(_byref(self._refcnt)) _debug("%r.Release() -> %s", self, result) if result == 0: del COMObject._instances_[self] _debug("%d active COM objects: Removed %r", len(COMObject._instances_), self) if self._factory is not None: self._factory.LockServer(None, 0) return result def IUnknown_QueryInterface(self, this, riid, ppvObj, _debug=logging.getLogger("comtypes.QueryInterface").debug): iid = riid[0] ptr = self._com_pointers_.get(iid.hashcode(), None) if ptr is not None: # CopyComPointer(src, dst) calls AddRef! _debug("%r.QueryInterface(%s) -> S_OK", self, iid) return CopyComPointer(ptr, ppvObj) _debug("%r.QueryInterface(%s) -> E_NOINTERFACE", self, iid) return E_NOINTERFACE __all__ = ["COMObject"] |
From: Thomas H. <th...@us...> - 2005-10-20 17:22:11
|
Update of /cvsroot/ctypes/ctypes/comtypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31604 Modified Files: Tag: branch_1_0 __init__.py Log Message: Add logging for easier debugging. Add COINIT_... flags. Use the value of sys.coinit_flags (when defined) in the call to CoInitializeEx, this allows to use multithreaded appartments. Clean up the lifetime management of implemented COM objects. Make COM attribute access case insensitive (has a large impact on the performance, unfortunately). Move the COMObject definition in a separate module comtypes\_comobject.py. Index: __init__.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/__init__.py,v retrieving revision 1.25.2.32 retrieving revision 1.25.2.33 diff -C2 -d -r1.25.2.32 -r1.25.2.33 *** __init__.py 11 Oct 2005 12:33:01 -0000 1.25.2.32 --- __init__.py 20 Oct 2005 17:21:57 -0000 1.25.2.33 *************** *** 11,14 **** --- 11,18 ---- from _ctypes import COMError + import logging + logger = logging.getLogger("comtypes") + + ##class IDLWarning(UserWarning): ## "Warn about questionable type information" *************** *** 63,67 **** _ole32 = oledll.ole32 ! _ole32.CoInitialize(None) class _Cleaner(object): --- 67,76 ---- _ole32 = oledll.ole32 ! COINIT_MULTITHREADED = 0x0 ! COINIT_APARTMENTTHREADED = 0x2 ! COINIT_DISABLE_OLE1DDE = 0x4 ! COINIT_SPEED_OVER_MEMORY = 0x8 ! ! _ole32.CoInitializeEx(None, getattr(sys, "coinit_flags", COINIT_APARTMENTTHREADED)) class _Cleaner(object): *************** *** 106,109 **** --- 115,120 ---- dispmethods = namespace.pop("_disp_methods_", None) cls = type.__new__(self, name, bases, namespace) + cls.__map_case__ = {} + if methods is not None: cls._methods_ = methods *************** *** 142,156 **** return value # Accept an CoClass instance which exposes the interface required. - # Again, more checks probably needed... - # Although the CoClass has a QueryInterface method, this method - # has a different signature. try: ! mth = value.IUnknown_QueryInterface except AttributeError: pass else: ! ptr = POINTER(klass)() ! if 0 == mth(None, pointer(klass._iid_), byref(ptr)): ! return ptr return value.QueryInterface(cls) --- 153,166 ---- return value # Accept an CoClass instance which exposes the interface required. try: ! table = getattr(value, "_com_pointers_") except AttributeError: pass else: ! try: ! # a kind of QueryInterface ! return table[str(klass._iid_)] ! except KeyError: ! raise TypeError("Interface %s not supported" % klass._iid_) return value.QueryInterface(cls) *************** *** 180,183 **** --- 190,198 ---- for m in methods: what, name, idlflags, restype, argspec = m + + ## XXX Must be tested + ## # COM is case insensitive + ## self.__map_case__[name.lower()] = name + # argspec is a sequence of tuples, each tuple is: # ([paramflags], type, name) *************** *** 343,346 **** --- 358,364 ---- else: setattr(self, name, mth) + # COM is case insensitive + self.__map_case__[name.lower()] = name + # create public properties / attribute accessors *************** *** 359,362 **** --- 377,383 ---- else: setattr(self, name, prop) + # COM is case insensitive + self.__map_case__[name.lower()] = name + ################################################################ *************** *** 410,418 **** self.Release() - # Hm, shouldn't this be in c_void_p ? - def __nonzero__(self): - # get the .value property of the baseclass, this is the pointer value - return bool(super(_compointer_base, self).value) - def __cmp__(self, other): # COM identity rule --- 431,434 ---- *************** *** 443,446 **** --- 459,484 ---- return "<%s instance at %x>" % (self.__class__.__name__, id(self)) + # case insensitive attributes for COM methods and properties + def __getattr__(self, name): + try: + name = self.__map_case__[name.lower()] + except KeyError: + raise AttributeError(name) + else: + return getattr(self, name) + + # XXX __setattr__ is pretty heavy-weight, because it is called for + # EVERY attribute assignment. Settings a non-com attribute + # through this function takes 8.6 usec, while without this + # function it takes 0.7 sec - 12 times slower. Maybe there should + # be a way to enable this method only for code that needs it + # (i.e., generated from a typelib)? + # + # Maybe triggered by a special attribute __case_insensitive__ ? + def __setattr__(self, name, value): + object.__setattr__(self, + self.__map_case__.get(name.lower(), name), + value) + ################################################################ *************** *** 622,626 **** raise TypeError, "len() of unsized object" ! # calling a COM pointer calls it's .Item property, if that is present. def __call__(self, *args, **kw): try: --- 660,664 ---- raise TypeError, "len() of unsized object" ! # calling a COM pointer calls its .Item property, if that is present. def __call__(self, *args, **kw): try: *************** *** 658,663 **** # Sometimes, however, it is a method. enum = enum() ! # _NewEnum returns an IUnknown pointer, ! # QueryInterface() it to IEnumVARIANT from comtypes.automation import IEnumVARIANT result = enum.QueryInterface(IEnumVARIANT) --- 696,701 ---- # Sometimes, however, it is a method. enum = enum() ! # _NewEnum returns an IUnknown pointer, QueryInterface() it to ! # IEnumVARIANT from comtypes.automation import IEnumVARIANT result = enum.QueryInterface(IEnumVARIANT) *************** *** 803,910 **** return cast(multiqi.pItf, POINTER(interface)) - ################################################################ ! # COM object implementation ! from _ctypes import CopyComPointer ! ! def _not_impl(*args): ! return -2147467263 # E_NOTIMPL, 0x80004001L ! ! def prepare_comobject(inst): ! # When a CoClass instance is created, COM pointers to all ! # interfaces are created. Also, the CoClass must be kept alive as ! # until the COM reference count drops to zero, even if no Python ! # code keeps a reference to the object. ! # ! # The _com_pointers_ instance variable maps string interface iids ! # to C compatible COM pointers. ! inst._com_pointers_ = {} ! # COM refcount starts at zero. ! inst._refcnt = c_long(0) ! for itf in inst._com_interfaces_[::-1]: ! make_interface_pointer(inst, itf) ! # keep reference to the object in a class variable. ! inst._instances_[inst] = None ! ! def make_interface_pointer(inst, itf): ! methods = [] # method implementations ! fields = [] # (name, prototype) for virtual function table ! iids = [] # hashcode for interface identifiers. ! # iterate over interface inheritance in reverse order to build the ! # virtual function table, and leave out the 'object' base class. ! for interface in itf.__mro__[-2::-1]: ! iids.append(interface._iid_.hashcode()) ! for m in interface._methods_: ! restype, mthname, argtypes, paramflags, idlflags, helptext = m ! proto = WINFUNCTYPE(restype, c_void_p, *argtypes) ! fields.append((mthname, proto)) ! # try the simple name, like 'QueryInterface' ! mth = getattr(inst, mthname, None) ! if mth is None: ! # qualified name, like 'IUnknown_QueryInterface' ! mth = getattr(inst, "%s_%s" % (interface.__name__, mthname), _not_impl) ! ## if mth is _not_impl: ! ## print "# Method %s.%s not implemented" % (interface.__name__, mthname) ! methods.append(proto(mth)) ! class Vtbl(Structure): ! _fields_ = fields ! Vtbl.__name__ = "Vtbl_%s" % itf.__name__ ! vtbl = Vtbl(*methods) ! for hashcode in iids: ! inst._com_pointers_[hashcode] = pointer(pointer(vtbl)) ! ! ################################################################ ! ! ##import logging ! ##logger = logging.getLogger("comtypes.server.object") ! ! _InterlockedIncrement = windll.kernel32.InterlockedIncrement ! _InterlockedDecrement = windll.kernel32.InterlockedDecrement ! ! class COMObject(object): ! _instances_ = {} ! _factory = None ! ! def __new__(cls, *args, **kw): ! self = super(COMObject, cls).__new__(cls, *args, **kw) ! if isinstance(self, c_void_p): ! # We build the VTables only for direct instances of ! # CoClass, not for POINTERs to CoClass. ! return self ! if hasattr(self, "_com_interfaces_"): ! prepare_comobject(self) ! return self ! ! ######################################################### ! # IUnknown methods implementations ! def IUnknown_AddRef(self, this): ! return _InterlockedIncrement(byref(self._refcnt)) ! ! def IUnknown_Release(self, this, ! _InterlockedDecrement=_InterlockedDecrement, ! _byref=byref): ! # If this is called at COM shutdown, byref() and ! # _InterlockedDecrement() must still be available, although ! # module level variables may have been deleted already - so we ! # supply them as default arguments. ! result = _InterlockedDecrement(_byref(self._refcnt)) ! if result == 0: ! self._com_pointers_.clear() ! del self._instances_[self] ! if self._factory is not None: ! self._factory.LockServer(None, 0) ! return result ! ! def IUnknown_QueryInterface(self, this, riid, ppvObj): ! iid = riid[0] ! ptr = self._com_pointers_.get(iid.hashcode(), None) ! if ptr is not None: ! # CopyComPointer(src, dst) calls AddRef! ! ## logger.debug("%r.QueryInterface(%s) -> S_OK", self, iid) ! return CopyComPointer(ptr, ppvObj) ! ## logger.debug("%r.QueryInterface(%s) -> E_NOINTERFACE", self, iid) ! return E_NOINTERFACE - ################################################################ # What's a coclass? # a POINTER to a coclass is allowed as parameter in a function declaration: --- 841,847 ---- return cast(multiqi.pItf, POINTER(interface)) ################################################################ ! from comtypes._comobject import COMObject # What's a coclass? # a POINTER to a coclass is allowed as parameter in a function declaration: *************** *** 915,919 **** ################################################################ ! if 0 and __name__ == "__main__": # a helper function. Not sure if it is needed, except for testing. --- 852,858 ---- ################################################################ ! if __name__ == "__main__": ! import logging ! logging.basicConfig(level=logging.DEBUG) # a helper function. Not sure if it is needed, except for testing. *************** *** 943,957 **** ptr = _get_interface(MyObj(), IUnknown) ! print ptr.AddRef(), ptr.Release() ! print ptr.QueryInterface(IUnknown) ! print ptr.QueryInterface(IPersist) ! print ptr.QueryInterface(IPersistPropertyBag2) ! try: ! print ptr.QueryInterface(IPersistPropertyBag) ! except COMError, detail: ! if detail.hresult != E_NOINTERFACE: ! raise ! # clean the traceback ! sys.exc_clear() ! del ptr --- 882,898 ---- ptr = _get_interface(MyObj(), IUnknown) ! ## print ptr.AddRef(), ptr.Release() ! ## print ptr.QueryInterface(IUnknown) ! ## print ptr.QueryInterface(IPersist) ! ## print ptr.QueryInterface(IPersistPropertyBag2) ! ## try: ! ## print ptr.QueryInterface(IPersistPropertyBag) ! ## except COMError, detail: ! ## if detail.hresult != E_NOINTERFACE: ! ## raise ! ## # clean the traceback ! ## sys.exc_clear() ! ## del ptr ! ! print COMObject._instances_ |
From: Thomas H. <th...@us...> - 2005-10-20 17:17:56
|
Update of /cvsroot/ctypes/ctypes/comtypes/tools In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30985 Modified Files: Tag: branch_1_0 codegenerator.py Log Message: Don't generate dispid() for non-dispatch based interfaces. Index: codegenerator.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/tools/codegenerator.py,v retrieving revision 1.6.2.20 retrieving revision 1.6.2.21 diff -C2 -d -r1.6.2.20 -r1.6.2.21 *** codegenerator.py 29 Sep 2005 13:11:22 -0000 1.6.2.20 --- codegenerator.py 20 Oct 2005 17:17:48 -0000 1.6.2.21 *************** *** 257,261 **** for m in body.itf.members: if isinstance(m, typedesc.ComMethod): ! self.make_ComMethod(m) else: raise TypeError, "what's this?" --- 257,261 ---- for m in body.itf.members: if isinstance(m, typedesc.ComMethod): ! self.make_ComMethod(m, "dual" in body.itf.idlflags) else: raise TypeError, "what's this?" *************** *** 308,314 **** # non-toplevel method generators # ! def make_ComMethod(self, m): # typ, name, idlflags, default ! idlflags = [dispid(m.memid)] + m.idlflags if __debug__ and m.doc: idlflags.insert(1, helpstring(m.doc)) --- 308,318 ---- # non-toplevel method generators # ! def make_ComMethod(self, m, isdual): # typ, name, idlflags, default ! if isdual: ! idlflags = [dispid(m.memid)] + m.idlflags ! else: ! # We don't include the dispid for non-dispatch COM interfaces ! idlflags = m.idlflags if __debug__ and m.doc: idlflags.insert(1, helpstring(m.doc)) |
From: Thomas H. <th...@us...> - 2005-10-20 17:16:22
|
Update of /cvsroot/ctypes/ctypes/comtypes/client In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30745 Modified Files: Tag: branch_1_0 __init__.py Log Message: Add logging. Index: __init__.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/client/Attic/__init__.py,v retrieving revision 1.1.2.9 retrieving revision 1.1.2.10 diff -C2 -d -r1.1.2.9 -r1.1.2.10 *** __init__.py 11 Oct 2005 14:08:46 -0000 1.1.2.9 --- __init__.py 20 Oct 2005 17:16:13 -0000 1.1.2.10 *************** *** 27,30 **** --- 27,32 ---- import comtypes.typeinfo + import logging + __all__ = ["CreateObject", "GetActiveObject", "CoGetObject", "GetEvents", "ReleaseEvents", "GetModule"] *************** *** 314,317 **** --- 316,321 ---- # makes sense is to use IProvideClassInfo2 to get the default # source interface. + logger = logging.getLogger("comtypes.events") + if interface is None: # QI for IConnectionPointContainer and thne *************** *** 330,333 **** --- 334,338 ---- guid = pci.GetGUID(1) interface = comtypes.com_interface_registry[str(guid)] + logger.debug("%s using sinkinterface %s", source, interface) if issubclass(interface, comtypes.automation.IDispatch): *************** *** 336,340 **** for memid, name in dispmap.iteritems(): # find methods to call, if not found ignore event ! mth = getattr(sink, "%s.%s" % (interface.__name__, name), None) if mth is None: mth = getattr(sink, name, lambda *args: 0) --- 341,345 ---- for memid, name in dispmap.iteritems(): # find methods to call, if not found ignore event ! mth = getattr(sink, "%s_%s" % (interface.__name__, name), None) if mth is None: mth = getattr(sink, name, lambda *args: 0) *************** *** 368,374 **** --- 373,382 ---- cpc = source.QueryInterface(comtypes.connectionpoints.IConnectionPointContainer) cp = cpc.FindConnectionPoint(ctypes.byref(interface._iid_)) + logger.debug("Start advise %s", interface) cookie = cp.Advise(rcv) def release(ref): + # XXX Do not reference 'source' here! + logger.debug("End advise %s", interface) try: cp.Unadvise(cookie) |
From: Thomas H. <th...@us...> - 2005-10-20 17:13:55
|
Update of /cvsroot/ctypes/ctypes/comtypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30417 Modified Files: Tag: branch_1_0 persist.py Log Message: Remove dispid() from non-dispatch based interfaces. Correct the Read method. Hack around the POINTER(c_wchar) <-> c_wchar_p problem. Index: persist.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/comtypes/Attic/persist.py,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -C2 -d -r1.1.2.2 -r1.1.2.3 *** persist.py 19 Aug 2005 18:51:26 -0000 1.1.2.2 --- persist.py 20 Oct 2005 17:13:42 -0000 1.1.2.3 *************** *** 3,12 **** from comtypes.automation import VARIANT, tagEXCEPINFO class IErrorLog(IUnknown): _iid_ = GUID('{3127CA40-446E-11CE-8135-00AA004BB851}') _idlflags_ = [] _methods_ = [ ! COMMETHOD([dispid(1610678272)], HRESULT, 'AddError', ! ( ['in'], POINTER(c_wchar), 'pszPropName' ), ( ['in'], POINTER(tagEXCEPINFO), 'pExcepInfo' )), ] --- 3,15 ---- from comtypes.automation import VARIANT, tagEXCEPINFO + # XXX Replace by canonical solution!!! + POINTER_c_wchar = c_wchar_p + class IErrorLog(IUnknown): _iid_ = GUID('{3127CA40-446E-11CE-8135-00AA004BB851}') _idlflags_ = [] _methods_ = [ ! COMMETHOD([], HRESULT, 'AddError', ! ( ['in'], POINTER_c_wchar, 'pszPropName' ), ( ['in'], POINTER(tagEXCEPINFO), 'pExcepInfo' )), ] *************** *** 16,20 **** _idlflags_ = [] _methods_ = [ ! COMMETHOD([dispid(1610678272)], HRESULT, 'GetClassID', ( ['out'], POINTER(GUID), 'pClassID' )), ] --- 19,23 ---- _idlflags_ = [] _methods_ = [ ! COMMETHOD([], HRESULT, 'GetClassID', ( ['out'], POINTER(GUID), 'pClassID' )), ] *************** *** 24,35 **** _idlflags_ = [] _methods_ = [ ! COMMETHOD([dispid(1610678272)], HRESULT, 'Read', ! ( ['in'], POINTER(c_wchar), 'pszPropName' ), ( ['out'], POINTER(VARIANT), 'pVar' ), ! ( ['in'], POINTER(IErrorLog), 'pErrorLog' ), ! ( ['in'], c_ulong, 'varType' ), ! ( ['in'], POINTER(IUnknown), 'pUnkObj' )), ! COMMETHOD([dispid(1610678273)], HRESULT, 'Write', ! ( ['in'], POINTER(c_wchar), 'pszPropName' ), ( ['in'], POINTER(VARIANT), 'pVar' )), ] --- 27,36 ---- _idlflags_ = [] _methods_ = [ ! COMMETHOD([], HRESULT, 'Read', ! ( ['in'], POINTER_c_wchar, 'pszPropName' ), ( ['out'], POINTER(VARIANT), 'pVar' ), ! ( ['in'], POINTER(IErrorLog), 'pErrorLog' )), ! COMMETHOD([], HRESULT, 'Write', ! ( ['in'], POINTER_c_wchar, 'pszPropName' ), ( ['in'], POINTER(VARIANT), 'pVar' )), ] *************** *** 39,47 **** _idlflags_ = [] _methods_ = [ ! COMMETHOD([dispid(1610743808)], HRESULT, 'InitNew'), ! COMMETHOD([dispid(1610743809)], HRESULT, 'Load', ( ['in'], POINTER(IPropertyBag), 'pPropBag' ), ( ['in'], POINTER(IErrorLog), 'pErrorLog' )), ! COMMETHOD([dispid(1610743810)], HRESULT, 'Save', ( ['in'], POINTER(IPropertyBag), 'pPropBag' ), ( ['in'], c_int, 'fClearDirty' ), --- 40,48 ---- _idlflags_ = [] _methods_ = [ ! COMMETHOD([], HRESULT, 'InitNew'), ! COMMETHOD([], HRESULT, 'Load', ( ['in'], POINTER(IPropertyBag), 'pPropBag' ), ( ['in'], POINTER(IErrorLog), 'pErrorLog' )), ! COMMETHOD([], HRESULT, 'Save', ( ['in'], POINTER(IPropertyBag), 'pPropBag' ), ( ['in'], c_int, 'fClearDirty' ), *************** *** 66,70 **** ('cfType', CLIPFORMAT), ('dwHint', c_ulong), ! ('pstrName', POINTER(c_wchar)), ('clsid', GUID), ] --- 67,71 ---- ('cfType', CLIPFORMAT), ('dwHint', c_ulong), ! ('pstrName', POINTER_c_wchar), ('clsid', GUID), ] *************** *** 76,80 **** _idlflags_ = [] _methods_ = [ ! COMMETHOD([dispid(1610678272)], HRESULT, 'Read', ( ['in'], c_ulong, 'cProperties' ), ( ['in'], POINTER(tagPROPBAG2), 'pPropBag' ), --- 77,81 ---- _idlflags_ = [] _methods_ = [ ! COMMETHOD([], HRESULT, 'Read', ( ['in'], c_ulong, 'cProperties' ), ( ['in'], POINTER(tagPROPBAG2), 'pPropBag' ), *************** *** 82,98 **** ( ['out'], POINTER(VARIANT), 'pvarValue' ), ( ['out'], POINTER(HRESULT), 'phrError' )), ! COMMETHOD([dispid(1610678273)], HRESULT, 'Write', ( ['in'], c_ulong, 'cProperties' ), ( ['in'], POINTER(tagPROPBAG2), 'pPropBag' ), ( ['in'], POINTER(VARIANT), 'pvarValue' )), ! COMMETHOD([dispid(1610678274)], HRESULT, 'CountProperties', ( ['out'], POINTER(c_ulong), 'pcProperties' )), ! COMMETHOD([dispid(1610678275)], HRESULT, 'GetPropertyInfo', ( ['in'], c_ulong, 'iProperty' ), ( ['in'], c_ulong, 'cProperties' ), ( ['out'], POINTER(tagPROPBAG2), 'pPropBag' ), ( ['out'], POINTER(c_ulong), 'pcProperties' )), ! COMMETHOD([dispid(1610678276)], HRESULT, 'LoadObject', ! ( ['in'], POINTER(c_wchar), 'pstrName' ), ( ['in'], c_ulong, 'dwHint' ), ( ['in'], POINTER(IUnknown), 'punkObject' ), --- 83,99 ---- ( ['out'], POINTER(VARIANT), 'pvarValue' ), ( ['out'], POINTER(HRESULT), 'phrError' )), ! COMMETHOD([], HRESULT, 'Write', ( ['in'], c_ulong, 'cProperties' ), ( ['in'], POINTER(tagPROPBAG2), 'pPropBag' ), ( ['in'], POINTER(VARIANT), 'pvarValue' )), ! COMMETHOD([], HRESULT, 'CountProperties', ( ['out'], POINTER(c_ulong), 'pcProperties' )), ! COMMETHOD([], HRESULT, 'GetPropertyInfo', ( ['in'], c_ulong, 'iProperty' ), ( ['in'], c_ulong, 'cProperties' ), ( ['out'], POINTER(tagPROPBAG2), 'pPropBag' ), ( ['out'], POINTER(c_ulong), 'pcProperties' )), ! COMMETHOD([], HRESULT, 'LoadObject', ! ( ['in'], POINTER_c_wchar, 'pstrName' ), ( ['in'], c_ulong, 'dwHint' ), ( ['in'], POINTER(IUnknown), 'punkObject' ), *************** *** 104,116 **** _idlflags_ = [] _methods_ = [ ! COMMETHOD([dispid(1610743808)], HRESULT, 'InitNew'), ! COMMETHOD([dispid(1610743809)], HRESULT, 'Load', ( ['in'], POINTER(IPropertyBag2), 'pPropBag' ), ( ['in'], POINTER(IErrorLog), 'pErrLog' )), ! COMMETHOD([dispid(1610743810)], HRESULT, 'Save', ( ['in'], POINTER(IPropertyBag2), 'pPropBag' ), ( ['in'], c_int, 'fClearDirty' ), ( ['in'], c_int, 'fSaveAllProperties' )), ! COMMETHOD([dispid(1610743811)], HRESULT, 'IsDirty'), ] --- 105,117 ---- _idlflags_ = [] _methods_ = [ ! COMMETHOD([], HRESULT, 'InitNew'), ! COMMETHOD([], HRESULT, 'Load', ( ['in'], POINTER(IPropertyBag2), 'pPropBag' ), ( ['in'], POINTER(IErrorLog), 'pErrLog' )), ! COMMETHOD([], HRESULT, 'Save', ( ['in'], POINTER(IPropertyBag2), 'pPropBag' ), ( ['in'], c_int, 'fClearDirty' ), ( ['in'], c_int, 'fSaveAllProperties' )), ! COMMETHOD([], HRESULT, 'IsDirty'), ] |
From: Thomas H. <th...@us...> - 2005-10-20 09:25:52
|
Update of /cvsroot/ctypes/ctypes/unittests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10588 Modified Files: Tag: branch_1_0 test_prototypes.py Log Message: Add two tests contributed by Mike Fletcher. Index: test_prototypes.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/unittests/test_prototypes.py,v retrieving revision 1.6.6.4 retrieving revision 1.6.6.5 diff -C2 -d -r1.6.6.4 -r1.6.6.5 *** test_prototypes.py 18 Oct 2005 18:08:24 -0000 1.6.6.4 --- test_prototypes.py 20 Oct 2005 09:25:43 -0000 1.6.6.5 *************** *** 85,88 **** --- 85,106 ---- self.failUnlessEqual("a", func(byref(ca))[0]) + def test_c_glteximage2d( self ): + """Test a failure case from OpenGL-ctypes""" + func = testdll._testfunc_glteximage2d + func.restype = c_uint + func.argtypes = c_uint, c_int, c_int, c_int, c_int, c_int, c_uint, c_uint, c_void_p + + result = func( 0xde1, 0, 1, 32, 32, 0, 0x1909, 0x1401, '' ) + assert result == 0x1401, hex(result) + + def test_c_glteximage2d2( self ): + """Test a failure case from OpenGL-ctypes""" + func = testdll._testfunc_glteximage2d2 + func.restype = c_uint + func.argtypes = c_uint, c_int, c_int, c_int, c_int, c_int, c_uint, c_uint + + result = func( 0xde1, 0, 1, 32, 32, 0, 0x1909, 0x1401) + assert result == 0x1401, hex(result) + def test_c_void_p_arg(self): func = testdll._testfunc_p_p |
From: Thomas H. <th...@us...> - 2005-10-20 09:25:46
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10567 Modified Files: Tag: branch_1_0 _ctypes_test.c Log Message: Add two tests contributed by Mike Fletcher. Index: _ctypes_test.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/_ctypes_test.c,v retrieving revision 1.46.2.5 retrieving revision 1.46.2.6 diff -C2 -d -r1.46.2.5 -r1.46.2.6 *** _ctypes_test.c 22 Aug 2005 07:34:03 -0000 1.46.2.5 --- _ctypes_test.c 20 Oct 2005 09:25:38 -0000 1.46.2.6 *************** *** 62,65 **** --- 62,96 ---- } + /* attempt to isolate problems with glTexImage2D */ + EXPORT(unsigned int) _testfunc_glteximage2d( + unsigned int target, + int level, + int internalformat, + int width, + int height, + int border, + unsigned int format, + unsigned int type, + const void * pixels + ) { + /*printf( + "Hello world target=0x%x level=%i internalformat=%i width=%i height=%i border=%i format=0x%x type=0x%x\n", + target, level, internalformat, width, height, border, format, type + );*/ + return type; + } + EXPORT(unsigned int) _testfunc_glteximage2d2( + unsigned int target, + int level, + int internalformat, + int width, + int height, + int border, + unsigned int format, + unsigned int type + ) { + return type; + } + EXPORT(void *) get_strchr(void) { |
From: Thomas H. <th...@us...> - 2005-10-18 19:23:49
|
Update of /cvsroot/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5090 Modified Files: Tag: branch_1_0 ChangeLog Log Message: Remove all this too fancy Traceback printing stuff. Get the DllCanUnloadNow() and DllGetClassObject() functions from the ctypes module. Index: ChangeLog =================================================================== RCS file: /cvsroot/ctypes/ctypes/ChangeLog,v retrieving revision 1.86.2.22 retrieving revision 1.86.2.23 diff -C2 -d -r1.86.2.22 -r1.86.2.23 *** ChangeLog 18 Oct 2005 18:56:45 -0000 1.86.2.22 --- ChangeLog 18 Oct 2005 19:23:41 -0000 1.86.2.23 *************** *** 1,4 **** --- 1,12 ---- 2005-10-18 Thomas Heller <th...@py...> + * source\callproc.c: Remove all the too fancy traceback printing + stuff. + + The DllGetClassObject() and DllCanUnloadNow() functions are now + exposed by the ctypes module itself, which forwards their requests + to ctypes.com.server. Later, there should also be a way to + forward to comtypes.server (when that exists). + * source\_ctypes.c: Implemented __nonzero__ for simple types. |
From: Thomas H. <th...@us...> - 2005-10-18 19:18:37
|
Update of /cvsroot/ctypes/ctypes/source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3835 Modified Files: Tag: branch_1_0 callbacks.c Log Message: Remove all this too fancy Traceback printing stuff. Get the DllCanUnloadNow() and DllGetClassObject() functions from the ctypes module. Index: callbacks.c =================================================================== RCS file: /cvsroot/ctypes/ctypes/source/callbacks.c,v retrieving revision 1.71.2.4 retrieving revision 1.71.2.5 diff -C2 -d -r1.71.2.4 -r1.71.2.5 *** callbacks.c 14 Oct 2005 20:09:53 -0000 1.71.2.4 --- callbacks.c 18 Oct 2005 19:18:28 -0000 1.71.2.5 *************** *** 245,248 **** --- 245,249 ---- Done: Py_XDECREF(arglist); + PyGILState_Release(state); } *************** *** 360,456 **** #ifdef MS_WIN32 - /* - Modeled after a function from Mark Hammond. - - Obtains a string from a Python traceback. This is the exact same string as - "traceback.print_exception" would return. - - Result is a string which must be free'd using PyMem_Free() - */ - #define TRACEBACK_FETCH_ERROR(what) {errMsg = what; goto done;} - - char *PyTraceback_AsString(void) - { - char *errMsg = NULL; /* holds a local error message */ - char *result = NULL; /* a valid, allocated result. */ - PyObject *modStringIO = NULL; - PyObject *modTB = NULL; - PyObject *obStringIO = NULL; - PyObject *obResult = NULL; - - PyObject *type, *value, *traceback; - - PyErr_Fetch(&type, &value, &traceback); - PyErr_NormalizeException(&type, &value, &traceback); - - modStringIO = PyImport_ImportModule("cStringIO"); - if (modStringIO==NULL) - TRACEBACK_FETCH_ERROR("cant import cStringIO\n"); - - obStringIO = PyObject_CallMethod(modStringIO, "StringIO", NULL); - - /* Construct a cStringIO object */ - if (obStringIO==NULL) - TRACEBACK_FETCH_ERROR("cStringIO.StringIO() failed\n"); - - modTB = PyImport_ImportModule("traceback"); - if (modTB==NULL) - TRACEBACK_FETCH_ERROR("cant import traceback\n"); - - obResult = PyObject_CallMethod(modTB, "print_exception", - "OOOOO", - type, value ? value : Py_None, - traceback ? traceback : Py_None, - Py_None, - obStringIO); - - if (obResult==NULL) - TRACEBACK_FETCH_ERROR("traceback.print_exception() failed\n"); - Py_DECREF(obResult); - - obResult = PyObject_CallMethod(obStringIO, "getvalue", NULL); - if (obResult==NULL) - TRACEBACK_FETCH_ERROR("getvalue() failed.\n"); - - /* And it should be a string all ready to go - duplicate it. */ - if (!PyString_Check(obResult)) - TRACEBACK_FETCH_ERROR("getvalue() did not return a string\n"); - - { // a temp scope so I can use temp locals. - char *tempResult = PyString_AsString(obResult); - result = (char *)PyMem_Malloc(strlen(tempResult)+1); - if (result==NULL) - TRACEBACK_FETCH_ERROR("memory error duplicating the traceback string\n"); - strcpy(result, tempResult); - } // end of temp scope. - done: - /* All finished - first see if we encountered an error */ - if (result==NULL && errMsg != NULL) { - result = (char *)PyMem_Malloc(strlen(errMsg)+1); - if (result != NULL) - /* if it does, not much we can do! */ - strcpy(result, errMsg); - } - Py_XDECREF(modStringIO); - Py_XDECREF(modTB); - Py_XDECREF(obStringIO); - Py_XDECREF(obResult); - Py_XDECREF(value); - Py_XDECREF(traceback); - Py_XDECREF(type); - return result; - } - - void MyPyErr_Print(char *msg) - { - char *text; - - text = PyTraceback_AsString(); - MessageBox(NULL, - text, - msg, - MB_OK | MB_ICONSTOP); - PyMem_Free(text); - } static void LoadPython(void) --- 361,364 ---- *************** *** 468,481 **** PyObject *mod, *func, *result; long retval; ! mod = PyImport_ImportModule("ctypes.com.server"); ! if (!mod) /* There has been a warning before about this already */ return E_FAIL; func = PyObject_GetAttrString(mod, "DllGetClassObject"); Py_DECREF(mod); if (!func) { ! MyPyErr_Print("DllGetClassObject"); return E_FAIL; } --- 376,395 ---- PyObject *mod, *func, *result; long retval; + static PyObject *context; ! if (context == NULL) ! context = PyString_FromString("_ctypes.DllGetClassObject"); ! ! mod = PyImport_ImportModule("ctypes"); ! if (!mod) { ! PyErr_WriteUnraisable(context ? context : Py_None); /* There has been a warning before about this already */ return E_FAIL; + } func = PyObject_GetAttrString(mod, "DllGetClassObject"); Py_DECREF(mod); if (!func) { ! PyErr_WriteUnraisable(context ? context : Py_None); return E_FAIL; } *************** *** 485,495 **** Py_DECREF(func); if (!result) { ! MyPyErr_Print("Called DllGetClassObject"); return E_FAIL; } retval = PyInt_AsLong(result); ! if (PyErr_Occurred()) ! MyPyErr_Print("Convert result of DllGetClassObject to int"); Py_DECREF(result); return retval; --- 399,411 ---- Py_DECREF(func); if (!result) { ! PyErr_WriteUnraisable(context ? context : Py_None); return E_FAIL; } retval = PyInt_AsLong(result); ! if (PyErr_Occurred()) { ! PyErr_WriteUnraisable(context ? context : Py_None); ! retval = E_FAIL; ! } Py_DECREF(result); return retval; *************** *** 502,505 **** --- 418,422 ---- long result; PyGILState_STATE state; + LoadPython(); state = PyGILState_Ensure(); *************** *** 513,527 **** PyObject *mod, *func, *result; long retval; ! mod = PyImport_ImportModule("ctypes.com.server"); if (!mod) { ! MyPyErr_Print("Importing ctypes.com.server in Call_CanUnloadNow"); return E_FAIL; } ! func = PyObject_GetAttrString(mod, "DllCanUnloadNow"); Py_DECREF(mod); if (!func) { ! PyErr_Clear(); return E_FAIL; } --- 430,451 ---- PyObject *mod, *func, *result; long retval; + static PyObject *context; ! if (context == NULL) ! context = PyString_FromString("_ctypes.DllCanUnloadNow"); ! ! mod = PyImport_ImportModule("ctypes"); if (!mod) { ! /* OutputDebugString("Could not import ctypes"); */ ! /* We assume that this error can only occur when shutting ! down, so we silently ignore it */ ! PyErr_Clear(); return E_FAIL; } ! /* Other errors cannot be raised, but are printed to stderr */ func = PyObject_GetAttrString(mod, "DllCanUnloadNow"); Py_DECREF(mod); if (!func) { ! PyErr_WriteUnraisable(context ? context : Py_None); return E_FAIL; } *************** *** 530,540 **** Py_DECREF(func); if (!result) { ! PyErr_Clear(); return E_FAIL; } retval = PyInt_AsLong(result); ! if (PyErr_Occurred()) ! PyErr_Clear(); Py_DECREF(result); return retval; --- 454,466 ---- Py_DECREF(func); if (!result) { ! PyErr_WriteUnraisable(context ? context : Py_None); return E_FAIL; } retval = PyInt_AsLong(result); ! if (PyErr_Occurred()) { ! PyErr_WriteUnraisable(context ? context : Py_None); ! retval = E_FAIL; ! } Py_DECREF(result); return retval; |
From: Thomas H. <th...@us...> - 2005-10-18 19:16:08
|
Update of /cvsroot/ctypes/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3147 Modified Files: Tag: branch_1_0 __init__.py Log Message: Expose DllGetClassObject and DllCanUnloadNow from the ctypes\__init__.py module. Index: __init__.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/__init__.py,v retrieving revision 1.61.2.10 retrieving revision 1.61.2.11 diff -C2 -d -r1.61.2.10 -r1.61.2.11 *** __init__.py 18 Oct 2005 18:57:24 -0000 1.61.2.10 --- __init__.py 18 Oct 2005 19:15:44 -0000 1.61.2.11 *************** *** 463,464 **** --- 463,475 ---- from decorators import stdcall + # Later, these functions should examine the registry (or whatever) + # to find out if they need ctypes.com.server or comtypes.server. + def DllGetClassObject(rclsid, riid, ppv): + # trick py2exe + ctcom = __import__("ctypes.com.server", globals(), locals(), ['*']) + return ctcom.DllGetClassObject(rclsid, riid, ppv) + + def DllCanUnloadNow(): + # trick py2exe + ctcom = __import__("ctypes.com.server", globals(), locals(), ['*']) + return ctcom.DllCanUnloadNow() |
From: Thomas H. <th...@us...> - 2005-10-18 18:57:32
|
Update of /cvsroot/ctypes/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30100 Modified Files: Tag: branch_1_0 __init__.py Log Message: Can't cast to c_uint. Index: __init__.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/__init__.py,v retrieving revision 1.61.2.9 retrieving revision 1.61.2.10 diff -C2 -d -r1.61.2.9 -r1.61.2.10 *** __init__.py 18 Aug 2005 19:06:32 -0000 1.61.2.9 --- __init__.py 18 Oct 2005 18:57:24 -0000 1.61.2.10 *************** *** 210,214 **** def __repr__(self): if windll.kernel32.IsBadStringPtrA(self, -1): ! return "%s(0x%x)" % (self.__class__.__name__, cast(self, c_uint).value) else: return "%s(%r)" % (self.__class__.__name__, self.value) --- 210,215 ---- def __repr__(self): if windll.kernel32.IsBadStringPtrA(self, -1): ! ## return "%s(0x%x)" % (self.__class__.__name__, cast(self, c_uint).value) ! return "%s(<invalid>)" % self.__class__.__name__ else: return "%s(%r)" % (self.__class__.__name__, self.value) *************** *** 221,224 **** --- 222,226 ---- def __repr__(self): return "%s(%r)" % (self.__class__.__name__, self.value) + c_voidp = c_void_p # backwards compatibility (to a bug) *************** *** 260,264 **** def __repr__(self): if windll.kernel32.IsBadStringPtrW(self, -1): ! return "%s(0x%x)" % (self.__class__.__name__, cast(self, c_uint).value) else: return "%s(%r)" % (self.__class__.__name__, self.value) --- 262,267 ---- def __repr__(self): if windll.kernel32.IsBadStringPtrW(self, -1): ! return "%s(<invalid>)" % self.__class__.__name__ ! ## return "%s(0x%x)" % (self.__class__.__name__, cast(self, c_uint).value) else: return "%s(%r)" % (self.__class__.__name__, self.value) |