[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [11459] branches/2-44-stable/blender/ source/blender/python/api2_2x: * - Armature.Get() in a loop would never free memory.
Campbell Barton
cbarton at metavr.com
Wed Aug 1 14:47:12 CEST 2007
Revision: 11459
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=11459
Author: campbellbarton
Date: 2007-08-01 14:47:12 +0200 (Wed, 01 Aug 2007)
Log Message:
-----------
* - Armature.Get() in a loop would never free memory.
it would never dealloc its weakref
added a weakref callback that removes the weakref from the weakref list.
* Curve append fixes that were commited before but removed for rc1.
* small changes from Trunk - remove unneeded checks.
Modified Paths:
--------------
branches/2-44-stable/blender/source/blender/python/api2_2x/Armature.c
branches/2-44-stable/blender/source/blender/python/api2_2x/BezTriple.c
branches/2-44-stable/blender/source/blender/python/api2_2x/Camera.c
branches/2-44-stable/blender/source/blender/python/api2_2x/Curve.c
branches/2-44-stable/blender/source/blender/python/api2_2x/Text.c
branches/2-44-stable/blender/source/blender/python/api2_2x/Window.c
branches/2-44-stable/blender/source/blender/python/api2_2x/World.c
branches/2-44-stable/blender/source/blender/python/api2_2x/bpy_config.c
branches/2-44-stable/blender/source/blender/python/api2_2x/doc/Draw.py
branches/2-44-stable/blender/source/blender/python/api2_2x/gen_utils.c
branches/2-44-stable/blender/source/blender/python/api2_2x/point.c
branches/2-44-stable/blender/source/blender/python/api2_2x/rgbTuple.c
branches/2-44-stable/blender/source/blender/python/api2_2x/sceneSequence.h
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-01 11:38:47 UTC (rev 11458)
+++ branches/2-44-stable/blender/source/blender/python/api2_2x/Armature.c 2007-08-01 12:47:12 UTC (rev 11459)
@@ -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.
@@ -124,11 +128,13 @@
py_bone = PyBone_FromBone(bone);
if (!py_bone)
return -1;
-
- if(PyDict_SetItem(dictionary,
- PyString_FromString(bone->name), py_bone) == -1){
+
+ if(PyDict_SetItemString(dictionary, bone->name, py_bone) == -1) {
+ /* unlikely but possible */
+ Py_DECREF(py_bone);
return -1;
}
+
Py_DECREF(py_bone);
if (bone->childbase.first)
BoneMapping_Init(dictionary, &bone->childbase);
@@ -144,9 +150,9 @@
py_editbone = PyEditBone_FromEditBone(editbone);
if (!py_editbone)
return -1;
-
- if(PyDict_SetItem(dictionary,
- PyString_FromString(editbone->name), py_editbone) == -1){
+
+ if(PyDict_SetItemString(dictionary, editbone->name, py_editbone) == -1) {
+ Py_DECREF(py_editbone);
return -1;
}
Py_DECREF(py_editbone);
@@ -215,7 +221,7 @@
Py_DECREF(self->bonesMap);
Py_DECREF(self->editbonesMap);
BLI_freelistN(&self->editbones);
- BonesDict_Type.tp_free(self);
+ PyObject_DEL( self );
return;
}
//------------------------mp_length
@@ -240,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);
}
@@ -260,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:
- return EXPP_intError(PyExc_AttributeError, "%s%s",
- sBoneDictBadArgs, "You must call makeEditable() first");
-AttributeError3:
- return EXPP_intError(PyExc_AttributeError, "%s%s",
- sBoneDictBadArgs, "The 'connected' flag is set but the bone has no parent!");
+ return 0;
}
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list