hash function for property-rna. eg. hash(bpy.context.object.modifiers)
authorCampbell Barton <ideasman42@gmail.com>
Sun, 25 Apr 2010 21:13:42 +0000 (21:13 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Sun, 25 Apr 2010 21:13:42 +0000 (21:13 +0000)
source/blender/python/intern/bpy_rna.c

index 5acabd81f461ffe570bcd574293fec6360a8e183..f5c24b16e8e19a9548104985ae3d92fe06afb456 100644 (file)
@@ -431,7 +431,27 @@ static PyObject *pyrna_prop_repr( BPy_PropertyRNA *self )
 
 static long pyrna_struct_hash( BPy_StructRNA *self )
 {
-       return (long)self->ptr.data;
+       return _Py_HashPointer(self->ptr.data);
+}
+
+/* from python's meth_hash v3.1.2 */
+static long pyrna_prop_hash(BPy_PropertyRNA *self)
+{      
+       long x,y;
+       if (self->ptr.data == NULL)
+               x = 0;
+       else {
+               x = _Py_HashPointer(self->ptr.data);
+               if (x == -1)
+                       return -1;
+       }
+       y = _Py_HashPointer((void*)(self->prop));
+       if (y == -1)
+               return -1;
+       x ^= y;
+       if (x == -1)
+               x = -2;
+       return x;
 }
 
 /* use our own dealloc so we can free a property if we use one */
@@ -3490,7 +3510,7 @@ PyTypeObject pyrna_prop_Type = {
 
        /* More standard operations (here for binary compatibility) */
 
-       NULL,                                           /* hashfunc tp_hash; */
+       ( hashfunc ) pyrna_prop_hash,   /* hashfunc tp_hash; */
        NULL,                       /* ternaryfunc tp_call; */
        NULL,                       /* reprfunc tp_str; */