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>
This commit is contained in:
parent
060e39716d
commit
a781abe326
@ -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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user