[pywin32-checkins] pywin32/com/win32com/src MiscTypes.cpp,1.2,1.3 PyIBase.cpp,1.2,1.3
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
|
From: <mha...@us...> - 2003-10-25 23:01:00
|
Update of /cvsroot/pywin32/pywin32/com/win32com/src
In directory sc8-pr-cvs1:/tmp/cvs-serv32579
Modified Files:
MiscTypes.cpp PyIBase.cpp
Log Message:
Move to the tp_getattro() slot, so we can use PyObject_GenericGetAttr(),
so we can get some of the new type benefits, such as the automatic 'next'
method on iterators. Start moving towards Python's new tp_base slot
in favour of the hand-rolled one we built before Python saw the light :)
Index: MiscTypes.cpp
===================================================================
RCS file: /cvsroot/pywin32/pywin32/com/win32com/src/MiscTypes.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** MiscTypes.cpp 6 Oct 2003 13:09:44 -0000 1.2
--- MiscTypes.cpp 23 Oct 2003 07:34:37 -0000 1.3
***************
*** 17,24 ****
0, /*tp_dealloc*/
0, /*tp_print*/
! PyType_Type.tp_getattr, /*tp_getattr*/
0, /*tp_setattr*/
0, /*tp_compare*/
! PyType_Type.tp_repr, /*tp_repr*/
0, /*tp_as_number*/
0, /*tp_as_sequence*/
--- 17,24 ----
0, /*tp_dealloc*/
0, /*tp_print*/
! 0, /*tp_getattr*/
0, /*tp_setattr*/
0, /*tp_compare*/
! 0, /*tp_repr*/
0, /*tp_as_number*/
0, /*tp_as_sequence*/
***************
*** 27,34 ****
0, /*tp_call*/
0, /*tp_str*/
! 0, /*tp_getattro */
0, /*tp_setattro */
0, /* tp_as_buffer */
! 0, /* tp_flags */
"Define the behavior of a PythonCOM Interface type.", /* tp_doc */
};
--- 27,34 ----
0, /*tp_call*/
0, /*tp_str*/
! PyObject_GenericGetAttr, /*tp_getattro */
0, /*tp_setattro */
0, /* tp_as_buffer */
! Py_TPFLAGS_DEFAULT, /* tp_flags */
"Define the behavior of a PythonCOM Interface type.", /* tp_doc */
};
***************
*** 40,44 ****
--- 40,48 ----
// probably better, as is forces _all_ python objects have the same type sig.
static const PyTypeObject type_template = {
+ #ifdef OLD_PYTHON_TYPES
PyObject_HEAD_INIT(&PyInterfaceType_Type)
+ #else
+ PyObject_HEAD_INIT(&PyType_Type)
+ #endif
0, /*ob_size*/
"PythonComTypeTemplate", /*tp_name*/
***************
*** 48,52 ****
(destructor) PyIBase::dealloc, /*tp_dealloc*/
0, /*tp_print*/
! (getattrfunc) PyIBase::getattr, /*tp_getattr*/
(setattrfunc) PyIBase::setattr, /*tp_setattr*/
PyIBase::cmp, /*tp_compare*/
--- 52,56 ----
(destructor) PyIBase::dealloc, /*tp_dealloc*/
0, /*tp_print*/
! 0, /*tp_getattr*/
(setattrfunc) PyIBase::setattr, /*tp_setattr*/
PyIBase::cmp, /*tp_compare*/
***************
*** 58,62 ****
0, /*tp_call*/
0, /*tp_str*/
! 0, /*tp_getattro */
0, /*tp_setattro */
0, /* tp_as_buffer */
--- 62,66 ----
0, /*tp_call*/
0, /*tp_str*/
! PyIBase::getattro, /* tp_getattro */
0, /*tp_setattro */
0, /* tp_as_buffer */
***************
*** 68,72 ****
0, /* tp_weaklistoffset */
PyIBase::iter, /* tp_iter */
! PyIBase::iternext /* tp_iternext */
};
--- 72,84 ----
0, /* tp_weaklistoffset */
PyIBase::iter, /* tp_iter */
! PyIBase::iternext, /* tp_iternext */
! 0, /* tp_methods */
! 0, /* tp_members */
! 0, /* tp_getset */
! #ifdef OLD_PYTHON_TYPES
! 0, /* tp_base */
! #else
! &PyInterfaceType_Type,
! #endif
};
***************
*** 89,93 ****
--- 101,110 ----
/* static */ BOOL PyComTypeObject::is_interface_type(const PyObject *ob)
{
+ #ifdef OLD_PYTHON_TYPES
return ob->ob_type == &PyInterfaceType_Type;
+ #else
+ return ob->ob_type == &PyType_Type &&
+ ((PyTypeObject *)ob)->tp_base == &PyInterfaceType_Type;
+ #endif
}
Index: PyIBase.cpp
===================================================================
RCS file: /cvsroot/pywin32/pywin32/com/win32com/src/PyIBase.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** PyIBase.cpp 6 Oct 2003 13:09:44 -0000 1.2
--- PyIBase.cpp 23 Oct 2003 07:34:37 -0000 1.3
***************
*** 31,38 ****
/*static*/PyObject *
! PyIBase::getattr(PyObject *self, char *name)
{
! return ((PyIBase *)self)->getattr(name);
}
PyObject *
PyIBase::getattr(char *name)
--- 31,52 ----
/*static*/PyObject *
! PyIBase::getattro(PyObject *self, PyObject *name)
{
! if (PyString_Check(name)) {
! PyObject *rc = ((PyIBase *)self)->getattr(PyString_AsString(name));
! if (rc)
! return rc;
! PyErr_Clear();
! }
! // Using PyObject_GenericGetAttr allows some special type magic
! // (ie,
! #ifdef OLD_PYTHON_TYPES
! PyErr_SetObject(PyExc_AttributeError, name);
! return NULL;
! #else
! return PyObject_GenericGetAttr(self, name);
! #endif
}
+
PyObject *
PyIBase::getattr(char *name)
***************
*** 41,57 ****
}
PyObject *
! PyIBase::iter()
{
! return PyErr_Format(PyExc_TypeError,
! "COM objects of type '%s' can not be iterated.", ob_type->tp_name);
! return NULL;
}
PyObject *
! PyIBase::iternext()
{
! PyErr_SetString(PyExc_RuntimeError, "not iterable");
! return NULL;
}
/*static*/int PyIBase::setattr(PyObject *op, char *name, PyObject *v)
{
--- 55,71 ----
}
PyObject *
! PyIBase::iternext()
{
! return PyErr_Format(PyExc_RuntimeError,
! "iternext must be overridden by objects supporting enumeration (type '%s').", ob_type->tp_name);
}
PyObject *
! PyIBase::iter()
{
! return PyErr_Format(PyExc_TypeError,
! "COM objects of type '%s' can not be iterated.", ob_type->tp_name);
}
+
/*static*/int PyIBase::setattr(PyObject *op, char *name, PyObject *v)
{
***************
*** 87,95 ****
{
return ((PyIBase *)ob1)->compare(ob2);
- }
-
- /*static*/ PyObject *PyIBase::iter(PyObject *self)
- {
- return ((PyIBase *)self)->iter();
}
--- 101,104 ----
|