Commit graph

1837 commits

Author SHA1 Message Date
Sergey B Kirpichev
bc4996c125
gh-128813: cleanup C-API docs for PyComplexObject (GH-137579)
* move non-deprecated API up
* make a dedicated section for deprecated low-leved API
2025-08-11 13:51:39 +02:00
da-woods
70218b4008
Fix documentation of hash in PyHash_FuncDef (#137595)
Because of a small typo, it wasn't showing up in the generated docs.
2025-08-11 13:18:37 +02:00
Sergey B Kirpichev
9743d069bd
gh-128813: deprecate cval field of the PyComplexObject struct (#137271)
Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
2025-08-08 10:36:42 +00:00
Sergey B Kirpichev
4dd85b347f
gh-137368: document __index__() support for PyLong_AsInt32/64() (GH-137369) 2025-08-04 15:30:29 +02:00
Serhiy Storchaka
1612dcbafe
gh-137341: Remove more word duplications (GH-137342) 2025-08-03 19:41:12 +03:00
Sergey B Kirpichev
9ced5c4ace
gh-128813: soft-deprecate _Py_c_*() functions (GH-137261) 2025-08-01 09:40:12 +02:00
Nathan Goldbaum
b13a5df52f
gh-133296: Fix versionadded for C API functions that were backported (#137024) 2025-07-22 21:27:50 +01:00
Nazım Can Altınova
a667800558
gh-136459: Add perf trampoline support for macOS (#136461) 2025-07-22 16:47:24 +01:00
Serhiy Storchaka
3a89dfe32b
Revert "gh-112068: C API: Add support of nullable arguments in PyArg_Parse (GH-121303)" (#136991) 2025-07-22 16:39:50 +03:00
Nathan Goldbaum
89c220b93c
gh-133296: Publicly expose critical section API that accepts PyMutex (gh-135899)
This makes the following APIs public:

* `Py_BEGIN_CRITICAL_SECTION_MUTEX(mutex),`
* `Py_BEGIN_CRITICAL_SECTION2_MUTEX(mutex1, mutex2)`
* `void PyCriticalSection_BeginMutex(PyCriticalSection *c, PyMutex *mutex)`
* `void PyCriticalSection2_BeginMutex(PyCriticalSection2 *c, PyMutex *mutex1, PyMutex *mutex2)`

The macros are identical to the corresponding `Py_BEGIN_CRITICAL_SECTION` and
`Py_BEGIN_CRITICAL_SECTION2` macros (e.g., they include braces), but they
accept a `PyMutex` instead of an object.

The new macros are still paired with the existing END macros
(`Py_END_CRITICAL_SECTION`, `Py_END_CRITICAL_SECTION2`).
2025-07-21 17:25:43 -04:00
Disconnect3d
d19bb44713
Doc/c-api/memory.rst: extend --without-pymalloc doc with ASan information (GH-136790)
* Doc/c-api/memory.rst: extend --without-pymalloc doc with ASan information

This commit extends the documentation for disabling pymalloc with the `--without-pymalloc` flag regarding why it is worth to use it when enabling AddressSanitizer for Python build (which is done, e.g., in CPython's CI builds).

I have tested the CPython latest main build with both ASan and pymalloc enabled and it seems to work just fine. I did run the `python -m test` suite which didn't uncover any ASan crashes (though, it detected some memory leaks, which I believe are irrelevant here).

I have discussed ASan and this flag with @encukou on the CPython Core sprint on EuroPython 2025. We initially thought that the `--without-pymalloc` flag is needed for ASan builds due to the fact pymalloc must hit the begining of page when determining if the memory to be freed comes from pymalloc or was allocated by the system malloc. In other words, we thought, that ASan would crash CPython during free of big objects (allocated by system malloc). It may be that this was the case in the past, but it is not the case anymore as the `address_in_range` function used by pymalloc is annotated to be skipped from the ASan instrumentation.

This code can be seen here:
acefb978dc/Objects/obmalloc.c (L2096-L2110)

While the annotation macro is defined here:
acefb978dc/Include/pyport.h (L582-L598)

And the corresponding attribute is documented in:
* for gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-no_005fsanitize_005faddress-function-attribute
* for clang: https://clang.llvm.org/docs/AttributeReference.html#no-sanitize-address-no-address-safety-analysis

* Update Doc/c-api/memory.rst

* Improve --with-address-sanitizer and pymalloc docs

---------

Co-authored-by: Petr Viktorin <encukou@gmail.com>
2025-07-19 13:52:54 +02:00
Adam Turner
c89a66feb1
GH-133711: Enable UTF-8 mode by default (PEP 686) (#133712)
Co-authored-by: Victor Stinner <vstinner@python.org>
2025-07-15 10:45:41 +01:00
Sergey B Kirpichev
e4654e0b3e
gh-136663: fix signatures of PyFloat_Pack/Unpack in docs (#136664) 2025-07-15 11:00:12 +05:30
Serhiy Storchaka
e18829a8ad
gh-132629: Deprecate accepting out-of-range values for unsigned integers in PyArg_Parse (GH-132630)
For unsigned integer formats in the PyArg_Parse* functions,
accepting Python integers with value that is larger than
the maximal value the corresponding C type or less than
the minimal value for the corresponding signed integer type
is now deprecated.
2025-07-13 12:44:54 +03:00
Peter Bierma
0d4fd10fba
Docs: Fix and improve the PyUnstable_Object_EnableDeferredRefcount documentation (GH-135323) 2025-07-13 02:46:13 -04:00
Petr Viktorin
85bc89f35f
gh-136209: Add .. c:var:: declarations for C exception types (GH-136210)
Co-authored-by: Victor Stinner <vstinner@python.org>
2025-07-10 13:07:55 +02:00
Petr Viktorin
73e1207a4e
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:`.
2025-07-07 14:05:17 +02:00
Petr Viktorin
2468aafe98
gh-135755: Document __future__.* and CO_* as proper Sphinx objects (GH-135980)
* 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.
2025-07-07 12:31:13 +02:00
Victor Stinner
da79ac9d26
gh-135075: Make PyObject_SetAttr() fail with NULL value and exception (#136180)
Make PyObject_SetAttr() and PyObject_SetAttrString() fail if called
with NULL value and an exception set.
2025-07-03 14:51:44 +02:00
Sam Gross
f41e9c750e
gh-134009: Expose PyMutex_IsLocked in the public C API (gh-134365)
The `PyMutex_IsLocked()` function is useful in assertions for verifying
that code maintains certain locking invariants.
2025-07-01 13:26:13 -04:00
Nicolas Trangez
579acf4562
gh-76595: Add note on PyCapsule_Import behavior (GH-134022) 2025-06-28 09:01:41 -04:00
Brian Schubert
34ce1920ca
Docs: Fix duplicate word typos (GH-135958) 2025-06-26 20:00:19 -04:00
Peter Bierma
ca87a47b3d
gh-135755: Docs: C API: Document missing PyFunction_GET* macros (GH-135762)
Co-authored-by: Brian Schubert <brianm.schubert@gmail.com>
Co-authored-by: Petr Viktorin <encukou@gmail.com>
2025-06-25 08:44:55 +00:00
Petr Viktorin
6aa0826ed7
gh-89488: Add warning about Py_BuildValue("p") needing exact int (GH-135610) 2025-06-23 12:35:59 +02:00
Rafael Fontenelle
6a16b3c440
Docs: Remove unnecessary trailing backslashes (GH-135781)
This fixes Sphinx's gettext extraction for translations.
2025-06-21 09:01:14 -04:00
Yuki Kobayashi
59963e866a
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`
2025-06-20 09:57:04 -04:00
Petr Viktorin
140731ff67
Document that PyType_GetModuleByDef returns a borrowed reference (GH-135666) 2025-06-19 09:00:41 +02:00
Yuki Kobayashi
46c60e0d0b
Docs: Fix markups for emphasis (GH-135598)
The word emphasis character `_` is not supported as sphinx markup, so changed to `*`.
2025-06-18 13:32:43 -04:00
Petr Viktorin
f4bc3a9320
gh-134160: Split extension module init from PyModule docs; emphasize multi-phase init (GH-135126)
Document behaviour of single-phase init. Call it "legacy".

Reorganize PyModule docs.

Move PyInit_modulename docs from the tutorial to reference documentation.

Move PyMODINIT_FUNC docs from generic macros to the new page.

Add doc stubs for `PYTHON_API_VERSION` & `PYTHON_ABI_VERSION`

Remove incorrect refcounts.dat entry for `PyModuleDef_Init`.
This removes the "Return value: Borrowed reference." note.
Instead, note that the function sometimes returns a borrowed reference,
sometimes as strong one.
(IMO, it's best to not think of `PyModuleDef` as a `PyObject` at all,
and act like it can't be reference-counted.)


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>
2025-06-13 16:39:35 +02:00
Malcolm Smith
b706ff003c
gh-133264: Correct documentation of how Py_Main and Py_RunMain handle SystemExit (#135337) 2025-06-11 17:23:47 +02:00
Victor Stinner
aaad2e81ce
gh-133968: Update PyUnicodeWriter_WriteASCII() documentation (#135297)
The function was added to Python 3.14.
2025-06-09 14:47:02 +02:00
Edward Z. Yang
8441b263af
bpo-45210: Document that error indicator may be set in tp_dealloc (#28358)
Signed-off-by: Edward Z. Yang <ezyang@fb.com>
Signed-off-by: Edward Z. Yang <ezyang@meta.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
2025-06-09 08:56:32 +00:00
Yuki Kobayashi
f00512db20
Docs: Update PyExc_* tables in the c-api documentation (GH-131640)
Add `PyExc_BaseExceptionGroup` and `PyExc_EncodingWarning`
2025-06-06 17:51:47 +02:00
Petr Viktorin
e413e26719
gh-134891: Add PyUnstable_Unicode_GET_CACHED_HASH (GH-134892) 2025-06-06 15:51:00 +02:00
Rafael Fontenelle
39859fcac5
Fix versionadded directive rendering in c-api/arg.rst (#135199) 2025-06-06 14:23:07 +02:00
Stan Ulbrych
0ac9e17fb4
gh-134830: Fix reference in Doc/extending/windows.rst (GH-134831)
Co-authored-by: Miro Hrončok <miro@hroncok.cz>
2025-06-03 00:08:20 +02:00
Rafael Fontenelle
c7051a3669
Remove newline in Doc/c-api/lifecycle.rst for gettext builder (GH-135013) 2025-06-02 21:13:08 +03:00
Petr Viktorin
eb145fabbd
gh-134160: Improve multi-phase init note on isolation & subinterpreters (GH-134775)
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
2025-05-30 16:27:54 +02:00
Inada Naoki
b367e27af9
Doc: remove unnecessary section header (GH-134917) 2025-05-30 17:59:23 +09:00
Victor Stinner
f49a07b531
gh-133968: Add PyUnicodeWriter_WriteASCII() function (#133973)
Replace most PyUnicodeWriter_WriteUTF8() calls with
PyUnicodeWriter_WriteASCII().

Unrelated change to please the linter: remove an unused
import in test_ctypes.

Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2025-05-29 14:54:30 +00:00
Petr Viktorin
4109a9c6b3
gh-133260: Remove claim that PyUnicode_InternFromString immortalizes (GH-134213) 2025-05-29 15:36:59 +02:00
Serhiy Storchaka
bac3fcba5b
gh-108512: Add and use new replacements for PySys_GetObject() (GH-111035)
Add functions PySys_GetAttr(), PySys_GetAttrString(),
PySys_GetOptionalAttr() and PySys_GetOptionalAttrString().
2025-05-28 20:11:09 +03:00
Victor Stinner
c3c88064f5
gh-133678: Document C API third party tools (#134526)
Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: Steve Dower <steve.dower@python.org>
2025-05-27 17:38:30 +02:00
neonene
96905bdd27
gh-134160: Use multi-phase init in documentation examples (#134296)
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
2025-05-26 21:43:35 +00:00
Julien Palard
24a47155d2
Fix sphinx-lint warnings (default-role used). (GH-134647) 2025-05-25 21:22:52 +02:00
Cody Maloney
b529b60fc2
gh-132246: Add special buffer methods to C API Type Object docs (gh-132247)
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.
2025-05-21 16:21:57 +02:00
Richard Hansen
3246ea514d
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

Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
2025-05-20 14:25:50 +02:00
da-woods
bb32f3c698
document Py_VISIT as a macro in the docs (#133688) 2025-05-18 21:58:43 +05:30
Peter Bierma
af6b3b825f
Docs: C API: Improve documentation around non-Python threads with subinterpreters (GH-131087)
Co-authored-by: Victor Stinner <vstinner@python.org>
2025-05-17 10:58:41 +02:00
Stan Ulbrych
f34ec09ba5
gh-46236: Document PyUnicode_BuildEncodingMap (#133270) 2025-05-09 17:19:07 +02:00