cpython/Include/cpython
Neil Schemenauer cdba68e563
[3.15] gh-159136: Avoid stop-the-world when setting function name attributes (gh-159269) (gh-159725)
Setting __name__, __qualname__, __doc__ or __module__ on a function
stopped the world in the free-threaded build since gh-154826 and
gh-154851, making functools.wraps() orders of magnitude slower with
multiple threads.

Use the per-object critical section and _PyObject_XSetRefDelayed()
instead, as gen_set_name() already does.  Use acquire loads in the
readers and hold strong references across error reporting, tracing, and
eval-frame recording that may execute Python or detach the thread.  The
__code__, __defaults__, __kwdefaults__ and __closure__ setters still
stop the world to clear func_version.

Document synchronization requirements for direct field access and the
lifetime of borrowed function attributes.

(cherry picked from commit 010bebbf9f)
2026-10-29 15:17:50 -07:00
..
abstract.h
audit.h
bytearrayobject.h
bytesobject.h
cellobject.h
ceval.h
classobject.h
code.h [3.15] gh-141004: Document remaining parts of the public C API (GH-159892) (GH-160067) 2026-10-21 18:22:50 +00:00
compile.h
complexobject.h
context.h
critical_section.h
descrobject.h
dictobject.h [3.15] gh-141004: Document remaining parts of the public C API (GH-159892) (GH-160067) 2026-10-21 18:22:50 +00:00
fileobject.h
fileutils.h
floatobject.h
frameobject.h
funcobject.h [3.15] gh-159136: Avoid stop-the-world when setting function name attributes (gh-159269) (gh-159725) 2026-10-29 15:17:50 -07:00
genobject.h
import.h [3.15] gh-159808: Sync documented C API structs with their headers (GH-159812) (#160074) 2026-10-21 18:17:16 +00:00
initconfig.h
listobject.h
longintrepr.h
longobject.h
marshal.h
memoryobject.h
methodobject.h
modsupport.h
monitoring.h
object.h
objimpl.h
odictobject.h
picklebufobject.h
pthread_stubs.h
pyatomic.h [3.15] gh-160208: Add a private wrapper around __STDC_VERSION__ (GH-160376) (GH-160437) 2026-10-23 20:31:48 +02:00
pyatomic_gcc.h [3.15] gh-158197: Fix split dict iteration during concurrent deletion (gh-158686) (#159953) 2026-10-20 17:03:22 -07:00
pyatomic_msc.h [3.15] gh-158197: Fix split dict iteration during concurrent deletion (gh-158686) (#159953) 2026-10-20 17:03:22 -07:00
pyatomic_std.h [3.15] gh-158197: Fix split dict iteration during concurrent deletion (gh-158686) (#159953) 2026-10-20 17:03:22 -07:00
pyctype.h
pydebug.h
pyerrors.h
pyfpe.h
pyframe.h
pyhash.h
pylifecycle.h
pylock.h
pymem.h
pystate.h
pystats.h
pythonrun.h
pythread.h
pytime.h
sentinelobject.h
setobject.h
sliceobject.h
structseq.h
traceback.h
tracemalloc.h
tupleobject.h
unicodeobject.h
warnings.h
weakrefobject.h