[Python-Dev] Py_CLEAR and assigning values
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
> > variables and doing the Py_DECREF's just before returning. That way,
> > 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...
More information about the Python-Dev