gh-136663: fix signatures of PyFloat_Pack/Unpack in docs (GH-136664)
(cherry picked from commit e4654e0b3e)
Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
Docs: Fix and improve the `PyUnstable_Object_EnableDeferredRefcount` documentation (GH-135323)
(cherry picked from commit 0d4fd10fba)
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
gh-135913: Document ob_refcnt, ob_type, ob_size (GH-135914)
* gh-135913: Document ob_refcnt, ob_type, ob_size
In `typeobj.rst`, instead of `:c:member:` it would be better to
use `.. c:member::` with a `:no-index:` option, see:
See ref. https://www.sphinx-doc.org/en/master/usage/domains/index.html#basic-markup
However, `c:member` currently does not support `:no-index:`.
(cherry picked from commit 73e1207a4e)
Co-authored-by: Petr Viktorin <encukou@gmail.com>
* Turn the __future__ table to list-table.
This'll make it easier to add entries that need longer markup
* Semantic markup for __future__ feature descriptions.
* Document CO_* C macros.
(cherry picked from commit 2468aafe98)
Co-authored-by: Petr Viktorin <encukou@gmail.com>
Docs: Document `PyExceptionClass` functions in the C API (GH-135697)
* Docs: Document `PyExceptionClass_Name`
`PyExceptionClass_Name` is an undocumented function in the limited API.
* Document `PyExceptionClass_Check`
(cherry picked from commit 59963e866a)
Co-authored-by: Yuki Kobayashi <drsuaimqjgar@gmail.com>
Docs: Fix markups for emphasis (GH-135598)
The word emphasis character `_` is not supported as sphinx markup, so changed to `*`.
(cherry picked from commit 46c60e0d0b)
Co-authored-by: Yuki Kobayashi <drsuaimqjgar@gmail.com>
Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
gh-133264: Correct documentation of how Py_Main and Py_RunMain handle SystemExit (GH-135337)
(cherry picked from commit b706ff003c)
Co-authored-by: Malcolm Smith <smith@chaquo.com>
bpo-45210: Document that error indicator may be set in tp_dealloc (GH-28358)
(cherry picked from commit 8441b263af)
Signed-off-by: Edward Z. Yang <ezyang@fb.com>
Signed-off-by: Edward Z. Yang <ezyang@meta.com>
Co-authored-by: Edward Z. Yang <ezyang@mit.edu>
Co-authored-by: Victor Stinner <vstinner@python.org>
gh-133968: Add PyUnicodeWriter_WriteASCII() function (#133973)
Replace most PyUnicodeWriter_WriteUTF8() calls with
PyUnicodeWriter_WriteASCII().
(cherry picked from commit f49a07b531)
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
gh-133678: Document C API third party tools (GH-134526)
(cherry picked from commit c3c88064f5)
Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: Steve Dower <steve.dower@python.org>
gh-134160: Use multi-phase init in documentation examples (GH-134296)
(cherry picked from commit 96905bdd27)
Co-authored-by: neonene <53406459+neonene@users.noreply.github.com>
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
Two special methods, __buffer__ and __release_buffer__ were added to
Python 3.12 by PEP 688. The C API Type Object documentation for slots
includes `tp_as_buffer`, and sub-slots `bf_getbuffer`, `bf_releasebuffer`
but does not refer to the Python Data Model version of those. Add the
missing references.
(cherry picked from commit b529b60fc2)
Co-authored-by: Cody Maloney <cmaloney@users.noreply.github.com>
gh-75459: Doc: C API: Improve object life cycle documentation (GH-125962)
* Add "cyclic isolate" to the glossary.
* Add a new "Object Life Cycle" page.
* Improve docs for related API, with special focus on cross-references and warnings
(cherry picked from commit 3246ea514d)
Co-authored-by: Richard Hansen <rhansen@rhansen.org>
Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
Docs: C API: Improve documentation around non-Python threads with subinterpreters (GH-131087)
(cherry picked from commit af6b3b825f)
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
After gh-130704, the interpreter replaces some uses of `LOAD_FAST` with
`LOAD_FAST_BORROW` which avoid incref/decrefs by "borrowing" references
on the interpreter stack when the bytecode compiler can determine that
it's safe.
This change broke some checks in C API extensions that relied on
`Py_REFCNT()` of `1` to determine if it's safe to modify an object
in-place. Objects may have a reference count of one, but still be
referenced further up the interpreter stack due to borrowing of
references.
This provides a replacement function for those checks.
`PyUnstable_Object_IsUniqueReferencedTemporary` is more conservative:
it checks that the object has a reference count of one and that it exists as a
unique strong reference in the interpreter's stack of temporary
variables in the top most frame.
See also:
* https://github.com/numpy/numpy/issues/28681
Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
Co-authored-by: T. Wouters <thomas@python.org>
Co-authored-by: mpage <mpage@cs.stanford.edu>
Co-authored-by: Mark Shannon <mark@hotpy.org>
Co-authored-by: Victor Stinner <vstinner@python.org>
* Skip sNaN's testing in 32-bit mode.
* Drop float_set_snan() helper.
* Use memcpy() workaround for sNaN's in PyFloat_Unpack4().
* Document, that sNaN's may not be preserved by PyFloat_Pack/Unpack API.
We replace it with _Py_GetMainModule(), and add _Py_CheckMainModule(), but both in the internal-only C-API. We also add _PyImport_GetModulesRef(), which is the equivalent of _PyImport_GetModules(), but which increfs before the lock is released.
This is used by a later change related to pickle and handling __main__.
If `Py_IsFinalizing()` is true, non-daemon threads (other than the current one)
are done, and daemon threads are prevented from running, so they
cannot finalize themselves and become done. Joining them (without timeout)
would block forever.
Raise PythonFinalizationError instead of hanging.
Raise even when a timeout is given, for consistency with trying to join your own thread.
See gh-123940 for a use case: calling `join()` from `__del__`. This is
ill-advised, but an exception should at least make it easier to diagnose.