[Bf-python] Python Object.getArmatureIpos()

Willian Padovani Germano wgermano at ig.com.br
Sat Apr 3 06:51:20 CEST 2004


Hi Anders, welcome aboard : )

----- Original Message -----
From: "Anders Nilsson" <breakin at home.se>
To: <bf-python at blender.org>
Cc: <michel.s at home.nl>
Sent: Friday, April 02, 2004 8:26 PM
Subject: [Bf-python] Python Object.getArmatureIpos()


> Maybe this patch is better. It returns a dict with name:ipo-keys.
Either
> one works. There is one memory leak in both (mentioned in this one), I
> don't know how to fix that one (it's easy but I've only coded Blender
> for one day so please be patient).

Ref counting is tricky ... and Python has some idiosyncrasies that do
not help -- we need to check often the Python/C api to be sure.  I
usually leave it open at its index page, letter p.

Reading your patch, looks like the problem is that PyDict_SetItem
increfs both key and value objects passed to it.  Since you create and
then store them at a dict, their ref count reaches 2 for each object.
Try to decref after succesfully storing with PyDict_SetItem.  BTW: if
you use PyDict_SetItemString, you can pass the key as a char*, no need
to make it a PyString yourself.

I mean this:

+     PyObject *name_attr=Py_BuildValue ("s", first->name);
+     PyObject *ipo_attr=Ipo_CreatePyObject (first->ipo);
+
+     if (name_attr && ipo_attr) {
+      if (PyDict_SetItem (dict, name_attr,ipo_attr)!=0) {
+       return EXPP_ReturnPyObjError (PyExc_RuntimeError,
+         "Object_getArmatureIpos: couldn't set dict item");
+      }

// -> here decref both name_attr and ipo_attr.

+     } else {
+      // TODO: free the one that isn't null
+     }

And indeed this is a good catch, thanks Anders.  I'll check calls to
PyDict_SetItem*, we may have skipped that one.

--
Willian, wgermano at ig.com.br




More information about the Bf-python mailing list