summaryrefslogtreecommitdiff
path: root/pyuno
diff options
context:
space:
mode:
authorMatthew J. Francis <mjay.francis@gmail.com>2015-07-21 09:58:44 +0800
committerMatthew Francis <mjay.francis@gmail.com>2015-07-21 06:56:42 +0000
commita781abe326b45573eb677030358c362394e2bc09 (patch)
treee824d17643f520fdcb20b52273d7e5fd6711b8ab /pyuno
parent060e39716dba27ecf585cec33a2de9a865980a42 (diff)
Make PyUNO objects hashable
This allows them to be used as set members and dict keys Change-Id: I10bd71788be6b508c6f491a27a8841e599e47e3a Reviewed-on: https://gerrit.libreoffice.org/17248 Reviewed-by: Matthew Francis <mjay.francis@gmail.com> Tested-by: Matthew Francis <mjay.francis@gmail.com>
Diffstat (limited to 'pyuno')
-rw-r--r--pyuno/source/module/pyuno.cxx26
1 files changed, 25 insertions, 1 deletions
diff --git a/pyuno/source/module/pyuno.cxx b/pyuno/source/module/pyuno.cxx
index 413cc20c227e..20e2f9fceb14 100644
--- a/pyuno/source/module/pyuno.cxx
+++ b/pyuno/source/module/pyuno.cxx
@@ -397,6 +397,30 @@ PyObject *PyUNO_repr( PyObject * self )
return ret;
}
+Py_hash_t PyUNO_hash( PyObject *self )
+{
+
+ PyUNO *me = reinterpret_cast<PyUNO *>(self);
+
+ // Py_hash_t is not necessarily the same size as a pointer, but this is not
+ // important for hashing - it just has to return the same value each time
+ if( me->members->wrappedObject.getValueType().getTypeClass()
+ == com::sun::star::uno::TypeClass_STRUCT ||
+ me->members->wrappedObject.getValueType().getTypeClass()
+ == com::sun::star::uno::TypeClass_EXCEPTION )
+ {
+ Reference< XMaterialHolder > xMe( me->members->xInvocation, UNO_QUERY );
+ return sal::static_int_cast< Py_hash_t >( reinterpret_cast< sal_IntPtr > (
+ xMe->getMaterial().getValue() ) );
+ }
+ else
+ {
+ return sal::static_int_cast< Py_hash_t >( reinterpret_cast< sal_IntPtr > (
+ me->members->wrappedObject.getValue() ) );
+ }
+
+}
+
PyObject *PyUNO_invoke( PyObject *object, const char *name , PyObject *args )
{
PyRef ret;
@@ -1690,7 +1714,7 @@ static PyTypeObject PyUNOType =
PyUNONumberMethods,
PyUNOSequenceMethods,
PyUNOMappingMethods,
- nullptr,
+ PyUNO_hash,
nullptr,
PyUNO_str,
nullptr,