Commit Graph

1778 Commits

Author SHA1 Message Date
Stan Ulbrych bba14c3e01
gh-46236: Document `PyUnicodeIter_Type` (GH-132925) 2025-04-29 14:23:06 +02:00
Eric Snow fe462f5a91
gh-132775: Drop PyUnstable_InterpreterState_GetMainModule() (gh-132978)
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__.
2025-04-28 12:46:22 -06:00
Petr Viktorin 4ebbfcf30e
gh-87135: Raise PythonFinalizationError when joining a blocked daemon thread (gh-130402)
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.
2025-04-28 15:48:48 +02:00
Serhiy Storchaka 632524a5cb
gh-132987: Support __index__() for "k" and "K" formats in PyArg_Parse (GH-132988) 2025-04-26 17:14:18 +03:00
Victor Stinner ac5424d6a9
gh-107954: Add audit event to PyConfig_Set() (#132958) 2025-04-25 18:30:39 +02:00
Victor Stinner 070d866567
gh-107954: Allow setting cpu_count in PyConfig_Set() (#132954)
* gh-107954: Allow setting cpu_count in PyConfig_Set()

* Update the doc
2025-04-25 18:29:55 +02:00
Bénédikt Tran 3fa024dec3
gh-132909: handle overflow for `'K'` format in `do_mkvalue` (#132911) 2025-04-25 11:02:57 +00:00
Kuba_Z2 984a314b9f
Fix a grammar error in the `Py_ALWAYS_INLINE` doc (#129304) 2025-04-24 17:20:48 +03:00
Sergey B Kirpichev 79f7c67bf6
gh-128813: hide mixed-mode functions for complex arithmetic from C-API (#131703) 2025-04-22 14:18:18 +02:00
Stan Ulbrych 5ffb89420c
gh-46236: Add Py_UNICODE_REPLACEMENT_CHARACTER doc (#132706)
Co-authored-by: Victor Stinner <vstinner@python.org>
2025-04-22 14:16:51 +02:00
RUANG (James Roy) 05d0559db0
gh-46236: Add PyUnicode_Resize() doc (#132628)
Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
2025-04-22 11:39:04 +02:00
RUANG (James Roy) 8768df2fe9
gh-46236: Add missing PyUnicode_FromOrdinal() doc (#132040) 2025-04-14 18:40:39 +02:00
Yongzi Li f69b344e09
Fix a typo in c-api/typeobj.rst (#132317) 2025-04-13 07:18:58 +00:00
Yongzi Li 03b18e0d8c
Docs: Fix a typo in `Doc/c-api/unicode.rst` (#132318) 2025-04-13 07:16:59 +00:00
da-woods 1e5798e372
Docs: Fix specifications of `gcvisitobjects_t` (#132433)
`gcvisitobjects_t` callbacks should return 1 for the iteration to continue instead of 0.
2025-04-12 17:36:02 +02:00
Bénédikt Tran 9ded6f0830
gh-111178: fix incorrect function signatures in docs (#132395)
Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
2025-04-11 14:59:38 +00:00
Serhiy Storchaka f5f1ac84b3
gh-112068: C API: Add support of nullable arguments in PyArg_Parse (GH-121303) 2025-04-08 22:08:00 +03:00
Cody Maloney 8421b648e9
gh-132246: Add PEP 688 to C Buffer Protocol docs (#132249) 2025-04-08 10:43:27 -07:00
Hugo van Kemenade c5e856a5dc Merge branch 'main' of https://github.com/python/cpython 2025-04-08 17:08:21 +03:00
Serhiy Storchaka 0e4cf9ce7c
gh-50333: Deprecate support of non-tuple sequences in PyArg_ParseTuple() (GH-128374)
Non-tuple sequences are deprecated as argument for the "(items)" format unit
in PyArg_ParseTuple() and other argument parsing functions if items contains
format units which store borrowed buffer or reference (e.g. "s" and "O").

str and bytearray are no longer accepted as valid sequences.
2025-04-08 14:26:32 +03:00
Hugo van Kemenade 29af6cee02 Python 3.14.0a7 2025-04-08 14:20:51 +03:00
Donghee Na 25275bda79
gh-131544: Update docs for PyType_AddWatcher (gh-132015) 2025-04-02 15:04:07 +00:00
Petr Viktorin 01ea4c77e5
gh-123909: Remove obsolete note in PyType_FromMetaclass docs (GH-131506)
Docs of the other `PyType_From*` functions link to `PyType_FromMetaclass`,
which noted that they differ for backwards compatibility reasons.
The note is no longer relevant in 3.14.
The other functions have `versionchanged` blurbs.
2025-03-24 13:06:21 +01:00
Peter Bierma 86d5fa95cf
gh-127989: C API: Refer to "attached thread states" instead of the GIL (GH-127990)
Co-authored-by: Victor Stinner <vstinner@python.org>
2025-03-20 13:06:59 +01:00
Cody Maloney a4832f6b9a
gh-131117: Update tp_finalize example to use PyErr_GetRaisedException (#131118)
The tp_finalize C API doc used PyErr_Fetch() and PyErr_Restore() in
its example code. That API was deprecated in 3.12.

Update to point to the suggested replacement function
PyErr_GetRaisedException() which has a sample usage.
2025-03-19 18:27:55 +01:00
Yuki Kobayashi a0478c9f0c
Docs: Fix documentation for "PyTypeObject Definition" (GH-130936)
The structure definition for `PyTypeObject` is in `Include/cpython/object.h`,
not in `Include/object.h`.
2025-03-19 14:46:32 +01:00
Yuki Kobayashi f819900245
gh-118915: Document `PY_MONITORING_IS_INSTRUMENTED_EVENT` (GH-128026) 2025-03-18 17:34:01 +01:00
Hugo van Kemenade 77b2c933ca Python 3.14.0a6 2025-03-14 17:05:02 +02:00
sharktide 6b932edc52
gh-130814: Enhance documentation for Python C API type objects (#130817)
The "Type Objects" title in `c-api/typeobj.rst`, duplicating the title of `c-api/type.rst`,
has been changed to "Type Objects Structures", thereby slightly improving Sphinx
search.
2025-03-14 10:53:13 +01:00
Russell Keith-Magee dd6d24e9d2
gh-130940: Modify default behavior of `PyConfig.use_system_logger` to enable on iOS (#131172)
Modify default behavior of use_system_log to enable on iOS.
2025-03-13 14:28:49 +08:00
Petr Viktorin ad0f618ab3
gh-129675: Update documentation for tp_basicsize & tp_itemsize (#129850)
* Update documentation for tp_basicsize & tp_itemsize

- Add alignment requirement
- Mention that ob_size is unreliable if you don't control it
- Add some links for context
- basicsize should include the base type in generaly not just PyObject

This adds a “by-the-way” link to `PyObject_New`, which shouldn't be
used for GC types. In order to be comfortable linking to it, I also
add a link to `PyObject_GC_New` from its docs. And the same for
`*Var` variants, while I'm here.

* Strongly suggest Py_SIZE & Py_SET_SIZE
2025-03-11 11:21:18 +01:00
RUANG (James Roy) faadb446d9
gh-46236: Add missing PyUnicode_Append() doc (#130531)
* Add missing PyUnicode_Append() doc

* Change the copied content

* Add '`` ``'

* Change doc

* Add PyUnicode_AppendAndDel function doc

* Change doc

* Add PyUnicode_AppendAndDel to refcounts

* Change doc

* Change doc

Co-authored-by: Petr Viktorin <encukou@gmail.com>

* Change doc

---------

Co-authored-by: Petr Viktorin <encukou@gmail.com>
2025-03-11 10:28:17 +01:00
Petr Viktorin d91cc9db15
gh-129666: Add C11/C++11 to docs and -pedantic-errors to GCC/clang test_c[pp]ext tests (GH-130692)
Disable pedantic check for c++03 (unlimited API)

Also add a check for c++03 *limited* API, which passes in pedantic mode
after removing a comma in the `PySendResult` declaration, and allowing
`long long`.
2025-03-04 14:10:09 +01:00
Yuki Kobayashi b3c18bfd82
gh-130711: Document `PyBaseObject_Type` (GH-130712)
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
2025-03-03 15:08:05 +01:00
Arijit Kumar Das 37145cb89f
Fix grammar typo in `Doc/c-api/arg.rst` (#130741) 2025-03-02 10:24:34 +01:00
Petr Viktorin ab11c09705
gh-129666: Revert "gh-129666: Add C11/C++11 to docs and `-pedantic-errors` to GCC/clang test_c[pp]ext tests (GH-130686)" (GH-130688)
This reverts commit 003e6d2b97.
2025-02-28 16:05:36 +00:00
Petr Viktorin 003e6d2b97
gh-129666: Add C11/C++11 to docs and `-pedantic-errors` to GCC/clang test_c[pp]ext tests (GH-130686) 2025-02-28 16:03:02 +01:00
Petr Viktorin e21863ce78
gh-46236: PyUnicode docs improvements (GH-129966)
Move deprecated PyUnicode API docs to new section

Move Py_UNICODE to a new "Deprecated API" section.

Formally soft-deprecate PyUnicode_READY, and move it

Document and soft-deprecate PyUnicode_IS_READY, and move it

Document PyUnicode_IS_ASCII, PyUnicode_CHECK_INTERNED

PyUnicode_New docs: Clarify requirements for "fresh" strings

PyUnicodeWriter_DecodeUTF8Stateful: Link "error-handlers"



Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2025-02-28 15:11:44 +01:00
Mark Shannon 014223649c
GH-130396: Use computed stack limits on linux (GH-130398)
* Implement C recursion protection with limit pointers for Linux, MacOS and Windows

* Remove calls to PyOS_CheckStack

* Add stack protection to parser

* Make tests more robust to low stacks

* Improve error messages for stack overflow
2025-02-25 09:24:48 +00:00
RUANG (James Roy) 9f25c1f012
gh-46236: Add docs for PyUnicode_GetDefaultEncoding() doc (GH-130335)
* Clarify sys.getdefaultencoding() documentation

* Add missing documentation for PyUnicode_GetDefaultEncoding,
  the C equivalent of sys.getdefaultencoding
2025-02-24 15:37:21 +01:00
Petr Viktorin fc8d2cba54
gh-129405: Fix doc for Py_mod_multiple_interpreters default, and add test (GH-129406) 2025-02-24 14:59:19 +01:00
Petr Viktorin ef29104f7d
GH-91079: Revert "GH-91079: Implement C stack limits using addresses, not counters. (GH-130007)" for now (GH130413)
Revert "GH-91079: Implement C stack limits using addresses, not counters. (GH-130007)" for now

Unfortunatlely, the change broke some buildbots.

This reverts commit 2498c22fa0.
2025-02-24 11:16:08 +01:00
Marc Mueller 0f5b82169e
gh-46236: Document PyUnicode_RSplit, PyUnicode_Partition and PyUnicode_RPartition (#130191)
Co-authored-by: Petr Viktorin <encukou@gmail.com>
2025-02-20 16:41:41 +01:00
Mark Shannon 2498c22fa0
GH-91079: Implement C stack limits using addresses, not counters. (GH-130007)
* Implement C recursion protection with limit pointers

* Remove calls to PyOS_CheckStack

* Add stack protection to parser

* Make tests more robust to low stacks

* Improve error messages for stack overflow
2025-02-19 11:44:57 +00:00
Pablo Galindo Salgado 51d4bf1e0e
bpo-45325: Add a new 'p' parameter to Py_BuildValue to convert an integer into a Python bool (#28634) 2025-02-18 17:14:11 +00:00
Yuki Kobayashi fc8c99a8ce
gh-130214: Document `PyEllipsis_Type` (GH-130215) 2025-02-17 13:56:33 +01:00
Stan Ulbrych 9837c2a214
gh-130169: Fix broken list markup in `Doc/c-api/function.rst` (#130174) 2025-02-16 13:55:31 +03:00
Stan Ulbrych 3402e133ef
gh-82045: Correct and deduplicate "isprintable" docs; add test. (GH-130118)
We had the definition of what makes a character "printable" documented in three places, giving two different definitions.
The definition in the comment on `_PyUnicode_IsPrintable` was inverted; correct that.

With that correction, the two definitions turn out to be equivalent -- but to confirm that, you have to go look up, or happen to know, that those are the only five "Other" categories and only three "Separator" categories in the Unicode character database.  That makes it hard for the reader to tell whether they really are the same, or if there's some subtle difference in the intended semantics.

Fix that by cutting the C API docs' and the C comment's copies of the subtle details, in favor of referring to the Python-level docs. That ensures it's explicit that these are all meant to agree, and also lets us concentrate improvements to the wording in one place.

Speaking of which, borrow some ideas from the C comment, along with other tweaks, to hopefully add a bit more clarity to that one newly-centralized copy in the docs.

Also add a thorough test that the implementation agrees with this definition.

Author:    Greg Price <gnprice@gmail.com>

Co-authored-by: Greg Price <gnprice@gmail.com>
2025-02-14 18:16:47 +01:00
Satyam Kumar 791cdfe141
gh-129912: Fix references to `Py_TPFLAGS_MANAGED_DICT` (gh-130044) 2025-02-12 17:48:14 -05:00
Hugo van Kemenade 3ae9101482 Python 3.14.0a5 2025-02-11 19:16:29 +02:00