[Python-Dev] Inplace operations for PyLong objects

Joe Jevnik jjevnik at quantopian.com
Fri Sep 1 16:35:41 EDT 2017


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.

On Fri, Sep 1, 2017 at 4:19 PM, Jelle Zijlstra <jelle.zijlstra at gmail.com>
wrote:

>
>
> 2017-09-01 13:05 GMT-07:00 Chris Barker <chris.barker at noaa.gov>:
>
>> On Thu, Aug 31, 2017 at 5:12 PM, Antoine Pitrou <solipsis at pitrou.net>
>> wrote:
>>
>>> I'm skeptical there are some programs out there that are limited by the
>>> speed of PyLong inplace additions.
>>>
>>
>> indeed, but that could be said about any number of operations.
>>
>> My question is -- how can the interpreter know if it can alter what is
>> supposed to be an immutable in-place? If it's used only internally to a
>> function, the it would be safe, but how to know that?
>>
> I believe Catalin's implementation checks if the object's refcount is 1.
> If that is the case, it is safe to mutate it.
>
>>
>> -CHB
>>
>>
>>
>> --
>>
>> Christopher Barker, Ph.D.
>> Oceanographer
>>
>> Emergency Response Division
>> NOAA/NOS/OR&R            (206) 526-6959   voice
>> 7600 Sand Point Way NE   (206) 526-6329   fax
>> Seattle, WA  98115       (206) 526-6317   main reception
>>
>> Chris.Barker at noaa.gov
>>
>> _______________________________________________
>> Python-Dev mailing list
>> Python-Dev at python.org
>> https://mail.python.org/mailman/listinfo/python-dev
>> Unsubscribe: https://mail.python.org/mailman/options/python-dev/jelle.
>> zijlstra%40gmail.com
>>
>>
>
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> https://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe: https://mail.python.org/mailman/options/python-dev/
> joe%40quantopian.com
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20170901/ccb27cad/attachment.html>


More information about the Python-Dev mailing list