Skip to content

Commit defb2b2

Browse files
committed
Make abi_info object a simple namespace with no explicit C API
1 parent b6c945c commit defb2b2

File tree

10 files changed

+60
-124
lines changed

10 files changed

+60
-124
lines changed

Doc/library/sys.rst

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,18 @@ always available. Unless explicitly noted otherwise, all variables are read-only
1313

1414
.. data:: abi_info
1515

16-
A :term:`named tuple` holding information about the ABI of the interpreter.
16+
An object containing information about the ABI of the currently running
17+
Python interpreter. The following attributes are available in cpython:
1718

18-
.. attribute:: abi_info.pointer_bits
19+
*pointer_bits* is the width of pointers in bits, as an integer, equivalent
20+
to ``8 * sizeof(void *)``, i.e. usually ``32`` or ``64``.
1921

20-
The width of pointers in bits, as an integer.
21-
Equivalent to ``8 * sizeof(void *)``, i.e. usually ``32`` or ``64``.
22+
*Py_GIL_DISABLED* is a boolean indicating whether the interpreter was built
23+
with the GIL disabled, i.e. with the :option:`--disable-gil` option,
24+
aka free-threading.
2225

23-
.. attribute:: abi_info.Py_GIL_DISABLED
24-
25-
A boolean indicating whether the interpreter was built in with the GIL
26-
disabled, i.e. with the :option:`--disable-gil` option, aka free-threading.
27-
28-
.. attribute:: abi_info.Py_DEBUG
29-
30-
A boolean indicating whether the interpreter was built in debug mode,
31-
i.e. with the :option:`--with-pydebug` option.
26+
*Py_DEBUG* is a boolean indicating whether the interpreter was built in
27+
debug mode, i.e. with the :option:`--with-pydebug` option.
3228

3329
.. versionadded:: next
3430

Include/internal/pycore_abiinfo.h

Lines changed: 0 additions & 14 deletions
This file was deleted.

Makefile.pre.in

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,6 @@ PYTHON_OBJS= \
423423
Python/_warnings.o \
424424
Python/Python-ast.o \
425425
Python/Python-tokenize.o \
426-
Python/abiinfo.o \
427426
Python/asdl.o \
428427
Python/assemble.o \
429428
Python/ast.o \

PCbuild/_freeze_module.vcxproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,6 @@
188188
<ClCompile Include="..\PC\msvcrtmodule.c" />
189189
<ClCompile Include="..\PC\winreg.c" />
190190
<ClCompile Include="..\Python\_warnings.c" />
191-
<ClCompile Include="..\Python\abiinfo.c" />
192191
<ClCompile Include="..\Python\asdl.c" />
193192
<ClCompile Include="..\Python\assemble.c" />
194193
<ClCompile Include="..\Python\ast.c" />

PCbuild/_freeze_module.vcxproj.filters

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@
2525
<ClCompile Include="..\Objects\abstract.c">
2626
<Filter>Source Files</Filter>
2727
</ClCompile>
28-
<ClCompile Include="..\Python\abiinfo.c">
29-
<Filter>Python</Filter>
30-
</ClCompile>
3128
<ClCompile Include="..\Python\asdl.c">
3229
<Filter>Source Files</Filter>
3330
</ClCompile>

PCbuild/pythoncore.vcxproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,6 @@
582582
<ClCompile Include="..\Python\pyhash.c" />
583583
<ClCompile Include="..\Python\_contextvars.c" />
584584
<ClCompile Include="..\Python\_warnings.c" />
585-
<ClCompile Include="..\Python\abiinfo.c" />
586585
<ClCompile Include="..\Python\asdl.c" />
587586
<ClCompile Include="..\Python\assemble.c" />
588587
<ClCompile Include="..\Python\ast.c" />

PCbuild/pythoncore.vcxproj.filters

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,9 +1316,6 @@
13161316
<ClCompile Include="..\Python\_warnings.c">
13171317
<Filter>Python</Filter>
13181318
</ClCompile>
1319-
<ClCompile Include="..\Python\abiinfo.c">
1320-
<Filter>Python</Filter>
1321-
</ClCompile>
13221319
<ClCompile Include="..\Python\asdl.c">
13231320
<Filter>Python</Filter>
13241321
</ClCompile>

Python/abiinfo.c

Lines changed: 0 additions & 79 deletions
This file was deleted.

Python/pylifecycle.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/* Python interpreter top-level routines, including init/exit */
22

33
#include "Python.h"
4-
#include "pycore_abiinfo.h" // _PyAbiInfo_InitTypes()
54
#include "pycore_audit.h" // _PySys_ClearAuditHooks()
65
#include "pycore_call.h" // _PyObject_CallMethod()
76
#include "pycore_ceval.h" // _PyEval_FiniGIL()
@@ -712,11 +711,6 @@ pycore_init_types(PyInterpreterState *interp)
712711
return status;
713712
}
714713

715-
status = _PyAbiInfo_InitTypes(interp);
716-
if (_PyStatus_EXCEPTION(status)) {
717-
return status;
718-
}
719-
720714
status = _PyLong_InitTypes(interp);
721715
if (_PyStatus_EXCEPTION(status)) {
722716
return status;
@@ -1866,7 +1860,6 @@ static void
18661860
finalize_interp_types(PyInterpreterState *interp)
18671861
{
18681862
_PyTypes_FiniExtTypes(interp);
1869-
_PyAbiInfo_FiniTypes(interp);
18701863
_PyUnicode_FiniTypes(interp);
18711864
_PySys_FiniTypes(interp);
18721865
_PyXI_FiniTypes(interp);

Python/sysmodule.c

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ Data members:
1515
*/
1616

1717
#include "Python.h"
18-
#include "pycore_abiinfo.h" // _PyAbiInfo_GetInfo()
1918
#include "pycore_audit.h" // _Py_AuditHookEntry
2019
#include "pycore_call.h" // _PyObject_CallNoArgs()
2120
#include "pycore_ceval.h" // _PyEval_SetAsyncGenFinalizer()
@@ -3632,6 +3631,56 @@ make_impl_info(PyObject *version_info)
36323631
return NULL;
36333632
}
36343633

3634+
3635+
PyObject *
3636+
make_abi_info(void)
3637+
{
3638+
int res;
3639+
PyObject *abi_info, *value, *ns;
3640+
abi_info = PyDict_New();
3641+
if (abi_info == NULL) {
3642+
goto error;
3643+
}
3644+
3645+
value = PyLong_FromLong(sizeof(void *) * 8);
3646+
if (value == NULL) {
3647+
goto error;
3648+
}
3649+
res = PyDict_SetItemString(abi_info, "pointer_bits", value);
3650+
Py_DECREF(value);
3651+
if (res < 0) {
3652+
goto error;
3653+
}
3654+
3655+
#ifdef Py_GIL_DISABLED
3656+
value = Py_True;
3657+
#else
3658+
value = Py_False;
3659+
#endif
3660+
res = PyDict_SetItemString(abi_info, "Py_GIL_DISABLED", value);
3661+
if (res < 0) {
3662+
goto error;
3663+
}
3664+
3665+
#ifdef Py_DEBUG
3666+
value = Py_True;
3667+
#else
3668+
value = Py_False;
3669+
#endif
3670+
res = PyDict_SetItemString(abi_info, "Py_DEBUG", value);
3671+
if (res < 0) {
3672+
goto error;
3673+
}
3674+
3675+
ns = _PyNamespace_New(abi_info);
3676+
Py_DECREF(abi_info);
3677+
return ns;
3678+
3679+
error:
3680+
Py_CLEAR(abi_info);
3681+
return NULL;
3682+
}
3683+
36353684
#ifdef __EMSCRIPTEN__
36363685

36373686
PyDoc_STRVAR(emscripten_info__doc__,
@@ -3857,7 +3906,7 @@ _PySys_InitCore(PyThreadState *tstate, PyObject *sysdict)
38573906

38583907
SET_SYS("thread_info", PyThread_GetInfo());
38593908

3860-
SET_SYS("abi_info", _PyAbiInfo_GetInfo());
3909+
SET_SYS("abi_info", make_abi_info());
38613910

38623911
/* initialize asyncgen_hooks */
38633912
if (_PyStructSequence_InitBuiltin(interp, &AsyncGenHooksType,

0 commit comments

Comments
 (0)