cpython/Include
Ken Jin 22b0de2755
gh-117139: Convert the evaluation stack to stack refs (#118450)
This PR sets up tagged pointers for CPython.

The general idea is to create a separate struct _PyStackRef for everything on the evaluation stack to store the bits. This forces the C compiler to warn us if we try to cast things or pull things out of the struct directly.

Only for free threading: We tag the low bit if something is deferred - that means we skip incref and decref operations on it. This behavior may change in the future if Mark's plans to defer all objects in the interpreter loop pans out.

This implies a strict stack reference discipline is required. ALL incref and decref operations on stackrefs must use the stackref variants. It is unsafe to untag something then do normal incref/decref ops on it.

The new incref and decref variants are called dup and close. They mimic a "handle" API operating on these stackrefs.

Please read Include/internal/pycore_stackref.h for more information!

---------

Co-authored-by: Mark Shannon <9448417+markshannon@users.noreply.github.com>
2024-06-27 03:10:43 +08:00
..
cpython gh-120593: Fix const qualifier in _PyLong_CompactValue() (#121053) 2024-06-26 20:11:21 +02:00
internal gh-117139: Convert the evaluation stack to stack refs (#118450) 2024-06-27 03:10:43 +08:00
abstract.h gh-119391: Amend comment description of PyMapping_Items, PyMapping_Values and PyMapping_Keys (#119392) 2024-05-22 08:52:36 -04:00
bltinmodule.h
boolobject.h gh-115754: Add Py_GetConstant() function (#116883) 2024-03-21 16:07:00 +00:00
bytearrayobject.h gh-87347: Add parenthesis around PyXXX_Check() arguments (#92815) 2022-06-16 13:49:43 +02:00
bytesobject.h gh-108765: Move standard includes to Python.h (#108769) 2023-09-01 21:03:20 +02:00
ceval.h GH-120507: Lower the BEFORE_WITH and BEFORE_ASYNC_WITH instructions. (#120640) 2024-06-18 12:17:46 +01:00
codecs.h Remove private _PyCodec_Lookup() function (#106269) 2023-06-30 09:34:01 +00:00
compile.h gh-109596: Ensure repeated rules in the grammar are not allowed and fix incorrect soft keywords (#109606) 2023-09-22 19:03:23 +01:00
complexobject.h gh-87347: Add parenthesis around PyXXX_Check() arguments (#92815) 2022-06-16 13:49:43 +02:00
critical_section.h gh-119344: Make critical section API public (#119353) 2024-06-21 15:50:18 -04:00
datetime.h gh-87347: Add parenthesis around macro arguments (#93915) 2022-06-20 16:04:52 +02:00
descrobject.h gh-103509: PEP 697 -- Limited C API for Extending Opaque Types (GH-103511) 2023-05-04 09:56:53 +02:00
dictobject.h gh-106004: PyDict_GetItemRef() should only be in the limited API 3.13 (GH-107229) 2023-07-25 21:48:07 +03:00
dynamic_annotations.h gh-96959: Update HTTP links which are redirected to HTTPS (GH-96961) 2022-09-24 14:38:53 +03:00
enumobject.h
errcode.h gh-107450: Check for overflow in the tokenizer and fix overflow test (#110832) 2023-10-16 16:42:49 +02:00
exports.h gh-108765: Move export code from pyport.h to exports.h (#108855) 2023-09-04 01:04:05 +02:00
fileobject.h gh-106320: Remove _PyIsSelectable_fd() C API (#107142) 2023-07-23 19:07:12 +00:00
fileutils.h gh-108765: Move stat() fiddling from pyport.h to fileutils.h (#108854) 2023-09-03 21:32:13 +00:00
floatobject.h gh-87347: Add parenthesis around PyXXX_Check() arguments (#92815) 2022-06-16 13:49:43 +02:00
frameobject.h
genericaliasobject.h
import.h gh-105922: Add PyImport_AddModuleRef() function (#105923) 2023-06-20 08:48:14 +02:00
intrcheck.h gh-106320: Remove private _PyOS_IsMainThread() function (#108605) 2023-08-29 03:20:31 +00:00
iterobject.h gh-106320: Remove _PyAnextAwaitable_Type from the public C API (#108597) 2023-08-29 02:05:11 +00:00
listobject.h gh-114329: Fix PyList_GetItemRef() limited C API definition (#117520) 2024-04-03 21:02:42 +00:00
lock.h gh-117511: Make PyMutex public in the non-limited API (#117731) 2024-06-20 11:29:08 -04:00
longobject.h gh-117021: Fix integer overflow in PyLong_AsPid() on non-Windows 64-bit platforms (GH-117064) 2024-03-20 15:39:53 +02:00
marshal.h bpo-45474: Exclude all of marshal.h if Py_LIMITED_API is defined (GH-29061) 2021-10-20 02:32:14 -07:00
memoryobject.h gh-79315: Add Include/cpython/memoryobject.h header (#99723) 2022-11-23 15:44:42 +01:00
methodobject.h gh-114626: Add again _PyCFunctionFastWithKeywords name (GH-115561) 2024-02-19 13:20:46 +01:00
modsupport.h gh-65210: Add const qualifiers in PyArg_VaParseTupleAndKeywords() (GH-105958) 2023-12-04 13:14:56 +02:00
moduleobject.h gh-116322: Rename PyModule_ExperimentalSetGIL to PyUnstable_Module_SetGIL (GH-118645) 2024-05-06 18:59:36 +02:00
monitoring.h gh-111997: C-API for signalling monitoring events (#116413) 2024-05-04 08:23:50 +00:00
object.h gh-117511: Make PyMutex public in the non-limited API (#117731) 2024-06-20 11:29:08 -04:00
objimpl.h gh-102013: Move PyUnstable_GC_VisitObjects() to Include/cpython/objimpl.h (#115560) 2024-02-16 15:49:13 +01:00
opcode.h gh-105481: opcode.h is no longer generated during the build (#108080) 2023-08-17 17:07:58 +01:00
opcode_ids.h GH-120507: Lower the BEFORE_WITH and BEFORE_ASYNC_WITH instructions. (#120640) 2024-06-18 12:17:46 +01:00
osdefs.h gh-108765: Reformat Include/osdefs.h (#108766) 2023-09-01 14:35:39 +00:00
osmodule.h
patchlevel.h Python 3.14.0a0 2024-05-08 16:57:05 +02:00
py_curses.h gh-109617: fix ncurses incompatibility on macOS with Xcode 15 (#111258) 2024-05-04 23:41:47 +02:00
pyatomic.h gh-108724: Add PyMutex and _PyParkingLot APIs (gh-109344) 2023-09-19 09:54:29 -06:00
pybuffer.h gh-102500: Implement PEP 688 (#102521) 2023-05-04 07:59:46 -07:00
pycapsule.h gh-108240: Add pycore_capsule.h internal header file (#108596) 2023-08-29 01:20:02 +00:00
pydtrace.d
pydtrace.h Fix pydtrace.d path comment in Include/pydtrace.h (#28539) 2022-12-31 22:40:25 +05:30
pyerrors.h gh-119521: Rename IncompleteInputError to _IncompleteInputError and remove from public API/ABI (GH-119680) 2024-06-24 14:08:12 +02:00
pyexpat.h gh-115398: Revert PyExpat_CAPI_MAGIC version bump (GH-116411) 2024-03-06 09:55:07 -08:00
pyframe.h gh-93937, C API: Move PyFrame_GetBack() to Python.h (#93938) 2022-06-19 12:02:33 +02:00
pyhash.h gh-111545: Add Include/cpython/pyhash.h header file (#112063) 2023-11-15 01:19:20 +01:00
pylifecycle.h gh-117987: Restore several functions removed in Python 3.13 alpha 1 (GH-117993) 2024-04-18 15:20:38 +02:00
pymacconfig.h gh-110820: Make sure processor specific defines are correct for Universal 2 build on macOS (#112828) 2023-12-08 10:09:34 +01:00
pymacro.h gh-118124: Use static_assert() in Py_BUILD_ASSERT() on C11 (#118398) 2024-04-30 22:29:48 +02:00
pymath.h gh-119613: Soft deprecate Py_IS_NAN/INFINITY/FINITE (#119701) 2024-05-29 10:45:14 +00:00
pymem.h gh-85283: Add PyMem_RawMalloc() to the limited C API (#108570) 2023-10-17 02:41:51 +02:00
pyport.h gh-119613: Soft deprecate the Py_MEMCPY() macro (#120020) 2024-06-04 09:23:55 +00:00
pystate.h gh-108867: Add PyThreadState_GetUnchecked() function (#108870) 2023-10-03 16:53:51 +00:00
pystats.h gh-108753: Enhance pystats (#108754) 2023-09-06 15:54:59 +00:00
pystrcmp.h
pystrtod.h gh-106320: Remove private float C API functions (#108430) 2023-08-24 19:09:49 +02:00
Python.h gh-120642: Move private PyCode APIs to the internal C API (#120643) 2024-06-26 13:54:03 +02:00
pythonrun.h gh-102755: PyErr_DisplayException only in ABI >= 3.12. Tests cover PyErr_Display as well (GH-102849) 2023-03-21 10:36:18 +01:00
pythread.h gh-81925: Implement native thread ids for kFreeBSD (#111761) 2023-11-09 21:02:30 +01:00
pytypedefs.h bpo-45459: Fix PyModuleDef_Slot type in the limited C API (GH-31668) 2022-03-03 23:06:55 +01:00
rangeobject.h gh-87347: Add parenthesis around PyXXX_Check() arguments (#92815) 2022-06-16 13:49:43 +02:00
README.rst gh-101101: Unstable C API tier (PEP 689) (GH-101102) 2023-02-28 09:31:01 +01:00
refcount.h gh-119853: Add Include/refcount.h file (#119854) 2024-05-31 16:49:26 +02:00
setobject.h gh-87347: Add parenthesis around PyXXX_Check() arguments (#92815) 2022-06-16 13:49:43 +02:00
sliceobject.h gh-115754: Add Py_GetConstant() function (#116883) 2024-03-21 16:07:00 +00:00
structmember.h Fix typos in comments (#120188) 2024-06-07 10:19:41 +02:00
structseq.h gh-106168: PyTuple_SET_ITEM() now checks the index (#106164) 2023-06-28 03:45:57 +02:00
sysmodule.h gh-117987: Restore several functions removed in Python 3.13 alpha 1 (GH-117993) 2024-04-18 15:20:38 +02:00
traceback.h gh-87347: Add parenthesis around PyXXX_Check() arguments (#92815) 2022-06-16 13:49:43 +02:00
tupleobject.h gh-87347: Add parenthesis around PyXXX_Check() arguments (#92815) 2022-06-16 13:49:43 +02:00
typeslots.h bpo-45459: Add Py_buffer to limited API (GH-29991) 2022-02-02 07:03:10 -08:00
unicodeobject.h gh-111089: Revert PyUnicode_AsUTF8() changes (#111833) 2023-11-07 22:36:13 +00:00
warnings.h
weakrefobject.h gh-105927: Limit PyWeakref_GetRef() to limited C API 3.13 (#117091) 2024-03-20 23:52:23 +01:00

The Python C API
================

The C API is divided into these sections:

1. ``Include/``: Limited API
2. ``Include/cpython/``: CPython implementation details
3. ``Include/cpython/``, names with the ``PyUnstable_`` prefix: API that can
   change between minor releases
4. ``Include/internal/``, and any name with ``_`` prefix: The internal API

Information on changing the C API is available `in the developer guide`_

.. _in the developer guide: https://devguide.python.org/c-api/