A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-dev/2017-September/149131.html below:

[Python-Dev] Inplace operations for PyLong objects

[Python-Dev] Inplace operations for PyLong objects [Python-Dev] Inplace operations for PyLong objectsChris Angelico rosuav at gmail.com
Fri Sep 1 17:12:13 EDT 2017
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
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4