[Bf-python] bug in Camera.c

Willian Padovani Germano wgermano at ig.com.br
Sun Jun 8 21:16:13 CEST 2003


On Sat, 2003-06-07 at 07:38, Jacques Guignot wrote:
(...)
> The "dangerous" line is  at the end of static int CameraSetAttr 
> (C_Camera *self, char *name, PyObject *value)
> when you do a  Py_DECREF(valtuple)  (the last  Py_DECREF, not the one
in 
> the if )

Good catch, Guignot : ).  The problem was in

Py_BuildValue("(N)", value);

Instead of 'N', I should've used 'O'.  'N' doesn't incref's value. It
should be fixed now, in all modules where it appeared.  Making a test,
the example script you sent worked fine with dozens of Alt+P's in a row.

> I'm not very good in ref counting, and Python is somehow strange with 
> that (never understood why PyNone should be incref or decrefd for
> instance!)

Yes, ref counting is tricky, but we can only dive and fight till it
becomes (hopefully one day ...) second nature.  PyNone ... yes, that
sure looks stupid (specially because it will -- or at least should --
never be deallocated), but I ended up decref'ing it because the docs
tell us to treat it just like any other PyObject in relation to ref
counting.  So I confirmed that Py_DECREF(Py_None) appeared in some good
pieces of code around the net, and decided to try.

Thanks again : ),  I'll update cvs today or tomorrow.

--
Willian, wgermano at ig.com.br




More information about the Bf-python mailing list