cpython/Modules/_testcapi
Victor Stinner 8356e9c721
[3.14] gh-158585: Fix _PyBytes_Resize() if hash value is already computed (#159585)
* [3.15] gh-158585: Fix _PyBytes_Resize() if hash value is already computed (#159555)

* gh-158585: Fix _PyBytes_Resize() if hash value is already computed (#158589)

_PyBytes_Resize() now creates a new bytes object if the hash value
was already computed.

bytes_resize_inplace() no longer sets the hash value to -1, since
this function must not be called if the hash value was already
computed.

Add tests on PyUnicode_Resize().

(cherry picked from commit 6e7738bb5e)

* gh-158585: Fix refleak in _testcapi.bytes_resize() (#158806)

(cherry picked from commit 587b7a5b31)
(cherry picked from commit 251278d5ee)

* Adjust code for 3.14
2026-10-16 22:09:04 +00:00
..
clinic [3.14] gh-156204: Guard recursion in PyErr_GivenExceptionMatches (GH-156205) (GH-158623) 2026-10-02 20:50:00 +00:00
abstract.c
buffer.c
bytes.c [3.14] gh-158585: Fix _PyBytes_Resize() if hash value is already computed (#159585) 2026-10-16 22:09:04 +00:00
code.c
codec.c
complex.c
config.c
datetime.c
dict.c
docstring.c
exceptions.c [3.14] gh-156204: Guard recursion in PyErr_GivenExceptionMatches (GH-156205) (GH-158623) 2026-10-02 20:50:00 +00:00
file.c
float.c
frame.c
function.c [3.14] gh-144629: Add test for the PyFunction_GetAnnotations() function (GH-144630) (#144670) 2026-02-10 15:05:25 +00:00
gc.c [3.14] gh-156395: Report frozen objects on free-threaded GC build (GH-156396) (#156421) 2026-08-28 09:51:31 -07:00
getargs.c
hash.c
heaptype.c [3.14] gh-129849: Add tests for Py_tp_bases (GH-143208) (#146225) 2026-03-21 15:22:58 +05:30
immortal.c [3.14] gh-143050: Correct PyLong_FromString() to use _PyLong_Negate() (GH-145901) (#147331) 2026-03-31 16:14:12 +02:00
import.c
list.c
long.c
mem.c [3.14] gh-157242: Do not close io.BytesIO on MemoryError (#159529) 2026-10-16 13:33:50 +00:00
monitoring.c
numbers.c
object.c [3.14] gh-155905: Fix error handling in _testcapi helpers (GH-155906) (GH-156581) 2026-08-29 16:32:57 +00:00
parts.h [3.14] gh-151130: Add more tests for PyWeakref_* C API (GH-151131) (GH-151141) 2026-06-09 11:45:18 +00:00
pyatomic.c
README.txt
run.c [3.14] gh-152132: Test Py_CompileString() in test_capi.test_run (#153470) (#153473) 2026-07-10 02:08:14 +00:00
set.c
structmember.c
time.c
tuple.c
type.c [3.14] gh-155503: Add more PyType C API tests (#155505) (#159085) (#159089) 2026-10-09 22:11:41 +00:00
unicode.c [3.14] gh-158451: Add _PyUnicodeWriter_WriteLatin1String() test (#158464) (#159549) 2026-10-16 21:50:55 +00:00
util.h [3.14] gh-156939: Add tests on the PyUnicode C API (#159533) (#159539) 2026-10-16 15:22:29 +00:00
vectorcall.c
watchers.c [3.14] gh-145235: Make dict watcher API thread-safe for free-threaded builds (gh-145233) (#149691) 2026-05-12 13:21:31 -04:00
weakref.c [3.14] gh-151130: Add more tests for PyWeakref_* C API (GH-151131) (GH-151141) 2026-06-09 11:45:18 +00:00

Tests in this directory are compiled into the _testcapi extension.
The main file for the extension is Modules/_testcapimodule.c, which
calls `_PyTestCapi_Init_*` from these functions.

General guideline when writing test code for C API.
* Use Argument Clinic to minimise the amount of boilerplate code.
* Add a newline between the argument spec and the docstring.
* If a test description is needed, make sure the added docstring clearly and succinctly describes purpose of the function.
* DRY, use the clone feature of Argument Clinic.
* Try to avoid adding new interned strings; reuse existing parameter names if possible. Use the `as` feature of Argument Clinic to override the C variable name, if needed.