Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-133143: Make information about the interpreter ABI more accessible#137476

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
encukou merged 28 commits intopython:mainfromzklaus:add-sys.abi_info
Sep 8, 2025
Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
Show all changes
28 commits
Select commitHold shift + click to select a range
2e3e54a
Add sys.abi_info
zklausAug 1, 2025
2ddafa4
📜🤖 Added by blurb_it.
blurb-it[bot]Aug 6, 2025
cdc50c3
Simplify pointer_bits handling
zklausAug 7, 2025
6fb25a3
Remove explicit C API function
zklausAug 7, 2025
4c3d83d
Make abi_info object a simple namespace with no explicit C API
zklausAug 7, 2025
820e002
Cleanup scaffolding
zklausAug 7, 2025
918521f
Fix make_abi_info to be static
zklausAug 7, 2025
7863651
Add test
zklausAug 12, 2025
81d75fc
Fix test
zklausAug 12, 2025
41027a3
Add link
zklausAug 14, 2025
56726ab
Rename attributes
zklausAug 14, 2025
94b7f40
Add better attribute specification to docs
zklausAug 21, 2025
6887d6c
Base `debug` on Py_REF_DEBUG
zklausAug 21, 2025
7ced683
Add byteorder
zklausAug 21, 2025
cc5ae8c
Fix test
zklausAug 21, 2025
5c18587
Improve error message in test
zklausAug 21, 2025
d025d17
Apply suggestions from code review
zklausSep 2, 2025
a089371
Revert "Base `debug` on Py_REF_DEBUG"
zklausSep 2, 2025
44ce7c7
Add whatsnew entry for improved sys module
zklausSep 2, 2025
8f57f17
Update Python/sysmodule.c
zklausSep 3, 2025
77f7b9b
Integrate suggestions from Adam Turner
zklausSep 3, 2025
312bff1
Add Windows configuration equivalents
zklausSep 4, 2025
ed7b6d9
Fix rst lint
zklausSep 4, 2025
15f065a
Use Sphinx markup for attributes
encukouSep 5, 2025
151eb4c
Merge pull request #3 from encukou/add-sys.abi_info
zklausSep 8, 2025
9f5ffae
Merge branch 'main' into add-sys.abi_info
AA-TurnerSep 8, 2025
128b150
Don't use ReST in a C comment
encukouSep 8, 2025
0506533
docs rephrasing
AA-TurnerSep 8, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
NextNext commit
Add sys.abi_info
  • Loading branch information
@zklaus
zklaus committedSep 3, 2025
commit2e3e54a84cff8075e1c50b51bb0a4c8572407ccd
1 change: 1 addition & 0 deletionsDoc/data/stable_abi.dat
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

25 changes: 25 additions & 0 deletionsDoc/library/sys.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,6 +11,31 @@ interpreter and to functions that interact strongly with the interpreter. It is
always available. Unless explicitly noted otherwise, all variables are read-only.


.. data:: abi_info

A :term:`named tuple` holding information about the ABI of the interpreter.

.. attribute:: abi_info.pointer_bits

The width of pointers in bits, as an integer.

* ``32``: 32-bit build
* ``64``: 64-bit build
* ``None`` if this information is unknown or neither 32 nore 64 bits.

.. attribute:: abi_info.Py_GIL_DISABLED

A boolean indicating whether the interpreter was built in with the GIL
disabled, i.e. with the :option:`--disable-gil` option, aka free-threading.

.. attribute:: abi_info.Py_DEBUG

A boolean indicating whether the interpreter was built in debug mode,
i.e. with the :option:`--with-pydebug` option.

.. versionadded:: next


.. data:: abiflags

On POSIX systems where Python was built with the standard ``configure``
Expand Down
1 change: 1 addition & 0 deletionsInclude/Python.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -147,6 +147,7 @@ __pragma(warning(disable: 4201))
#include "fileutils.h"
#include "cpython/pyfpe.h"
#include "cpython/tracemalloc.h"
#include "pyabiinfo.h"

#ifdef _MSC_VER
__pragma(warning(pop)) // warning(disable: 4201)
Expand Down
13 changes: 13 additions & 0 deletionsInclude/internal/pycore_abiinfo.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
#ifndef Py_INTERNAL_ABIINFO_H
#define Py_INTERNAL_ABIINFO_H
#ifdef __cplusplus
extern "C" {
#endif

extern PyStatus _PyAbiInfo_InitTypes(PyInterpreterState *);
extern void _PyAbiInfo_FiniTypes(PyInterpreterState *interp);

#ifdef __cplusplus
}
#endif
#endif /* !Py_INTERNAL_ABIINFO_H */
15 changes: 15 additions & 0 deletionsInclude/pyabiinfo.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
#ifndefPy_PYABIINFO_H
#definePy_PYABIINFO_H

#ifdef__cplusplus
extern"C" {
#endif

#if !defined(Py_LIMITED_API)||Py_LIMITED_API+0 >=0x030F0000
PyAPI_FUNC(PyObject*)PyAbiInfo_GetInfo(void);
#endif

#ifdef__cplusplus
}
#endif
#endif/* !Py_PYABIINFO_H */
1 change: 1 addition & 0 deletionsLib/test/_test_embed_structseq.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -25,6 +25,7 @@ def check_structseq(self, obj_type):

def test_sys_attrs(self):
for attr_name in (
'abi_info', # AbiInfoType
'flags', # FlagsType
'float_info', # FloatInfoType
'hash_info', # Hash_InfoType
Expand Down
1 change: 1 addition & 0 deletionsLib/test/test_stable_abi_ctypes.py
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

1 change: 1 addition & 0 deletionsMakefile.pre.in
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -423,6 +423,7 @@ PYTHON_OBJS=\
Python/_warnings.o \
Python/Python-ast.o \
Python/Python-tokenize.o \
Python/abiinfo.o \
Python/asdl.o \
Python/assemble.o \
Python/ast.o \
Expand Down
2 changes: 2 additions & 0 deletionsMisc/stable_abi.toml
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2583,3 +2583,5 @@
added = '3.15'
[function.PySys_GetOptionalAttrString]
added = '3.15'
[function.PyAbiInfo_GetInfo]
added = '3.15'
1 change: 1 addition & 0 deletionsPC/python3dll.c
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

1 change: 1 addition & 0 deletionsPCbuild/_freeze_module.vcxproj
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -188,6 +188,7 @@
<ClCompile Include="..\PC\msvcrtmodule.c" />
<ClCompile Include="..\PC\winreg.c" />
<ClCompile Include="..\Python\_warnings.c" />
<ClCompile Include="..\Python\abiinfo.c" />
<ClCompile Include="..\Python\asdl.c" />
<ClCompile Include="..\Python\assemble.c" />
<ClCompile Include="..\Python\ast.c" />
Expand Down
3 changes: 3 additions & 0 deletionsPCbuild/_freeze_module.vcxproj.filters
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -25,6 +25,9 @@
<ClCompile Include="..\Objects\abstract.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\Python\abiinfo.c">
<Filter>Python</Filter>
</ClCompile>
<ClCompile Include="..\Python\asdl.c">
<Filter>Source Files</Filter>
</ClCompile>
Expand Down
1 change: 1 addition & 0 deletionsPCbuild/pythoncore.vcxproj
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -582,6 +582,7 @@
<ClCompile Include="..\Python\pyhash.c" />
<ClCompile Include="..\Python\_contextvars.c" />
<ClCompile Include="..\Python\_warnings.c" />
<ClCompile Include="..\Python\abiinfo.c" />
<ClCompile Include="..\Python\asdl.c" />
<ClCompile Include="..\Python\assemble.c" />
<ClCompile Include="..\Python\ast.c" />
Expand Down
3 changes: 3 additions & 0 deletionsPCbuild/pythoncore.vcxproj.filters
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1316,6 +1316,9 @@
<ClCompile Include="..\Python\_warnings.c">
<Filter>Python</Filter>
</ClCompile>
<ClCompile Include="..\Python\abiinfo.c">
<Filter>Python</Filter>
</ClCompile>
<ClCompile Include="..\Python\asdl.c">
<Filter>Python</Filter>
</ClCompile>
Expand Down
100 changes: 100 additions & 0 deletionsPython/abiinfo.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
/* ABI information object implementation */

#include"Python.h"
#include"pycore_initconfig.h"// _PyStatus_OK()
#include"pycore_structseq.h"// _PyStructSequence_InitBuiltin()

staticPyTypeObjectAbiInfoType;

PyDoc_STRVAR(abi_info__doc__,
"ABI information object.\n\
This object provides information about the ABI \
features available in the current Python interpreter.\n");

staticPyStructSequence_Fieldabi_info_fields[]= {
{"pointer_bits","Is this a 32-bit or 64-bit build?"},
{"Py_GIL_DISABLED","Is free-threading enabled?"},
{"Py_DEBUG","Is debug mode enabled?"},
{0}
};

staticPyStructSequence_Descabi_info_desc= {
"sys.abi_info",
abi_info__doc__,
abi_info_fields,
3
};

PyObject*
_PyAbiInfo_GetPointerBits(void)
{
PyObject*pointer_bits;
switch (SIZEOF_VOID_P) {
case4:
pointer_bits=PyLong_FromLong(32);
break;
case8:
pointer_bits=PyLong_FromLong(64);
break;
default:
pointer_bits=Py_NewRef(Py_None);
break;
}
if (pointer_bits==NULL) {
returnNULL;
}
returnpointer_bits;
}

PyObject*
PyAbiInfo_GetInfo(void)
{
PyObject*abi_info,*value;
intpos=0;
abi_info=PyStructSequence_New(&AbiInfoType);
if (abi_info==NULL) {
gotoerror;
}

value=_PyAbiInfo_GetPointerBits();
if (value==NULL) {
gotoerror;
}
PyStructSequence_SetItem(abi_info,pos++,value);

#ifdefPy_GIL_DISABLED
value=Py_True;
#else
value=Py_False;
#endif
PyStructSequence_SetItem(abi_info,pos++,value);

#ifdefPy_DEBUG
value=Py_True;
#else
value=Py_False;
#endif
PyStructSequence_SetItem(abi_info,pos++,value);

returnabi_info;

error:
Py_XDECREF(abi_info);
returnNULL;
}

PyStatus
_PyAbiInfo_InitTypes(PyInterpreterState*interp)
{
if (_PyStructSequence_InitBuiltin(interp,&AbiInfoType,&abi_info_desc)<0) {
return_PyStatus_ERR("Failed to initialize AbiInfoType");
}

return_PyStatus_OK();
}

void
_PyAbiInfo_FiniTypes(PyInterpreterState*interp)
{
_PyStructSequence_FiniBuiltin(interp,&AbiInfoType);
}
7 changes: 7 additions & 0 deletionsPython/pylifecycle.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
/* Python interpreter top-level routines, including init/exit */

#include "Python.h"
#include "pycore_abiinfo.h" // _PyAbiInfo_InitTypes()
#include "pycore_audit.h" // _PySys_ClearAuditHooks()
#include "pycore_call.h" // _PyObject_CallMethod()
#include "pycore_ceval.h" // _PyEval_FiniGIL()
Expand DownExpand Up@@ -711,6 +712,11 @@ pycore_init_types(PyInterpreterState *interp)
return status;
}

status = _PyAbiInfo_InitTypes(interp);
if (_PyStatus_EXCEPTION(status)) {
return status;
}

status = _PyLong_InitTypes(interp);
if (_PyStatus_EXCEPTION(status)) {
return status;
Expand DownExpand Up@@ -1860,6 +1866,7 @@ static void
finalize_interp_types(PyInterpreterState *interp)
{
_PyTypes_FiniExtTypes(interp);
_PyAbiInfo_FiniTypes(interp);
_PyUnicode_FiniTypes(interp);
_PySys_FiniTypes(interp);
_PyXI_FiniTypes(interp);
Expand Down
3 changes: 3 additions & 0 deletionsPython/sysmodule.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3268,6 +3268,7 @@ PyDoc_STR(
"\n\
Static objects:\n\
\n\
abi_info -- a named tuple with information about the ABI.\n\
builtin_module_names -- tuple of module names built into this interpreter\n\
copyright -- copyright notice pertaining to this interpreter\n\
exec_prefix -- prefix used to find the machine-specific Python library\n\
Expand DownExpand Up@@ -3863,6 +3864,8 @@ _PySys_InitCore(PyThreadState *tstate, PyObject *sysdict)

SET_SYS("thread_info", PyThread_GetInfo());

SET_SYS("abi_info", PyAbiInfo_GetInfo());

/* initialize asyncgen_hooks */
if (_PyStructSequence_InitBuiltin(interp, &AsyncGenHooksType,
&asyncgen_hooks_desc) < 0)
Expand Down
1 change: 1 addition & 0 deletionsTools/c-analyzer/TODO
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -841,6 +841,7 @@ Objects/unicodeobject.c:PyUnicode_Type PyTypeObject Py
Objects/weakrefobject.c:_PyWeakref_CallableProxyType PyTypeObject _PyWeakref_CallableProxyType
Objects/weakrefobject.c:_PyWeakref_ProxyType PyTypeObject _PyWeakref_ProxyType
Objects/weakrefobject.c:_PyWeakref_RefType PyTypeObject _PyWeakref_RefType
Python/abiinfo.c:AbiInfoType static PyTypeObject AbiInfoType
Python/bltinmodule.c:PyFilter_Type PyTypeObject PyFilter_Type
Python/bltinmodule.c:PyMap_Type PyTypeObject PyMap_Type
Python/bltinmodule.c:PyZip_Type PyTypeObject PyZip_Type
Expand Down
1 change: 1 addition & 0 deletionsTools/c-analyzer/cpython/globals-to-fix.tsv
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -153,6 +153,7 @@ Objects/object.c-_PyLegacyEventHandler_Type-

Objects/floatobject.c-FloatInfoType-
Objects/longobject.c-Int_InfoType-
Python/abiinfo.c-AbiInfoType-
Python/errors.c-UnraisableHookArgsType-
Python/sysmodule.c-AsyncGenHooksType-
Python/sysmodule.c-FlagsType-
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp