homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: [C API] stable_abi.py script must not include PyType_HasFeature() static inline function in the stable ABI
Type: Stage: resolved
Components: C API Versions: Python 3.10
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: pablogsal, petr.viktorin, vstinner
Priority: normal Keywords: patch

Created on 2021年04月01日 09:37 by vstinner, last changed 2022年04月11日 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 25136 merged vstinner, 2021年04月01日 10:38
Messages (4)
msg389964 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021年04月01日 09:37
I just ran "make regen-limited-abi" and it added PyType_HasFeature():
commit baf10da75072d1f8ec714d3c2c8550d34db343a9
Author: Victor Stinner <vstinner@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 ;-)
msg389976 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021年04月01日 12:14
New changeset 61092a99c4840f36dbde8457cb566fc3c012930f by Victor Stinner in branch 'master':
bpo-43690: stable_abi.py no longer parses macros (GH-25136)
https://github.com/python/cpython/commit/61092a99c4840f36dbde8457cb566fc3c012930f
msg389977 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021年04月01日 12:16
Pablo: My previous commit added PyType_HasFeature to Doc/data/stable_abi.dat. But it prevented me to fix another bug, PR 25135. So I merged this change (PR 25136) to unblock the CI. Feel free to revert/adjust my change as soon as it doesn't add PyType_HasFeature back into Doc/data/stable_abi.dat :-)
msg389978 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021年04月01日 12:20
Oh, I forgot the mention "Tests / Check if generated files are up to date" job error message:
LD_LIBRARY_PATH=/home/runner/work/cpython/cpython:/opt/hostedtoolcache/Python/3.9.2/x64/lib ./python ./Tools/scripts/stable_abi.py check ./Doc/data/stable_abi.dat
Some symbols from the limited API are missing: PyType_HasFeature
This error means that there are some missing symbols among the ones exported
in the Python library ("libpythonx.x.a" or "libpythonx.x.so"). This normally
means that some symbol, function implementation or a prototype, belonging to
a symbol in the limited API has been deleted or is missing.
Check if this was a mistake and if not, update the file containing the limited
API symbols. This file is located at:
./Doc/data/stable_abi.dat
You can read more about the limited API and its contracts at:
https://docs.python.org/3/c-api/stable.html
And in PEP 384:
https://www.python.org/dev/peps/pep-0384/ 
History
Date User Action Args
2022年04月11日 14:59:43adminsetgithub: 87856
2021年04月01日 12:20:27vstinnersetmessages: + msg389978
2021年04月01日 12:16:45vstinnersetstatus: open -> closed
resolution: fixed
messages: + msg389977

stage: patch review -> resolved
2021年04月01日 12:14:08vstinnersetmessages: + msg389976
2021年04月01日 10:38:38vstinnersetkeywords: + patch
stage: patch review
pull_requests: + pull_request23883
2021年04月01日 09:37:33vstinnercreate

AltStyle によって変換されたページ (->オリジナル) /