summaryrefslogtreecommitdiffstats
path: root/Modules/_testcapimodule.c
Commit message (Collapse)AuthorAgeFilesLines
* [3.12] gh-129185: Fix PyTraceMalloc_Untrack() at Python exit (#129191) ↵Victor Stinner2025-01-231-0/+1
| | | | | | | | | | | | | | | | | | (#129217) (#129221) [3.13] gh-129185: Fix PyTraceMalloc_Untrack() at Python exit (#129191) (#129217) gh-129185: Fix PyTraceMalloc_Untrack() at Python exit (#129191) Support calling PyTraceMalloc_Track() and PyTraceMalloc_Untrack() during late Python finalization. * Call _PyTraceMalloc_Fini() later in Python finalization. * Test also PyTraceMalloc_Untrack() without the GIL * PyTraceMalloc_Untrack() now gets the GIL. * Test also PyTraceMalloc_Untrack() in test_tracemalloc_track_race(). (cherry picked from commit 46c7e13c055c218e18b0424efc60965e6a5fe6ea) (cherry picked from commit e3b3e01d6a6f43c15890d14f139f38155601643a)
* [3.12] gh-111495: Add more tests on PyEval C APIs (#122789) (#128987) (#129023)Victor Stinner2025-01-191-14/+3
| | | | | | | | | | | * Add Lib/test/test_capi/test_eval.py * Add Modules/_testlimitedcapi/eval.c (cherry picked from commit bf8b3746398ea756c97e3cf263d63ca3ce3a544e) * gh-111495: Fix refleaks in test_capi.test_eval tests (#122851) (cherry picked from commit b4a316087c32d83e375087fd35fc511bc430ee8b) (cherry picked from commit 430ccbc009aa7a2da92b85d7aeadd39e1666e875)
* [3.12] gh-128679: Fix tracemalloc.stop() race conditions (#128897) (#129022)Victor Stinner2025-01-191-0/+100
| | | | | | | | | | | | | | | | | [3.13] gh-128679: Fix tracemalloc.stop() race conditions (#128897) tracemalloc_alloc(), tracemalloc_realloc(), PyTraceMalloc_Track(), PyTraceMalloc_Untrack() and _PyTraceMalloc_TraceRef() now check tracemalloc_config.tracing after calling TABLES_LOCK(). _PyTraceMalloc_Stop() now protects more code with TABLES_LOCK(), especially setting tracemalloc_config.tracing to 1. Add a test using PyTraceMalloc_Track() to test tracemalloc.stop() race condition. Call _PyTraceMalloc_Init() at Python startup. (cherry picked from commit 6b47499510e47c0401d1f6cca2660fc12c496e39)
* [3.12] gh-128911: Add tests on the PyImport C API (GH-128915) (GH-128960) ↵Serhiy Storchaka2025-01-191-0/+3
| | | | | | | | | | | | | | (#128989) * Add Modules/_testlimitedcapi/import.c * Add Lib/test/test_capi/test_import.py * Remove _testcapi.check_pyimport_addmodule(): tests already covered by newly added tests. (cherry picked from commit 34ded1a1a10204635cad27830fcbee2f8547e8ed) Co-authored-by: Victor Stinner <vstinner@python.org> Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> (cherry picked from commit d95ba9fa1110534b7247fa2ff12b90e930c93256)
* [3.12] gh-119585: Fix crash involving `PyGILState_Release()` and ↵Sam Gross2024-05-311-0/+9
| | | | | | | | | | | `PyThreadState_Clear()` (GH-119753) (#119861) Make sure that `gilstate_counter` is not zero in when calling `PyThreadState_Clear()`. A destructor called from `PyThreadState_Clear()` may call back into `PyGILState_Ensure()` and `PyGILState_Release()`. If `gilstate_counter` is zero, it will try to create a new thread state before the current active thread state is destroyed, leading to an assertion failure or crash. (cherry picked from commit bcc1be39cb1d04ad9fc0bd1b9193d3972835a57c)
* [3.12] gh-117968: Add tests for the part of the PyRun family of the C API ↵Serhiy Storchaka2024-04-221-0/+13
| | | | | | | | (GH-117982) (GH-118011) (cherry picked from commit 6078f2033ea15a16cf52fe8d644a95a3be72d2e3) Co-authored-by: NGRsoftlab <78017794+NGRsoftlab@users.noreply.github.com> Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
* [3.12] gh-117694: Improve tests for PyEval_EvalCodeEx() (GH-117695) (GH-117884)Miss Islington (bot)2024-04-151-80/+33
| | | | | (cherry picked from commit 57bdb75975ff90f95248c59fda34345f3bfff3c4) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* [3.12] gh-117021: Fix integer overflow in PyLong_AsPid() on non-Windows ↵Serhiy Storchaka2024-03-201-0/+1
| | | | | 64-bit platforms (GH-117064) (GH-117070) (cherry picked from commit 519b2ae22b54760475bbf62b9558d453c703f9c6)
* [3.12] Check for valid tp_version_tag in specializer (gh-89811) (gh-114216)Peter Lazorchak2024-01-191-0/+29
|
* [3.12] bpo-36796: Clean the error handling in _testcapimodule.c (GH-13085) ↵Miss Islington (bot)2023-12-141-6/+12
| | | | | | | (GH-113132) (cherry picked from commit a723a13bf135306cdc5999a959596bfb487e8f4f) Co-authored-by: Zackery Spytz <zspytz@gmail.com>
* [3.12] gh-111495: add stub files for C API test modules (GH-111586) (GH-111592)Sergey B Kirpichev2023-11-011-0/+24
| | | | | This is to reduce merge conflicts (Modules/Setup.stdlib.in) for subsequent pull requests for the issue. (cherry picked from commit 33ed5fa69dbe25d64a910c450be527f4db9dc5dd)
* [3.12] gh-111065: Add more tests for the C API with the PySys_ prefix ↵Serhiy Storchaka2023-10-251-31/+3
| | | | | | | | | | | | (GH-111067) (GH-111305) * Move existing tests for PySys_GetObject() and PySys_SetObject() into specialized files. * Add test for PySys_GetXOptions() using _testcapi. * Add tests for PySys_FormatStdout(), PySys_FormatStderr(), PySys_WriteStdout() and PySys_WriteStderr() using ctypes. (cherry picked from commit b2ba2985275d1200e5c44c3f224d754141fc5292)
* [3.12] gh-110628: Add tests for PyLong C API (GH-110629) (GH-110854)Serhiy Storchaka2023-10-141-0/+2
| | | (cherry picked from commit 9d40ebf1902812fad6aa85ede7b6f1fdff3c1291)
* [3.12] gh-84489: C API: Add tests for Py_BuildValue() (GH-110596) (GH-110680)Miss Islington (bot)2023-10-111-0/+37
| | | | | (cherry picked from commit 5c6e85480ad8365c1b05fdbd678c7867103f7d76) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* [3.12] gh-110525: Add CAPI tests for set and frozenset objects (GH-110526). ↵Nikita Sobolev2023-10-091-0/+3
| | | | | (GH-110547) (cherry picked from commit c49edd7d9c5395a6a6696a4846f56bc8b2b22792)
* [3.12] gh-109496: Detect Py_DECREF() after dealloc in debug mode (GH-109539) ↵Miss Islington (bot)2023-09-181-0/+21
| | | | | | | | | | | | | | | | | (#109545) gh-109496: Detect Py_DECREF() after dealloc in debug mode (GH-109539) On a Python built in debug mode, Py_DECREF() now calls _Py_NegativeRefcount() if the object is a dangling pointer to deallocated memory: memory filled with 0xDD "dead byte" by the debug hook on memory allocators. The fix is to check the reference count *before* checking for _Py_IsImmortal(). Add test_decref_freed_object() to test_capi.test_misc. (cherry picked from commit 0bb0d88e2d4e300946e399e088e2ff60de2ccf8c) Co-authored-by: Victor Stinner <vstinner@python.org>
* [3.12] C API tests: use special markers to test that output parameters were ↵Serhiy Storchaka2023-09-081-0/+6
| | | | | | set (GH-109014) (#109023) [3.12] C API tests: use special markers to test that output parameters were set (GH-109014). (cherry picked from commit bf414b7fcb7c8ba780a5e1d9f320ecef0c7f9488)
* [3.12] Add Modules/_testcapi/util.h header (GH-108774) (#108780)Miss Islington (bot)2023-09-021-16/+2
| | | | | | | | Add Modules/_testcapi/util.h header (GH-108774) It contains common macros used in C API tests. (cherry picked from commit 0e01fac315dfa705ac8a6954485546f28cf4c87d) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* [3.12] gh-107178: Add the C API tests for the Abstract Objects Layer ↵Serhiy Storchaka2023-08-161-162/+7
| | | | | | | | | | | | (GH-107179) (#107728) Cover all the Mapping Protocol, almost all the Sequence Protocol (except PySequence_Fast) and a part of the Object Protocol. Move existing tests to Lib/test/test_capi/test_abstract.py and Modules/_testcapi/abstract.c. Add also tests for PyDict C API.. (cherry picked from commit 16c9415fba4972743f1944ebc44946e475e68bc4)
* [3.12] gh-107735: Add C API tests for PySys_GetObject() and ↵Serhiy Storchaka2023-08-161-0/+41
| | | | | | PySys_SetObject() (GH-107736) (#107740) [3.12] gh-107735: Add C API tests for PySys_GetObject() and PySys_SetObject() (GH-107736). (cherry picked from commit bea5f93196d213d6fbf4ba8984caf4c3cd1da882)
* [3.12] gh-105227: Add PyType_GetDict() (GH-105747) (#106600)Miss Islington (bot)2023-07-101-0/+25
| | | | | | | | | | gh-105227: Add PyType_GetDict() (GH-105747) This compensates for static builtin types having `tp_dict` set to `NULL`. (cherry picked from commit a840806d338805fe74a9de01081d30da7605a29f) Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com> Co-authored-by: Petr Viktorin <encukou@gmail.com>
* [3.12] gh-105603: Change the PyInterpreterConfig.own gil Field (gh-105620) ↵Miss Islington (bot)2023-06-131-7/+7
| | | | | | | | (gh-105731) We are changing it to be more flexible that a strict bool can be for possible future expanded used cases. (cherry picked from commit b97e14a806477af4225777d215ac38c0d9b845f0) Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
* [3.12] gh-104614: Fix potential ref. leak in ↵Miss Islington (bot)2023-06-021-1/+3
| | | | | | | _testcapimodule/get_basic_static_type() (GH-105225) (#105248) (cherry picked from commit e01b04c9075c6468ed57bc883693ec2a06a6dd8e) Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
* [3.12] gh-104614: Make Sure ob_type is Always Set Correctly by ↵Miss Islington (bot)2023-06-011-0/+45
| | | | | | | | | | PyType_Ready() (gh-105122) (gh-105211) When I added the relevant condition to type_ready_set_bases() in gh-103912, I had missed that the function also sets tp_base and ob_type (if necessary). That led to problems for third-party static types. We fix that here, by making those extra operations distinct and by adjusting the condition to be more specific. (cherry picked from commit 1469393) Co-authored-by: Eric Snow ericsnowcurrently@gmail.com
* [3.12] gh-105020: Share tp_bases and tp_mro Between Interpreters For All ↵Miss Islington (bot)2023-06-011-0/+23
| | | | | | | | Static Builtin Types (gh-105115) (gh-105124) In gh-103912 we added tp_bases and tp_mro to each PyInterpreterState.types.builtins entry. However, doing so ignored the fact that both PyTypeObject fields are public API, and not documented as internal (as opposed to tp_subclasses). We address that here by reverting back to shared objects, making them immortal in the process. (cherry picked from commit 7be667d) Co-authored-by: Eric Snow ericsnowcurrently@gmail.com
* gh-104645: fix error handling in marshal tests (#104646)Irit Katriel2023-05-191-18/+14
|
* GH-102818: Do not call `PyTraceBack_Here` in sys.settrace trampoline. ↵Mark Shannon2023-05-191-0/+28
| | | | (GH-104579)
* gh-93649: Split gc- and allocation tests from _testcapimodule.c (GH-104403)Jurica Bradarić2023-05-121-326/+3
|
* gh-99113: Add PyInterpreterConfig.own_gil (gh-104204)Eric Snow2023-05-051-2/+10
| | | | | We also add PyInterpreterState.ceval.own_gil to record if the interpreter actually has its own GIL. Note that for now we don't actually respect own_gil; all interpreters still share the one GIL. However, PyInterpreterState.ceval.own_gil does reflect PyInterpreterConfig.own_gil. That lie is a temporary one that we will fix when the GIL really becomes per-interpreter.
* gh-104190: fix ubsan crash (#104191)sunmy20192023-05-051-1/+1
|
* gh-99593: Add tests for Unicode C API (part 2) (#99868)Serhiy Storchaka2023-05-041-0/+1
| | | | | Add tests for lower-level functions. Co-authored-by: Oleg Iarygin <oleg@arhadthedev.net>
* gh-102500: Implement PEP 688 (#102521)Jelle Zijlstra2023-05-041-1/+3
| | | Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
* gh-103509: PEP 697 -- Limited C API for Extending Opaque Types (GH-103511)Petr Viktorin2023-05-041-0/+3
| | | | Co-authored-by: Oleg Iarygin <oleg@arhadthedev.net> Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
* gh-104109: Expose Py_NewInterpreterFromConfig() in the Public C-API (gh-104110)Eric Snow2023-05-031-2/+2
| | | | | We also expose PyInterpreterConfig. This is part of the PEP 684 (per-interpreter GIL) implementation. We will add docs as soon as we can. FYI, I'm adding the new config field for per-interpreter GIL in gh-99114.
* gh-84436: Add integration C API tests for immortal objects (gh-103962)Dong-hee Na2023-05-021-0/+3
|
* gh-103743: Add PyUnstable_Object_GC_NewWithExtraData (GH-103744)Jurica Bradarić2023-05-021-1/+104
| | | | Co-authored-by: Petr Viktorin <encukou@gmail.com> Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
* gh-101659: Isolate "obmalloc" State to Each Interpreter (gh-101660)Eric Snow2023-04-241-2/+10
| | | | | | | | | | | | | | This is strictly about moving the "obmalloc" runtime state from `_PyRuntimeState` to `PyInterpreterState`. Doing so improves isolation between interpreters, specifically most of the memory (incl. objects) allocated for each interpreter's use. This is important for a per-interpreter GIL, but such isolation is valuable even without it. FWIW, a per-interpreter obmalloc is the proverbial canary-in-the-coalmine when it comes to the isolation of objects between interpreters. Any object that leaks (unintentionally) to another interpreter is highly likely to cause a crash (on debug builds at least). That's a useful thing to know, relative to interpreter isolation.
* gh-103091: Add PyUnstable_Type_AssignVersionTag (#103095)Brett Simmers2023-04-241-0/+13
|
* gh-101659: Add _Py_AtExit() (gh-103298)Eric Snow2023-04-061-0/+32
| | | | | The function is like Py_AtExit() but for a single interpreter. This is a companion to the atexit module's register() function, taking a C callback instead of a Python one. We also update the _xxinterpchannels module to use _Py_AtExit(), which is the motivating case. (This is inspired by pain points felt while working on gh-101660.)
* GH-94808: Cover `PyOS_mystrnicmp` and `PyOS_mystricmp` (gh-102469)Artem Mukhin2023-03-221-0/+3
|
* gh-98608: Stop Treating All Errors from _Py_NewInterpreterFromConfig() as ↵Eric Snow2023-03-211-2/+6
| | | | | | | Fatal (gh-102657) Prior to this change, errors in _Py_NewInterpreterFromConfig() were always fatal. Instead, callers should be able to handle such errors and keep going. That's what this change supports. (This was an oversight in the original implementation of _Py_NewInterpreterFromConfig().) Note that the existing [fatal] behavior of the public Py_NewInterpreter() is preserved. https://github.com/python/cpython/issues/98608
* gh-102013: Add PyUnstable_GC_VisitObjects (#102014)Jacob Bower2023-03-141-0/+69
|
* gh-102304: Consolidate Direct Usage of _Py_RefTotal (gh-102514)Eric Snow2023-03-081-6/+1
| | | | | This simplifies further changes to _Py_RefTotal (e.g. make it atomic or move it to PyInterpreterState). https://github.com/python/cpython/issues/102304
* gh-101101: Unstable C API tier (PEP 689) (GH-101102)Petr Viktorin2023-02-281-0/+3
|
* gh-102192: Replace PyErr_Fetch/Restore etc by more efficient alternatives ↵Irit Katriel2023-02-241-4/+3
| | | | (in Modules/) (#102196)
* gh-93649: Split exception tests from _testcapimodule.c (GH-102173)Erlend E. Aasland2023-02-231-287/+3
| | | Automerge-Triggered-By: GH:erlend-aasland
* GH-100719: Remove redundant `gi_code` field from generator object. (GH-100749)Mark Shannon2023-02-231-0/+11
|
* gh-98627: Add an Optional Check for Extension Module Subinterpreter ↵Eric Snow2023-02-161-2/+10
| | | | | | | | | | | | | | | Compatibility (gh-99040) Enforcing (optionally) the restriction set by PEP 489 makes sense. Furthermore, this sets the stage for a potential restriction related to a per-interpreter GIL. This change includes the following: * add tests for extension module subinterpreter compatibility * add _PyInterpreterConfig.check_multi_interp_extensions * add Py_RTFLAGS_MULTI_INTERP_EXTENSIONS * add _PyImport_CheckSubinterpIncompatibleExtensionAllowed() * fail iff the module does not implement multi-phase init and the current interpreter is configured to check https://github.com/python/cpython/issues/98627
* gh-101819: Remove _testcapi dependencies on specific _io symbols (#101918)Erlend E. Aasland2023-02-151-2/+6
|
* GH-101578: Normalize the current exception (GH-101607)Mark Shannon2023-02-081-0/+37
| | | | | | | | | | * Make sure that the current exception is always normalized. * Remove redundant type and traceback fields for the current exception. * Add new API functions: PyErr_GetRaisedException, PyErr_SetRaisedException * Add new API functions: PyException_GetArgs, PyException_SetArgs