[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [43396] trunk/blender/source/blender/ python/intern/bpy_rna.c: note on compating RNA pointers and compare RNA types for RNA-Properties too .

Campbell Barton ideasman42 at gmail.com
Sun Jan 15 13:35:46 CET 2012


Revision: 43396
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=43396
Author:   campbellbarton
Date:     2012-01-15 12:35:40 +0000 (Sun, 15 Jan 2012)
Log Message:
-----------
note on compating RNA pointers and compare RNA types for RNA-Properties too.

Modified Paths:
--------------
    trunk/blender/source/blender/python/intern/bpy_rna.c

Modified: trunk/blender/source/blender/python/intern/bpy_rna.c
===================================================================
--- trunk/blender/source/blender/python/intern/bpy_rna.c	2012-01-15 11:53:14 UTC (rev 43395)
+++ trunk/blender/source/blender/python/intern/bpy_rna.c	2012-01-15 12:35:40 UTC (rev 43396)
@@ -743,14 +743,28 @@
 	return 0;
 }
 
+/* note on __cmp__:
+ * checking the 'ptr->data' matches works in almost all cases,
+ * however there are a few RNA properties that are fake sub-structs and
+ * share the pointer with the parent, in those cases this happens 'a.b == a'
+ * see: r43352 for example.
+ *
+ * So compare the 'ptr->type' as well to avoid this problem.
+ * It's highly unlikely this would happen that 'ptr->data' and 'ptr->prop' would match,
+ * but _not_ 'ptr->type' but include this check for completeness.
+ * - campbell */
+
 static int pyrna_struct_compare(BPy_StructRNA *a, BPy_StructRNA *b)
 {
-	return (a->ptr.data == b->ptr.data && a->ptr.type == b->ptr.type) ? 0 : -1;
+	return ( (a->ptr.data == b->ptr.data) &&
+	         (a->ptr.type == b->ptr.type)) ? 0 : -1;
 }
 
 static int pyrna_prop_compare(BPy_PropertyRNA *a, BPy_PropertyRNA *b)
 {
-	return (a->prop == b->prop && a->ptr.data == b->ptr.data) ? 0 : -1;
+	return ( (a->prop == b->prop) &&
+	         (a->ptr.data == b->ptr.data) &&
+	         (a->ptr.type == b->ptr.type) ) ? 0 : -1;
 }
 
 static PyObject *pyrna_struct_richcmp(PyObject *a, PyObject *b, int op)




More information about the Bf-blender-cvs mailing list