mirror of
https://github.com/python/cpython.git
synced 2025-12-31 20:43:36 +00:00
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> |
||
|---|---|---|
| .. | ||
| clinic | ||
| abstract.c | ||
| buffer.c | ||
| bytes.c | ||
| code.c | ||
| codec.c | ||
| complex.c | ||
| config.c | ||
| datetime.c | ||
| dict.c | ||
| docstring.c | ||
| exceptions.c | ||
| file.c | ||
| float.c | ||
| frame.c | ||
| function.c | ||
| gc.c | ||
| getargs.c | ||
| hash.c | ||
| heaptype.c | ||
| immortal.c | ||
| import.c | ||
| list.c | ||
| long.c | ||
| mem.c | ||
| monitoring.c | ||
| numbers.c | ||
| object.c | ||
| parts.h | ||
| pyatomic.c | ||
| README.txt | ||
| run.c | ||
| set.c | ||
| structmember.c | ||
| time.c | ||
| tuple.c | ||
| type.c | ||
| unicode.c | ||
| util.h | ||
| vectorcall.c | ||
| watchers.c | ||
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.