[pywin32-checkins] pywin32/com/win32com/src MiscTypes.cpp,1.5,1.6 PyIBase.cpp,1.5,1.6
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
|
From: <mha...@us...> - 2003-11-02 05:26:39
|
Update of /cvsroot/pywin32/pywin32/com/win32com/src
In directory sc8-pr-cvs1:/tmp/cvs-serv5588
Modified Files:
MiscTypes.cpp PyIBase.cpp
Log Message:
Roger inspired me to do tp_iter support in a far more generic way.
Should be possible to make all Enums and Providers support tp_iter()
simply by declaring the correct type - no implementation of the
iter()/iternext() should be necessary.
All enums in the core package should now support Enums correctly
(a few more could possibly be nominated as Enum providers though.
Index: MiscTypes.cpp
===================================================================
RCS file: /cvsroot/pywin32/pywin32/com/win32com/src/MiscTypes.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** MiscTypes.cpp 31 Oct 2003 06:55:12 -0000 1.5
--- MiscTypes.cpp 2 Nov 2003 05:26:13 -0000 1.6
***************
*** 113,128 ****
PyComTypeObject( name, pBase, typeSize, methodList, thector)
{
! tp_iter = PyIBase::iter;
! tp_iternext = PyIBase::iternext;
! tp_flags |= Py_TPFLAGS_HAVE_ITER;
}
// Our type for IEnum provider interfaces
! PyComEnumProviderTypeObject::PyComEnumProviderTypeObject( const char *name, PyComTypeObject *pBase, int typeSize, struct PyMethodDef* methodList, PyIUnknown * (* thector)(IUnknown *)) :
! PyComTypeObject( name, pBase, typeSize, methodList, thector)
{
! tp_iter = PyIBase::iter;
! // tp_iternext remains NULL
! tp_flags |= Py_TPFLAGS_HAVE_ITER;
}
--- 113,135 ----
PyComTypeObject( name, pBase, typeSize, methodList, thector)
{
! tp_iter = PyIEnum::iter;
! tp_iternext = PyIEnum::iternext;
! tp_flags |= Py_TPFLAGS_HAVE_ITER;
}
// Our type for IEnum provider interfaces
! PyComEnumProviderTypeObject::PyComEnumProviderTypeObject(
! const char *name,
! PyComTypeObject *pBase,
! int typeSize,
! struct PyMethodDef* methodList,
! PyIUnknown * (* thector)(IUnknown *),
! const char *penum_method_name) :
! PyComTypeObject( name, pBase, typeSize, methodList, thector),
! enum_method_name(penum_method_name)
{
! tp_iter = PyIEnumProvider::iter;
! // tp_iternext remains NULL
! tp_flags |= Py_TPFLAGS_HAVE_ITER;
}
Index: PyIBase.cpp
===================================================================
RCS file: /cvsroot/pywin32/pywin32/com/win32com/src/PyIBase.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** PyIBase.cpp 31 Oct 2003 06:55:12 -0000 1.5
--- PyIBase.cpp 2 Nov 2003 05:26:13 -0000 1.6
***************
*** 55,72 ****
}
- PyObject *
- PyIBase::iter()
- {
- return PyErr_Format(PyExc_RuntimeError,
- "iter must be overridden by objects supporting enumeration (type '%s').", ob_type->tp_name);
- }
-
- PyObject *
- PyIBase::iternext()
- {
- return PyErr_Format(PyExc_RuntimeError,
- "iternext must be overridden by objects supporting enumeration (type '%s').", ob_type->tp_name);
- }
-
/*static*/int PyIBase::setattr(PyObject *op, char *name, PyObject *v)
{
--- 55,58 ----
***************
*** 104,114 ****
}
! /*static*/ PyObject *PyIBase::iter(PyObject *self)
{
! return ((PyIBase *)self)->iter();
}
! /*static*/ PyObject *PyIBase::iternext(PyObject *self)
{
! return ((PyIBase *)self)->iternext();
}
--- 90,134 ----
}
! // PyIEnum iter methods - generic for any "standard" COM IEnum interface.
! PyObject *PyIEnum::iter()
{
! Py_INCREF(this);
! return this;
}
! PyObject *PyIEnum::iternext()
{
! PyObject *method = PyObject_GetAttrString(this, "Next");
! if (!method)
! return NULL;
! PyObject *args=Py_BuildValue("(i)", 1);
! PyObject *result = PyObject_Call(method, args, NULL);
! Py_DECREF(method);
! Py_DECREF(args);
! if (!result)
! return NULL;
! PyObject *ret;
! if (PySequence_Length(result)==0){
! PyErr_SetNone(PyExc_StopIteration);
! ret = NULL;
! } else
! ret = PySequence_GetItem(result, 0);
! Py_DECREF(result);
! return ret;
! }
!
! // PyIEnumProvider iter methods - generic for COM object that can provide an IEnum*
! // interface via a method call taking no args.
! PyObject *PyIEnumProvider::iter()
! {
! PyComEnumProviderTypeObject *t = (PyComEnumProviderTypeObject *)ob_type;
! PyObject *method = PyObject_GetAttrString(this, (char *)t->enum_method_name);
! if (!method)
! return NULL;
! PyObject *args=PyTuple_New(0);
! PyObject *result = PyObject_Call(method, args, NULL);
! Py_DECREF(method);
! Py_DECREF(args);
! return result;
}
+
|