[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [11148] branches/pyapi_devel/source/ blender/python/api2_2x/layer_set.c: layer sets wernt updating because the PyObject_GetIter was calling an alredy wrapped function that copied the layer back to the set , this stopped the set from updating the layer is it was supposed to.

Campbell Barton cbarton at metavr.com
Tue Jul 3 08:48:49 CEST 2007


Revision: 11148
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=11148
Author:   campbellbarton
Date:     2007-07-03 08:48:48 +0200 (Tue, 03 Jul 2007)

Log Message:
-----------
layer sets wernt updating because the PyObject_GetIter was calling an alredy wrapped function that copied the layer back to the set, this stopped the set from updating the layer is it was supposed to.

Modified Paths:
--------------
    branches/pyapi_devel/source/blender/python/api2_2x/layer_set.c

Modified: branches/pyapi_devel/source/blender/python/api2_2x/layer_set.c
===================================================================
--- branches/pyapi_devel/source/blender/python/api2_2x/layer_set.c	2007-07-03 01:23:30 UTC (rev 11147)
+++ branches/pyapi_devel/source/blender/python/api2_2x/layer_set.c	2007-07-03 06:48:48 UTC (rev 11148)
@@ -61,35 +61,45 @@
 	}\
 	return ret;
 
-/* checks the set before returning,
+/* This is used to return from the value from an internal
+ * python set function.
+ * 
+ * Only use this in a PyC function that returns a (PyObject *)
+ * 
+ * If _ret is NULL it means that the there was an error.
+ * 
+ * If sync_layer_from_set__internal is zero it means that the set was not compatible
+ * with layers.
+ *  
+ * This checks the set before returning,
  * raises an error and reverts if the set
  * contains ints that cant be used as layers */
 #define LAYSEQ_RET_ERRORCHECK(_self, _ret) \
-	if (_ret && !sync_layer_from_set__internal(_self))\
+	if (!_ret || !sync_layer_from_set__internal(_self))\
 			return ( EXPP_ReturnPyObjError( PyExc_ValueError,\
 					"Unsupported values for a layer in this set." ) );\
 	return _ret;
 
 
 /* store these methods so we dont have to lookup the list methods each time */
-static const PyObject * CONST_PySet_add;
-static const PyObject * CONST_PySet_clear;
-static const PyObject * CONST_PySet_contains;
-static const PyObject * CONST_PySet_copy;
-static const PyObject * CONST_PySet_discard;
-static const PyObject * CONST_PySet_difference;
-static const PyObject * CONST_PySet_difference_update;
-static const PyObject * CONST_PySet_intersection;
-static const PyObject * CONST_PySet_intersection_update;
-static const PyObject * CONST_PySet_issubset;
-static const PyObject * CONST_PySet_issuperset;
-static const PyObject * CONST_PySet_pop;
-static const PyObject * CONST_PySet_reduce;
-static const PyObject * CONST_PySet_remove;
-static const PyObject * CONST_PySet_symmetric_difference;
-static const PyObject * CONST_PySet_symmetric_difference_update;
-static const PyObject * CONST_PySet_union;
-static const PyObject * CONST_PySet_update;
+PyObject * CONST_PySet_add;
+PyObject * CONST_PySet_clear;
+PyObject * CONST_PySet_contains;
+PyObject * CONST_PySet_copy;
+PyObject * CONST_PySet_discard;
+PyObject * CONST_PySet_difference;
+PyObject * CONST_PySet_difference_update;
+PyObject * CONST_PySet_intersection;
+PyObject * CONST_PySet_intersection_update;
+PyObject * CONST_PySet_issubset;
+PyObject * CONST_PySet_issuperset;
+PyObject * CONST_PySet_pop;
+PyObject * CONST_PySet_reduce;
+PyObject * CONST_PySet_remove;
+PyObject * CONST_PySet_symmetric_difference;
+PyObject * CONST_PySet_symmetric_difference_update;
+PyObject * CONST_PySet_union;
+PyObject * CONST_PySet_update;
 
 void id_set_layer(ID *id, int lay) {
 	/* only care about types that can have materials */
@@ -141,7 +151,7 @@
 
 static void sync_set_from_layer__internal(BPy_LayerSet *self)
 {
-	int bit, layer;
+	int bit, layer= 0;
 
 	PyObject *pyob;
 	ID *id;
@@ -170,16 +180,22 @@
 	ID *id;
 	int bit, layer = 0;
 	
-	if (!self->genlib || !self->genlib->id)
-		return 0;
+	if (!self->genlib)
+		return 1; /* not wrapped so this is ok */
 	
 	id = self->genlib->id;
-	layer = layer_from_id(id);
 	
-	iter = PyObject_GetIter((PyObject *)self);
+	if (!id)
+		return 0;
 	
-	item = PyIter_Next(iter);
-	while (item) {
+	/* we cant use PyObject_GetIter because that runs
+	 * our own wrapped iter function and 
+	 * overwrites this set from the layer */
+	/*iter = PyObject_GetIter((PyObject *)self);*/
+	iter = PySet_Type.tp_iter((PyObject *)self);
+	
+	while ((item = PyIter_Next(iter)) != NULL) {
+		
 		/* type checking is alredy been done! */
 		if (!PyInt_Check(item)) {
 			Py_DECREF(item);
@@ -189,16 +205,16 @@
 		}
 		
 		bit = PyInt_AS_LONG(item)-1;
-		Py_DECREF(item);
 		
 		if (!LAYSEQ_COMPAT_INT_BLEN(bit)) {
 			Py_DECREF(iter);
+			Py_DECREF(item);
 			sync_set_from_layer__internal(self); /* revert */
 			return 0;
 		}		
 		
-		layer |= 1<<(bit-1); 
-		item = PyIter_Next(iter);
+		layer |= 1<<bit; 
+		Py_DECREF(item);
 	}
 	Py_DECREF(iter);
 	





More information about the Bf-blender-cvs mailing list