[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [11833] branches/2-44-stable/blender/ source/blender/python/api2_2x/Armature.c: 11832 - armature weakref fix from trunk

Campbell Barton cbarton at metavr.com
Sat Aug 25 21:09:42 CEST 2007


Revision: 11833
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=11833
Author:   campbellbarton
Date:     2007-08-25 21:09:42 +0200 (Sat, 25 Aug 2007)

Log Message:
-----------
11832 - armature weakref fix from trunk

Modified Paths:
--------------
    branches/2-44-stable/blender/source/blender/python/api2_2x/Armature.c

Modified: branches/2-44-stable/blender/source/blender/python/api2_2x/Armature.c
===================================================================
--- branches/2-44-stable/blender/source/blender/python/api2_2x/Armature.c	2007-08-25 19:05:18 UTC (rev 11832)
+++ branches/2-44-stable/blender/source/blender/python/api2_2x/Armature.c	2007-08-25 19:09:42 UTC (rev 11833)
@@ -1306,6 +1306,9 @@
 		Py_RETURN_NONE;
 	}
 	PySequence_DelItem(armlist, i);
+	
+	/*PyObject_Print(	armlist, stderr, 0);*/
+	
 	Py_RETURN_NONE;
 }
 
@@ -1318,7 +1321,28 @@
 	PyObject *maindict = NULL, *weakref = NULL;
 	PyObject *armlist = NULL;  /* list of armature weak refs */
 	char *list_name = ARM_WEAKREF_LIST_NAME;
+	int i;
 
+	//put a weakreference in __main__
+	maindict= PyModule_GetDict(PyImport_AddModule(	"__main__"));
+
+	armlist = PyDict_GetItemString(maindict, list_name);
+	if(!armlist) {
+		printf("Oops - can't get the armature weakref list\n");
+		goto RuntimeError;
+	}
+
+	/* see if we alredy have it */
+	for (i=0; i< PyList_Size(armlist); i++) { 
+		py_armature = (BPy_Armature *)PyWeakref_GetObject(PyList_GET_ITEM(armlist, i));
+		if (BPy_Armature_Check(py_armature) && py_armature->armature == armature) {
+			Py_INCREF(py_armature);
+			/*printf("reusing armature\n");*/
+			return (PyObject *)py_armature;
+		}
+	}
+
+	
 	/*create armature type*/
 	py_armature = PyObject_NEW( BPy_Armature, &Armature_Type );
 	
@@ -1336,19 +1360,13 @@
 		printf("Oops - creating armature.bones\n");
 		goto RuntimeError;
 	}
-
-	//put a weakreference in __main__
-	maindict= PyModule_GetDict(PyImport_AddModule(	"__main__"));
-
-	armlist = PyDict_GetItemString(maindict, list_name);
-	if( armlist){
-		weakref = PyWeakref_NewProxy((PyObject*)py_armature, arm_weakref_callback_weakref_dealloc__pyfunc);
-		if (PyList_Append(armlist, weakref) == -1){
-			printf("Oops - list-append failed\n");
-			goto RuntimeError;
-		}
-		Py_DECREF(weakref);
+	
+	weakref = PyWeakref_NewProxy((PyObject*)py_armature, arm_weakref_callback_weakref_dealloc__pyfunc);
+	if (PyList_Append(armlist, weakref) == -1){
+		printf("Oops - list-append failed\n");
+		goto RuntimeError;
 	}
+	Py_DECREF(weakref);
 
 	return (PyObject *) py_armature;
 





More information about the Bf-blender-cvs mailing list