[Cython] Bug, or changed array assignment in 0.17beta1?

Robert Bradshaw robertwb at gmail.com
Thu Jul 26 06:57:22 CEST 2012


On Wed, Jul 25, 2012 at 4:24 AM, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> mark florisson wrote:
>
>> I'm wondering, what was the original motivation to reuse temporaries?
>
> It goes back to Pyrex, where I didn't really give it much
> thought -- it just seemed like the tidiest thing to do.
> Once you have the logic to release temp references as soon
> as it's safe to do so, it's not much harder to return the
> variable to a pool as well.

Somewhat along the lines of what's been said, it also makes cleaning
up any temps (on exceptions or function exits) shorter too, as opposed
to what would be required if every temporary was its own variable.
This cleanup might interfere with the C compiler's ability to alias
the stack variables.

>> Do we ever have C++
>> stack-allocated object temporaries?
>
>
> Theoretically, yes --  temporaries aren't necessarily
> object references, they can be of any type (or they can
> in Pyrex, at least).

Same in Cython, including C++ stack-allocated objects (assuming a
zero-argument constructor), though in this latter case the scope can't
be restricted to less than the entire function body.

This actually relates to one of the annoying C++isms I've run into: an
untouched stack-allocated C++ object will be a "unused variable"
warning if and only if its constructors and destructors are
side-effect free.

- Robert


More information about the cython-devel mailing list