On Mar 12, 2020, at 12:02, Marco Sulla <mail.python....@marco.sulla.e4ward.com> 
wrote:
> 
> On Thu, 12 Mar 2020 at 19:52, Andrew Barnert
> <abarn...@yahoo.com.via.e4ward.com> wrote:
>> I suppose it could track calls out to C functions as they happen and mark 
>> every value that was live before the call, and then instead of numpy 
>> checking refs==1 is could check refs==1 && !c_flagged, and then it wouldn’t 
>> need the C frame hackery. But that seems like it would slow down everything 
>> in exchange for occasionally helping numpy and a few other C extension libs.
> 
> The author of the patch says this is already implemented in string
> concatenation in Python itself. Maybe we should look at the
> implementation, but I don't know where and what to search.

Strings, unlike numpy arrays, are immutable. (You can’t mutate them from 
Python; you can mutate them from the C API but it’s against the rules to do so 
after they’ve been shared with the interpreter.) And strings, unlike numbers 
(which numpy arrays act as), don’t have any C API functions that steal 
references. So they don’t require any kind of tracking or stack-fumbling.

For a simpler parallel: the CPython compiler can merge two strings into a 
single object, and the CPython interpreter can intern strings at runtime, 
because this is guaranteed to be safe, but obviously neither can do the same 
thing for arbitrary objects.

_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/Y5JNE2MCTCQMKJCXWOZFFKGWOBA6Q3HY/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to