[Python-Dev] Py_CLEAR and assigning values

Daniel Stutzbach daniel at stutzbachenterprises.com
Wed Aug 6 05:00:38 CEST 2008


On Tue, Aug 5, 2008 at 4:30 PM, Paul Pogonyshev <pogonyshev at gmx.net> wrote:

> > Generally, I end up storing all the objects to be Py_DECREF'd in
> temporary
> > variables and doing the Py_DECREF's just before returning.  That way,
> "self"
> > is never in an inconsistent state.
>
> Right.  But wouldn't it be easier if there was a standard Python macro
> for this, sort of like proposed Py_ASSIGN?
>

If you're modifying exactly one property in the C function, yes.

In my C code, when I modifying an object I usually need to modifying many of
the properties which means that I need to delay all of the Py_DECREF's until
just before returning.  The Py_ASSIGN macro that you propose would not
achieve this.  If I used Py_ASSIGN, all the pointers would point to valid
objects, true, but the object might not be in a consistent state.

If in your code you frequently need to modifying just one property, you are
certainly free to create your own macro. :-)

--
Daniel Stutzbach, Ph.D.
President, Stutzbach Enterprises, LLC <http://stutzbachenterprises.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20080805/b5847812/attachment.htm>


More information about the Python-Dev mailing list