[Python-Dev] Inplace operations for PyLong objects
Chris Angelico
rosuav at gmail.com
Fri Sep 1 17:12:13 EDT 2017
More information about the Python-Dev mailing list
Fri Sep 1 17:12:13 EDT 2017
- Previous message (by thread): [Python-Dev] Inplace operations for PyLong objects
- Next message (by thread): [Python-Dev] Inplace operations for PyLong objects
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Sat, Sep 2, 2017 at 6:35 AM, Joe Jevnik via Python-Dev <python-dev at python.org> wrote: > Is it true that checking for refcount == 1 is enough? What if a user wrote: > > args = (compute_integer(), 5) > # give away args to someone > int.__iadd__(*args) > > here `args[0]` still has refcount=1 because only `args` owns this integer. This particular example is safe, because the arguments get passed individually - so 'args' has one reference, plus there's one more for the actual function call (what would be 'self' if it were implemented in Python). There may be other examples that are more dangerous, but my suspicion is that the nature of += with anything other than a simple name will defeat the optimization, since the owning collection will retain a reference until __iadd__ returns. ChrisA
- Previous message (by thread): [Python-Dev] Inplace operations for PyLong objects
- Next message (by thread): [Python-Dev] Inplace operations for PyLong objects
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-Dev mailing list