New submission from STINNER Victor <vstin...@python.org>:

I just ran "make regen-limited-abi" and it added PyType_HasFeature():

commit baf10da75072d1f8ec714d3c2c8550d34db343a9
Author: Victor Stinner <vstin...@python.org>
Date:   Thu Apr 1 11:29:46 2021 +0200

    bpo-43688: Run make regen-limited-abi (GH-25134)

diff --git a/Doc/data/stable_abi.dat b/Doc/data/stable_abi.dat
index 3adee103bc..ed20521b7f 100644
--- a/Doc/data/stable_abi.dat
+++ b/Doc/data/stable_abi.dat
@@ -192,6 +192,7 @@ PyExc_ConnectionRefusedError
 PyExc_ConnectionResetError
 PyExc_DeprecationWarning
 PyExc_EOFError
+PyExc_EncodingWarning
 PyExc_EnvironmentError
 PyExc_Exception
 PyExc_FileExistsError
@@ -615,6 +616,7 @@ PyType_GetFlags
 PyType_GetModule
 PyType_GetModuleState
 PyType_GetSlot
+PyType_HasFeature
 PyType_IsSubtype
 PyType_Modified
 PyType_Ready


The problem is that PyType_HasFeature() is currently implemented as a static 
inline function in the limited C API for best performance.

Issue about PyType_HasFeature() performance in CPython itself:
https://bugs.python.org/issue39542#msg372962

Currently, PyType_HasFeature() is declared in Include/object.h as:

static inline int
PyType_HasFeature(PyTypeObject *type, unsigned long feature)
{
    unsigned long flags;
#ifdef Py_LIMITED_API
    // PyTypeObject is opaque in the limited C API
    flags = PyType_GetFlags(type);
#else
    flags = type->tp_flags;
#endif
    return ((flags & feature) != 0);
}

IMO static inline functions must not be listed in the stable *ABI*. At the ABI 
level, libpython doesn't export "PyType_HasFeature" symbol:

$ objdump -T /lib64/libpython3.10.so.1.0|grep '\<PyObject_CallFunction\>'
00000000000fedf0 g    DF .text  00000000000000d0  Base        
PyObject_CallFunction
$ objdump -T /lib64/libpython3.10.so.1.0|grep '\<PyType_HasFeature\>'
# nothing

"PyObject_CallFunction" symbol is exported, but not "PyType_HasFeature".

--

Maybe for the stable ABI, it would be a good idea to export PyType_HasFeature() 
as an opaque function. But that's out of the scope of this issue which is about 
the stable_abi.py script ;-)

----------
components: C API
messages: 389964
nosy: pablogsal, petr.viktorin, vstinner
priority: normal
severity: normal
status: open
title: [C API] stable_abi.py script must not include PyType_HasFeature() static 
inline function in the stable ABI
versions: Python 3.10

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue43690>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to