[Cython] Treatment of right-hand side after assignment

Robert Bradshaw robertwb at gmail.com
Sun Apr 9 02:00:23 EDT 2017


On Sun, Apr 2, 2017 at 9:42 AM, Clemens Hofreither <chofreither at gmail.com>
wrote:

> Hey all,
>
> (I hope this list isn't dead.)
>
> I'm reading up on the Cython codebase because I'm trying to implement
> a small feature (more on that later). There's one thing that really
> confuses me currently, and that's the distinction between
> generate_post_assignment_code and generate_disposal_code. From the
> comments, it appears that exactly one of these should be called, and
> which one it is depends on whether a reference from the rhs was
> absorbed into the lhs.
>
> So much for the theory, but in practice it seems to work differently.
> I'm looking at NameNode.generate_assignment_code() and
> IndexNode.generate_assignment_code(), which should do similar things
> (generate code for an assignment) except that the lhs has different
> structure.
>
> Yet they treat the cleanup of the rhs completely differently.
> IndexNode always calls rhs.generate_disposal_code. NameNode almost
> always calls rhs.generate_post_assignment_code.
>
> Can anyone shed light on why this cleanup is handled differently
> depending on the target of the assignment?


It's been a while since I've looked at this, but the best explanation is
that generate_post_assignment_code is used when the rhs is "moved" into the
lhs whereas generate_post_assignment_code is what happens for a "copy."
This is mostly relevant for temps, e.g. when a temp holds a reference to a
Python object, it can be transferred to the assignee (e.g. with NameNodes)
or a new reference can be created for the assignee (e.g. with IndexNodes)
which changes whether the temp lhs needs to be decref'ed.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cython-devel/attachments/20170408/219addff/attachment.html>


More information about the cython-devel mailing list