[Libreoffice-commits] core.git: pyuno/source

Matthew J. Francis mjay.francis at gmail.com
Mon Jul 20 23:57:16 PDT 2015


 pyuno/source/module/pyuno.cxx |   26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)

New commits:
commit a781abe326b45573eb677030358c362394e2bc09
Author: Matthew J. Francis <mjay.francis at gmail.com>
Date:   Tue Jul 21 09:58:44 2015 +0800

    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 at gmail.com>
    Tested-by: Matthew Francis <mjay.francis at gmail.com>

diff --git a/pyuno/source/module/pyuno.cxx b/pyuno/source/module/pyuno.cxx
index 413cc20..20e2f9f 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,


More information about the Libreoffice-commits mailing list