summaryrefslogtreecommitdiff
path: root/py/modules/IcePy/Proxy.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'py/modules/IcePy/Proxy.cpp')
-rw-r--r--py/modules/IcePy/Proxy.cpp123
1 files changed, 81 insertions, 42 deletions
diff --git a/py/modules/IcePy/Proxy.cpp b/py/modules/IcePy/Proxy.cpp
index f7c67609c06..90df0035ad8 100644
--- a/py/modules/IcePy/Proxy.cpp
+++ b/py/modules/IcePy/Proxy.cpp
@@ -72,7 +72,7 @@ allocateProxy(const Ice::ObjectPrx& proxy, const Ice::CommunicatorPtr& communica
extern "C"
#endif
static ProxyObject*
-proxyNew(PyObject* /*arg*/)
+proxyNew(PyTypeObject* /*type*/, PyObject* /*args*/, PyObject* /*kwds*/)
{
PyErr_Format(PyExc_RuntimeError, STRCAST("A proxy cannot be created directly"));
return 0;
@@ -86,27 +86,63 @@ proxyDealloc(ProxyObject* self)
{
delete self->proxy;
delete self->communicator;
- self->ob_type->tp_free(self);
+ Py_TYPE(self)->tp_free(reinterpret_cast<PyObject*>(self));
}
#ifdef WIN32
extern "C"
#endif
-static int
-proxyCompare(ProxyObject* p1, ProxyObject* p2)
+static PyObject*
+proxyCompare(ProxyObject* p1, PyObject* other, int op)
{
- if(*p1->proxy < *p2->proxy)
- {
- return -1;
- }
- else if(*p1->proxy == *p2->proxy)
+ bool result;
+
+ if(PyObject_TypeCheck(other, &ProxyType))
{
- return 0;
+ ProxyObject* p2 = reinterpret_cast<ProxyObject*>(other);
+
+ switch(op)
+ {
+ case Py_EQ:
+ result = *p1->proxy == *p2->proxy;
+ break;
+ case Py_NE:
+ result = *p1->proxy != *p2->proxy;
+ break;
+ case Py_LE:
+ result = *p1->proxy <= *p2->proxy;
+ break;
+ case Py_GE:
+ result = *p1->proxy >= *p2->proxy;
+ break;
+ case Py_LT:
+ result = *p1->proxy < *p2->proxy;
+ break;
+ case Py_GT:
+ result = *p1->proxy > *p2->proxy;
+ break;
+ }
}
else
{
- return 1;
+ if(op == Py_EQ)
+ {
+ result = false;
+ }
+ else if(op == Py_NE)
+ {
+ result = true;
+ }
+ else
+ {
+ PyErr_Format(PyExc_TypeError, "can't compare %s to %s", Py_TYPE(p1)->tp_name, Py_TYPE(other)->tp_name);
+ return 0;
+ }
}
+
+ PyObject* r = result ? getTrue() : getFalse();
+ Py_INCREF(r);
+ return r;
}
#ifdef WIN32
@@ -504,7 +540,7 @@ proxyIceContext(ProxyObject* self, PyObject* args)
return 0;
}
- return createProxy(newProxy, *self->communicator, reinterpret_cast<PyObject*>(self->ob_type));
+ return createProxy(newProxy, *self->communicator, reinterpret_cast<PyObject*>(Py_TYPE(self)));
}
#ifdef WIN32
@@ -616,7 +652,7 @@ proxyIceAdapterId(ProxyObject* self, PyObject* args)
return 0;
}
- return createProxy(newProxy, *self->communicator, reinterpret_cast<PyObject*>(self->ob_type));
+ return createProxy(newProxy, *self->communicator, reinterpret_cast<PyObject*>(Py_TYPE(self)));
}
#ifdef WIN32
@@ -704,7 +740,7 @@ proxyIceEndpoints(ProxyObject* self, PyObject* args)
return 0;
}
- return createProxy(newProxy, *self->communicator, reinterpret_cast<PyObject*>(self->ob_type));
+ return createProxy(newProxy, *self->communicator, reinterpret_cast<PyObject*>(Py_TYPE(self)));
}
#ifdef WIN32
@@ -718,7 +754,7 @@ proxyIceGetLocatorCacheTimeout(ProxyObject* self)
try
{
Ice::Int timeout = (*self->proxy)->ice_getLocatorCacheTimeout();
- return PyInt_FromLong(timeout);
+ return PyLong_FromLong(timeout);
}
catch(const Ice::Exception& ex)
{
@@ -772,7 +808,7 @@ proxyIceLocatorCacheTimeout(ProxyObject* self, PyObject* args)
return 0;
}
- return createProxy(newProxy, *self->communicator, reinterpret_cast<PyObject*>(self->ob_type));
+ return createProxy(newProxy, *self->communicator, reinterpret_cast<PyObject*>(Py_TYPE(self)));
}
#ifdef WIN32
@@ -829,7 +865,7 @@ proxyIceConnectionCached(ProxyObject* self, PyObject* args)
return 0;
}
- return createProxy(newProxy, *self->communicator, reinterpret_cast<PyObject*>(self->ob_type));
+ return createProxy(newProxy, *self->communicator, reinterpret_cast<PyObject*>(Py_TYPE(self)));
}
#ifdef WIN32
@@ -917,7 +953,7 @@ proxyIceEndpointSelection(ProxyObject* self, PyObject* args)
return 0;
}
- return createProxy(newProxy, *self->communicator, reinterpret_cast<PyObject*>(self->ob_type));
+ return createProxy(newProxy, *self->communicator, reinterpret_cast<PyObject*>(Py_TYPE(self)));
}
#ifdef WIN32
@@ -974,8 +1010,7 @@ proxyIceSecure(ProxyObject* self, PyObject* args)
return 0;
}
- PyTypeObject* type = self->ob_type; // Necessary to prevent GCC's strict-alias warnings.
- return createProxy(newProxy, *self->communicator, reinterpret_cast<PyObject*>(type));
+ return createProxy(newProxy, *self->communicator, reinterpret_cast<PyObject*>(Py_TYPE(self)));
}
#ifdef WIN32
@@ -1032,7 +1067,7 @@ proxyIcePreferSecure(ProxyObject* self, PyObject* args)
return 0;
}
- return createProxy(newProxy, *self->communicator, reinterpret_cast<PyObject*>(self->ob_type));
+ return createProxy(newProxy, *self->communicator, reinterpret_cast<PyObject*>(Py_TYPE(self)));
}
#ifdef WIN32
@@ -1098,7 +1133,7 @@ proxyIceRouter(ProxyObject* self, PyObject* args)
return 0;
}
- return createProxy(newProxy, *self->communicator, reinterpret_cast<PyObject*>(self->ob_type));
+ return createProxy(newProxy, *self->communicator, reinterpret_cast<PyObject*>(Py_TYPE(self)));
}
#ifdef WIN32
@@ -1164,7 +1199,7 @@ proxyIceLocator(ProxyObject* self, PyObject* args)
return 0;
}
- return createProxy(newProxy, *self->communicator, reinterpret_cast<PyObject*>(self->ob_type));
+ return createProxy(newProxy, *self->communicator, reinterpret_cast<PyObject*>(Py_TYPE(self)));
}
#ifdef WIN32
@@ -1186,7 +1221,7 @@ proxyIceTwoway(ProxyObject* self)
return 0;
}
- return createProxy(newProxy, *self->communicator, reinterpret_cast<PyObject*>(self->ob_type));
+ return createProxy(newProxy, *self->communicator, reinterpret_cast<PyObject*>(Py_TYPE(self)));
}
#ifdef WIN32
@@ -1231,7 +1266,7 @@ proxyIceOneway(ProxyObject* self)
return 0;
}
- return createProxy(newProxy, *self->communicator, reinterpret_cast<PyObject*>(self->ob_type));
+ return createProxy(newProxy, *self->communicator, reinterpret_cast<PyObject*>(Py_TYPE(self)));
}
#ifdef WIN32
@@ -1276,7 +1311,7 @@ proxyIceBatchOneway(ProxyObject* self)
return 0;
}
- return createProxy(newProxy, *self->communicator, reinterpret_cast<PyObject*>(self->ob_type));
+ return createProxy(newProxy, *self->communicator, reinterpret_cast<PyObject*>(Py_TYPE(self)));
}
#ifdef WIN32
@@ -1321,7 +1356,7 @@ proxyIceDatagram(ProxyObject* self)
return 0;
}
- return createProxy(newProxy, *self->communicator, reinterpret_cast<PyObject*>(self->ob_type));
+ return createProxy(newProxy, *self->communicator, reinterpret_cast<PyObject*>(Py_TYPE(self)));
}
#ifdef WIN32
@@ -1366,7 +1401,7 @@ proxyIceBatchDatagram(ProxyObject* self)
return 0;
}
- return createProxy(newProxy, *self->communicator, reinterpret_cast<PyObject*>(self->ob_type));
+ return createProxy(newProxy, *self->communicator, reinterpret_cast<PyObject*>(Py_TYPE(self)));
}
#ifdef WIN32
@@ -1423,7 +1458,7 @@ proxyIceCompress(ProxyObject* self, PyObject* args)
return 0;
}
- return createProxy(newProxy, *self->communicator, reinterpret_cast<PyObject*>(self->ob_type));
+ return createProxy(newProxy, *self->communicator, reinterpret_cast<PyObject*>(Py_TYPE(self)));
}
#ifdef WIN32
@@ -1451,7 +1486,7 @@ proxyIceTimeout(ProxyObject* self, PyObject* args)
return 0;
}
- return createProxy(newProxy, *self->communicator, reinterpret_cast<PyObject*>(self->ob_type));
+ return createProxy(newProxy, *self->communicator, reinterpret_cast<PyObject*>(Py_TYPE(self)));
}
// NOTE: ice_collocationOptimized is not currently supported.
@@ -1487,7 +1522,7 @@ proxyIceConnectionId(ProxyObject* self, PyObject* args)
return 0;
}
- return createProxy(newProxy, *self->communicator, reinterpret_cast<PyObject*>(self->ob_type));
+ return createProxy(newProxy, *self->communicator, reinterpret_cast<PyObject*>(Py_TYPE(self)));
}
#ifdef WIN32
@@ -1901,7 +1936,7 @@ proxyIceCheckedCast(PyObject* type, PyObject* args)
PyObject* facet = 0;
- if(PyString_Check(facetOrCtx))
+ if(checkString(facetOrCtx))
{
facet = facetOrCtx;
}
@@ -2013,7 +2048,7 @@ proxyCheckedCast(PyObject* /*self*/, PyObject* args)
if(arg1 != 0)
{
- if(!PyString_Check(arg1))
+ if(!checkString(arg1))
{
PyErr_Format(PyExc_ValueError, STRCAST("facet argument to checkedCast must be a string"));
return 0;
@@ -2030,7 +2065,7 @@ proxyCheckedCast(PyObject* /*self*/, PyObject* args)
}
else if(arg1 != 0 && arg1 != Py_None)
{
- if(PyString_Check(arg1))
+ if(checkString(arg1))
{
facet = arg1;
}
@@ -2238,33 +2273,37 @@ PyTypeObject ProxyType =
{
/* The ob_type field must be initialized in the module init function
* to be portable to Windows without using C++. */
- PyObject_HEAD_INIT(0)
- 0, /* ob_size */
+ PyVarObject_HEAD_INIT(0, 0)
STRCAST("IcePy.ObjectPrx"), /* tp_name */
sizeof(ProxyObject), /* tp_basicsize */
0, /* tp_itemsize */
/* methods */
- (destructor)proxyDealloc, /* tp_dealloc */
+ reinterpret_cast<destructor>(proxyDealloc), /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
- (cmpfunc)proxyCompare, /* tp_compare */
- (reprfunc)proxyRepr, /* tp_repr */
+ 0, /* tp_reserved */
+ reinterpret_cast<reprfunc>(proxyRepr), /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
- (hashfunc)proxyHash, /* tp_hash */
+ reinterpret_cast<hashfunc>(proxyHash), /* tp_hash */
0, /* tp_call */
0, /* tp_str */
0, /* tp_getattro */
0, /* tp_setattro */
0, /* tp_as_buffer */
+#if PY_VERSION_HEX >= 0x03000000
+ Py_TPFLAGS_BASETYPE, /* tp_flags */
+#else
Py_TPFLAGS_BASETYPE |
+ Py_TPFLAGS_HAVE_RICHCOMPARE |
Py_TPFLAGS_HAVE_CLASS, /* tp_flags */
+#endif
0, /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
- 0, /* tp_richcompare */
+ reinterpret_cast<richcmpfunc>(proxyCompare), /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
@@ -2278,7 +2317,7 @@ PyTypeObject ProxyType =
0, /* tp_dictoffset */
0, /* tp_init */
0, /* tp_alloc */
- (newfunc)proxyNew, /* tp_new */
+ reinterpret_cast<newfunc>(proxyNew), /* tp_new */
0, /* tp_free */
0, /* tp_is_gc */
};