Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
2e3e54a
Add sys.abi_info
zklaus Aug 1, 2025
2ddafa4
📜🤖 Added by blurb_it.
blurb-it[bot] Aug 6, 2025
cdc50c3
Simplify pointer_bits handling
zklaus Aug 7, 2025
6fb25a3
Remove explicit C API function
zklaus Aug 7, 2025
4c3d83d
Make abi_info object a simple namespace with no explicit C API
zklaus Aug 7, 2025
820e002
Cleanup scaffolding
zklaus Aug 7, 2025
918521f
Fix make_abi_info to be static
zklaus Aug 7, 2025
7863651
Add test
zklaus Aug 12, 2025
81d75fc
Fix test
zklaus Aug 12, 2025
41027a3
Add link
zklaus Aug 14, 2025
56726ab
Rename attributes
zklaus Aug 14, 2025
94b7f40
Add better attribute specification to docs
zklaus Aug 21, 2025
6887d6c
Base `debug` on Py_REF_DEBUG
zklaus Aug 21, 2025
7ced683
Add byteorder
zklaus Aug 21, 2025
cc5ae8c
Fix test
zklaus Aug 21, 2025
5c18587
Improve error message in test
zklaus Aug 21, 2025
d025d17
Apply suggestions from code review
zklaus Sep 2, 2025
a089371
Revert "Base `debug` on Py_REF_DEBUG"
zklaus Sep 2, 2025
44ce7c7
Add whatsnew entry for improved sys module
zklaus Sep 2, 2025
8f57f17
Update Python/sysmodule.c
zklaus Sep 3, 2025
77f7b9b
Integrate suggestions from Adam Turner
zklaus Sep 3, 2025
312bff1
Add Windows configuration equivalents
zklaus Sep 4, 2025
ed7b6d9
Fix rst lint
zklaus Sep 4, 2025
15f065a
Use Sphinx markup for attributes
encukou Sep 5, 2025
151eb4c
Merge pull request #3 from encukou/add-sys.abi_info
zklaus Sep 8, 2025
9f5ffae
Merge branch 'main' into add-sys.abi_info
AA-Turner Sep 8, 2025
128b150
Don't use ReST in a C comment
encukou Sep 8, 2025
0506533
docs rephrasing
AA-Turner Sep 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
Prev Previous commit
Next Next commit
Make abi_info object a simple namespace with no explicit C API
  • Loading branch information
zklaus committed Sep 3, 2025
commit 4c3d83d0ed0ba6c6f398acaf23e555f642cb99f3
22 changes: 9 additions & 13 deletions Doc/library/sys.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,18 @@ 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.
An object containing information about the ABI of the currently running
Python interpreter. The following attributes are available in cpython:

.. attribute:: abi_info.pointer_bits
*pointer_bits* is the width of pointers in bits, as an integer, equivalent
to ``8 * sizeof(void *)``, i.e. usually ``32`` or ``64``.
Comment thread
zklaus marked this conversation as resolved.
Outdated

The width of pointers in bits, as an integer.
Equivalent to ``8 * sizeof(void *)``, i.e. usually ``32`` or ``64``.
*Py_GIL_DISABLED* is a boolean indicating whether the interpreter was built
Comment thread
zklaus marked this conversation as resolved.
Outdated
with the GIL disabled, i.e. with the :option:`--disable-gil` option,
aka free-threading.

.. 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.
*Py_DEBUG* is a boolean indicating whether the interpreter was built in
Comment thread
vstinner marked this conversation as resolved.
Outdated
debug mode, i.e. with the :option:`--with-pydebug` option.
Comment thread
zklaus marked this conversation as resolved.
Outdated

.. versionadded:: next
Comment thread
zklaus marked this conversation as resolved.
Outdated

Expand Down
14 changes: 0 additions & 14 deletions Include/internal/pycore_abiinfo.h

This file was deleted.

1 change: 0 additions & 1 deletion Makefile.pre.in
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,6 @@ 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
1 change: 0 additions & 1 deletion PCbuild/_freeze_module.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@
<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: 0 additions & 3 deletions PCbuild/_freeze_module.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
<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: 0 additions & 1 deletion PCbuild/pythoncore.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,6 @@
<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: 0 additions & 3 deletions PCbuild/pythoncore.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -1316,9 +1316,6 @@
<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
79 changes: 0 additions & 79 deletions Python/abiinfo.c

This file was deleted.

7 changes: 0 additions & 7 deletions Python/pylifecycle.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* 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 Down Expand Up @@ -712,11 +711,6 @@ 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 Down Expand Up @@ -1866,7 +1860,6 @@ static void
finalize_interp_types(PyInterpreterState *interp)
{
_PyTypes_FiniExtTypes(interp);
_PyAbiInfo_FiniTypes(interp);
_PyUnicode_FiniTypes(interp);
_PySys_FiniTypes(interp);
_PyXI_FiniTypes(interp);
Expand Down
53 changes: 51 additions & 2 deletions Python/sysmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ Data members:
*/

#include "Python.h"
#include "pycore_abiinfo.h" // _PyAbiInfo_GetInfo()
#include "pycore_audit.h" // _Py_AuditHookEntry
#include "pycore_call.h" // _PyObject_CallNoArgs()
#include "pycore_ceval.h" // _PyEval_SetAsyncGenFinalizer()
Expand Down Expand Up @@ -3640,6 +3639,56 @@ make_impl_info(PyObject *version_info)
return NULL;
}


PyObject *
make_abi_info(void)
{
int res;
PyObject *abi_info, *value, *ns;
abi_info = PyDict_New();
if (abi_info == NULL) {
goto error;
}

value = PyLong_FromLong(sizeof(void *) * 8);
if (value == NULL) {
goto error;
}
res = PyDict_SetItemString(abi_info, "pointer_bits", value);
Py_DECREF(value);
if (res < 0) {
goto error;
}

#ifdef Py_GIL_DISABLED
value = Py_True;
#else
value = Py_False;
#endif
res = PyDict_SetItemString(abi_info, "Py_GIL_DISABLED", value);
if (res < 0) {
goto error;
}

#ifdef Py_DEBUG
value = Py_True;
#else
value = Py_False;
#endif
res = PyDict_SetItemString(abi_info, "Py_DEBUG", value);
if (res < 0) {
goto error;
}

ns = _PyNamespace_New(abi_info);
Py_DECREF(abi_info);
return ns;

error:
Py_CLEAR(abi_info);
Comment thread
zklaus marked this conversation as resolved.
Outdated
return NULL;
}

#ifdef __EMSCRIPTEN__

PyDoc_STRVAR(emscripten_info__doc__,
Expand Down Expand Up @@ -3865,7 +3914,7 @@ _PySys_InitCore(PyThreadState *tstate, PyObject *sysdict)

SET_SYS("thread_info", PyThread_GetInfo());

SET_SYS("abi_info", _PyAbiInfo_GetInfo());
SET_SYS("abi_info", make_abi_info());

/* initialize asyncgen_hooks */
if (_PyStructSequence_InitBuiltin(interp, &AsyncGenHooksType,
Expand Down