A RetroSearch Logo

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

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2017-May/147831.html below:

[Python-Dev] Guarantee the success of some object creation C API functions

[Python-Dev] Guarantee the success of some object creation C API functionsSerhiy Storchaka storchaka at gmail.com
Tue May 2 01:49:41 EDT 2017
On 02.05.17 00:52, Chris Angelico wrote:
> Aside from straight-up bugs, how can one of these functions fail? Is
> memory allocation failure the only way?

Yes, memory allocation failure is the only way. In normal Python build 
this can happen only at early stage of the interpreter initialization, 
until the first call of the function allocate a singleton in dynamic 
memory, or, for some instances, at late stage of the interpreter 
finalization after deallocating singletons. In custom Python build with 
disabled free lists for small ints, tuples, etc (if define NSMALLPOSINTS 
or PyTuple_MAXSAVESIZE to 0) this can happen at any time.

> Incidentally, this guarantee, if implemented the obvious way, will
> also mean that (), "", 0, etc are singletons. People talk casually
> about the "empty tuple singleton", but I don't think it's actually
> guaranteed anywhere.

As noted Nick this guarantee doesn't go so far. With C API you can 
modify just created tuple in-place and set its size to 0. This gives you 
an empty tuple different from the "empty tuple singleton". Some C API 
functions actually can return non-singletons equal to singleton objects, 
but usually we try to avoid this. Not because there are any guaranties, 
but for optimization. References to singletons consume less memory and 
compare faster.


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