[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [11460] trunk/blender/source/blender/ python/api2_2x: armature weakref fix from stable, Curve. c removed unneeded cruft

Campbell Barton cbarton at metavr.com
Wed Aug 1 14:57:59 CEST 2007


Revision: 11460
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=11460
Author:   campbellbarton
Date:     2007-08-01 14:57:59 +0200 (Wed, 01 Aug 2007)

Log Message:
-----------
armature weakref fix from stable, Curve.c removed unneeded cruft

Modified Paths:
--------------
    trunk/blender/source/blender/python/api2_2x/Armature.c
    trunk/blender/source/blender/python/api2_2x/Curve.c

Modified: trunk/blender/source/blender/python/api2_2x/Armature.c
===================================================================
--- trunk/blender/source/blender/python/api2_2x/Armature.c	2007-08-01 12:47:12 UTC (rev 11459)
+++ trunk/blender/source/blender/python/api2_2x/Armature.c	2007-08-01 12:57:59 UTC (rev 11460)
@@ -60,6 +60,10 @@
 static const char sModuleError[] = "Blender.Armature - Error: ";
 static const char sModuleBadArgs[] = "Blender.Armature - Bad Arguments: ";
 
+PyObject * arm_weakref_callback_weakref_dealloc(PyObject *self, PyObject *weakref);
+/* python callable */
+PyObject * arm_weakref_callback_weakref_dealloc__pyfunc;
+
 //################## BonesDict_Type (internal) ########################
 /*This is an internal psuedo-dictionary type that allows for manipulation
 * of bones inside of an armature. It is a subobject of armature.
@@ -118,18 +122,19 @@
 //-----------------(internal)
 static int BoneMapping_Init(PyObject *dictionary, ListBase *bones){
 	Bone *bone = NULL;
-	PyObject *py_bone = NULL, *str;
+	PyObject *py_bone = NULL;
 
 	for (bone = bones->first; bone; bone = bone->next){
 		py_bone = PyBone_FromBone(bone);
 		if (!py_bone)
 			return -1;
 		
-		str = PyString_FromString(bone->name);
-		if(PyDict_SetItem(dictionary, str, py_bone) == -1)
+		if(PyDict_SetItemString(dictionary, bone->name, py_bone) == -1) {
+			/* unlikely but possible */
+			Py_DECREF(py_bone);
 			return -1;
+		}
 		
-		Py_DECREF(str);
 		Py_DECREF(py_bone);
 		if (bone->childbase.first) 
 			BoneMapping_Init(dictionary, &bone->childbase);
@@ -139,18 +144,17 @@
 //-----------------(internal)
 static int EditBoneMapping_Init(PyObject *dictionary, ListBase *editbones){
 	EditBone *editbone = NULL;
-	PyObject *py_editbone = NULL, *str;
+	PyObject *py_editbone = NULL;
 
 	for (editbone = editbones->first; editbone; editbone = editbone->next){
 		py_editbone = PyEditBone_FromEditBone(editbone);
 		if (!py_editbone)
 			return -1;
 		
-		str = PyString_FromString(editbone->name);
-		if(PyDict_SetItem(dictionary, str, py_editbone) == -1)
+		if(PyDict_SetItemString(dictionary, editbone->name, py_editbone) == -1) {
+			Py_DECREF(py_editbone);
 			return -1;
-		
-		Py_DECREF(str);
+		}
 		Py_DECREF(py_editbone);
 	}
 	return 0;
@@ -242,17 +246,14 @@
 		value = PyDict_GetItem(self->bonesMap, key);
 	}
 	if(value == NULL){  /* item not found in dict. throw exception */
-		char buffer[128];
-		char* key_str;
-		key_str = PyString_AsString( key );
-		if( !key_str ){  /* key not a py string */
-			key_str = "";  /* use empty string for printing */
+		char* key_str = PyString_AsString( key );
+		if (key_str) {
+			return EXPP_ReturnPyObjError(PyExc_KeyError, "bone key must be a string" );
+		} else {
+			char buffer[128];
+			PyOS_snprintf( buffer, sizeof(buffer), "bone %s not found", key_str);
+			return EXPP_ReturnPyObjError(PyExc_KeyError, buffer );
 		}
-  
-		PyOS_snprintf( buffer, sizeof(buffer),
-					   "bone %s not found", key_str);
-			
-        return EXPP_ReturnPyObjError(PyExc_KeyError, buffer );
 	}
 	return EXPP_incr_ret(value);
 }
@@ -262,107 +263,98 @@
 {
 	BPy_EditBone *editbone_for_deletion;
 	struct EditBone *editbone = NULL;
-	char *key_str = "";
+	char *key_str = PyString_AsString(key);
 
-	if (self->editmode_flag){
-		//Get the key name
-		if(key && PyString_Check(key)){
-			key_str = PyString_AsString(key);
-		}else{
-			goto AttributeError;
-		}
-		//parse value for assignment
-		if (value && EditBoneObject_Check(value)){
-			//create a new editbone
-			editbone = MEM_callocN(sizeof(EditBone), "eBone");
-			BLI_strncpy(editbone->name, key_str, 32);
-			unique_editbone_name(NULL, editbone->name);
-			editbone->dist = ((BPy_EditBone*)value)->dist;
-			editbone->ease1 = ((BPy_EditBone*)value)->ease1;
-			editbone->ease2 = ((BPy_EditBone*)value)->ease2;
-			editbone->flag = ((BPy_EditBone*)value)->flag;
-			editbone->parent = ((BPy_EditBone*)value)->parent;
-			editbone->rad_head = ((BPy_EditBone*)value)->rad_head;
-			editbone->rad_tail = ((BPy_EditBone*)value)->rad_tail;
-			editbone->roll = ((BPy_EditBone*)value)->roll;
-			editbone->segments = ((BPy_EditBone*)value)->segments;
-			editbone->weight = ((BPy_EditBone*)value)->weight;
-			editbone->xwidth = ((BPy_EditBone*)value)->xwidth;
-			editbone->zwidth = ((BPy_EditBone*)value)->zwidth;
-			VECCOPY(editbone->head, ((BPy_EditBone*)value)->head);
-			VECCOPY(editbone->tail, ((BPy_EditBone*)value)->tail);
-			
-			// FIXME, should be exposed via python. this avoids creating bones with no layers.
-			editbone->layer= 1;
-			
-			//set object pointer
-			((BPy_EditBone*)value)->editbone = editbone;
+	if (!self->editmode_flag)
+		return EXPP_intError(PyExc_AttributeError, "%s%s", 
+				sBoneDictBadArgs,  "You must call makeEditable() first");
+	
+	if (!key_str)
+		return EXPP_intError(PyExc_AttributeError, "%s%s", 
+				sBoneDictBadArgs,  "The key must be the name of an editbone");
+	
+	if (value && !EditBoneObject_Check(value))
+		return EXPP_intError(PyExc_AttributeError, "%s%s",
+				sBoneDictBadArgs,  "Can only assign editbones as values");
+	
+	//parse value for assignment
+	if (value){ /* we know this must be an editbone from the above check */
+		//create a new editbone
+		editbone = MEM_callocN(sizeof(EditBone), "eBone");
+		BLI_strncpy(editbone->name, key_str, 32);
+		unique_editbone_name(NULL, editbone->name);
+		editbone->dist = ((BPy_EditBone*)value)->dist;
+		editbone->ease1 = ((BPy_EditBone*)value)->ease1;
+		editbone->ease2 = ((BPy_EditBone*)value)->ease2;
+		editbone->flag = ((BPy_EditBone*)value)->flag;
+		editbone->parent = ((BPy_EditBone*)value)->parent;
+		editbone->rad_head = ((BPy_EditBone*)value)->rad_head;
+		editbone->rad_tail = ((BPy_EditBone*)value)->rad_tail;
+		editbone->roll = ((BPy_EditBone*)value)->roll;
+		editbone->segments = ((BPy_EditBone*)value)->segments;
+		editbone->weight = ((BPy_EditBone*)value)->weight;
+		editbone->xwidth = ((BPy_EditBone*)value)->xwidth;
+		editbone->zwidth = ((BPy_EditBone*)value)->zwidth;
+		VECCOPY(editbone->head, ((BPy_EditBone*)value)->head);
+		VECCOPY(editbone->tail, ((BPy_EditBone*)value)->tail);
+		
+		// FIXME, should be exposed via python. this avoids creating bones with no layers.
+		editbone->layer= 1;
+		
+		//set object pointer
+		((BPy_EditBone*)value)->editbone = editbone;
 
-			//fix the bone's head position if flags indicate that it is 'connected'
-			if (editbone->flag & BONE_CONNECTED){
-				if(!editbone->parent){
-					((BPy_EditBone*)value)->editbone = NULL;
-					MEM_freeN(editbone);
-					goto AttributeError3;
-				}else{
-					VECCOPY(editbone->head, editbone->parent->tail);
-				}
+		//fix the bone's head position if flags indicate that it is 'connected'
+		if (editbone->flag & BONE_CONNECTED){
+			if(!editbone->parent){
+				((BPy_EditBone*)value)->editbone = NULL;
+				MEM_freeN(editbone);
+					return EXPP_intError(PyExc_AttributeError, "%s%s", 
+							sBoneDictBadArgs,  "The 'connected' flag is set but the bone has no parent!");
+			}else{
+				VECCOPY(editbone->head, editbone->parent->tail);
 			}
+		}
 
-			//set in editbonelist
-			BLI_addtail(&self->editbones, editbone);
+		//set in editbonelist
+		BLI_addtail(&self->editbones, editbone);
 
-			//set the new editbone in the mapping
-			if(PyDict_SetItemString(self->editbonesMap, key_str, value) == -1){
-				((BPy_EditBone*)value)->editbone = NULL;
-				BLI_freelinkN(&self->editbones, editbone);
-				goto RuntimeError;
+		//set the new editbone in the mapping
+		if(PyDict_SetItemString(self->editbonesMap, key_str, value) == -1){
+			((BPy_EditBone*)value)->editbone = NULL;
+			BLI_freelinkN(&self->editbones, editbone);
+			return EXPP_intError(PyExc_RuntimeError, "%s%s", 
+					sBoneDictError,  "Unable to access dictionary!");
+		}
+	}else {
+		//they are trying to delete the bone using 'del'
+		editbone_for_deletion = (BPy_EditBone*)PyDict_GetItem(self->editbonesMap, key);
+
+		if (!editbone_for_deletion)
+			return EXPP_intError(PyExc_KeyError, "%s%s%s%s", 
+					sBoneDictError,  "The key: ", key_str, " is not present in this dictionary!");
+
+		/*first kill the datastruct then remove the item from the dict
+		and wait for GC to pick it up.
+		We have to delete the datastruct here because the tp_dealloc
+		doesn't handle it*/
+		
+		/*this is ugly but you have to set the parent to NULL for else 
+		editbones_to_armature will crash looking for this bone*/
+		for (editbone = self->editbones.first; editbone; editbone = editbone->next){
+			if (editbone->parent == editbone_for_deletion->editbone) {
+				editbone->parent = NULL;
+				 /* remove the connected flag or else the 'root' ball
+				  * doesn't get drawn */
+				editbone->flag &= ~BONE_CONNECTED;
 			}
-		}else if(!value){
-			//they are trying to delete the bone using 'del'
-			if(PyDict_GetItem(self->editbonesMap, key) != NULL){
-				/*first kill the datastruct then remove the item from the dict
-				and wait for GC to pick it up.
-				We have to delete the datastruct here because the tp_dealloc
-				doesn't handle it*/
-				editbone_for_deletion = (BPy_EditBone*)PyDict_GetItem(self->editbonesMap, key);
-				/*this is ugly but you have to set the parent to NULL for else 
-				editbones_to_armature will crash looking for this bone*/
-				for (editbone = self->editbones.first; editbone; editbone = editbone->next){
-					if (editbone->parent == editbone_for_deletion->editbone) {
-						editbone->parent = NULL;
-						 /* remove the connected flag or else the 'root' ball
-						  * doesn't get drawn */
-						editbone->flag &= ~BONE_CONNECTED;
-					}
-				}
-				BLI_freelinkN(&self->editbones, editbone_for_deletion->editbone);
-				if(PyDict_DelItem(self->editbonesMap, key) == -1)
-					goto RuntimeError;
-			}else{
-				goto KeyError;
-			}
 		}
-		return 0;
-	}else{
-		goto AttributeError2;
+		BLI_freelinkN(&self->editbones, editbone_for_deletion->editbone);
+		if(PyDict_DelItem(self->editbonesMap, key) == -1)
+			return EXPP_intError(PyExc_RuntimeError, "%s%s", 
+					sBoneDictError,  "Unable to access dictionary!");
 	}
-
-KeyError:
-return EXPP_intError(PyExc_KeyError, "%s%s%s%s", 
-	    sBoneDictError,  "The key: ", key_str, " is not present in this dictionary!");
-RuntimeError:
-	return EXPP_intError(PyExc_RuntimeError, "%s%s", 
-		sBoneDictError,  "Unable to access dictionary!");
-AttributeError:
-	return EXPP_intError(PyExc_AttributeError, "%s%s", 
-		sBoneDictBadArgs,  "Expects EditboneType Object");
-AttributeError2:

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list