4 ms·
Why is that array not const in the Cpython code?
by rep_movsd 3y ago
Why is that array not const in the Cpython code?
- aflag 3y agoThat wouldn't make a difference in this case, would it? I suppose it would mean that the code would be UB, but in practice it'd just work the same.
- ynik 3y agoBecause every Python object also contains a reference count (which needs to be modified whenever the object is passed around), a `const PyObject*` is effectively useless.
- deleted 3y ago[deleted]
- colejohnson66 3y agoBut we’re talking about an integer cache. It’s full of singletons; Why do they need to have reference counts?
- t-vi 3y agoThis special casing just had not been implemented yet. But as it is an interesting optimization, more so with multi-interpreter or no-GIL Python, the developers will actually introduce immortal objects in Python 3.12 to avoid counting references on some objects (PEP 683 has been accepted): https://peps.python.org/pep-0683/ https://peps.python.org/pep-0683/