On 07. 02. 22 15:29, Victor Stinner wrote:
On Mon, Feb 7, 2022 at 2:26 PM Victor Stinner <vstinner@python.org> wrote:
CPython is also affected by these issues, but the benefits of PEP 674 (alone) are too indirect, so I chose to avoid mentioning CPython issues directly, to avoid confusion.
A concrete example of problem caused by exposing structures in the C API (unrelated to PEP 674). It's a tricky problem...
typedef struct { PyObject_VAR_HEAD Py_hash_t ob_shash; char ob_sval[1]; } PyBytesObject;
The "char ob_sval[1];" syntax used to declare an array is an undefined behavior if the array is longer in memory. On a bytes object of 4 bytes, accessing ob_sval[3] works, but is an undefined behavior.
=> see https://bugs.python.org/issue40120 for details
The problem can be solved by using "char ob_sval[];" syntax, but we cannot use this syntax in the public C header, since it causes compiler errors if the header is built with a C++ compiler (not to build Python itself, but build a C++ extension using the Python C API). Removing the structure from the public C API would solve the C++ issue.
That sounds like a good candidate for deprecation, and adding proper getters if we didn't have them. But I don't think we actually need to remove the deprecated struct from the public C API.