Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
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
Uh oh!
There was an error while loading.Please reload this page.
Changes from1 commit
2e3e54a2ddafa4cdc50c36fb25a34c3d83d820e002918521f786365181d75fc41027a356726ab94b7f406887d6c7ced683cc5ae8c5c18587d025d17a08937144ce7c78f57f1777f7b9b312bff1ed7b6d915f065a151eb4c9f5ffae128b1500506533File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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. | ||
zklaus marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| .. 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 | ||
zklaus marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| .. data:: abiflags | ||
| On POSIX systems where Python was built with the standard ``configure`` | ||
| Original file line number | Diff line number | Diff 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 */ |
| Original file line number | Diff line number | Diff 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); | ||
zklaus marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| #endif | ||
| #ifdef__cplusplus | ||
| } | ||
| #endif | ||
| #endif/* !Py_PYABIINFO_H */ | ||
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -2583,3 +2583,5 @@ | ||
| added = '3.15' | ||
| [function.PySys_GetOptionalAttrString] | ||
| added = '3.15' | ||
| [function.PyAbiInfo_GetInfo] | ||
| added = '3.15' | ||
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
| Original file line number | Diff line number | Diff 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[]= { | ||
zklaus marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| {"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(); | ||
zklaus marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| 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); | ||
encukou marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| #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); | ||
| } | ||