From 608192ee2f6c60aaae1c6f2f64ea45ad2667ff2d Mon Sep 17 00:00:00 2001 From: Sam Gross Date: Fri, 3 May 2024 11:33:05 -0400 Subject: [PATCH] gh-118527: Use deferred reference counting for C functions on modules (#118529) This addresses a scaling bottleneck in the free-threaded build when calling functions like `math.floor()` concurrently from multiple threads. --- Objects/moduleobject.c | 1 + 1 file changed, 1 insertion(+) diff --git a/Objects/moduleobject.c b/Objects/moduleobject.c index d877edaf545..a570b13e120 100644 --- a/Objects/moduleobject.c +++ b/Objects/moduleobject.c @@ -183,6 +183,7 @@ _add_methods_to_object(PyObject *module, PyObject *name, PyMethodDef *functions) if (func == NULL) { return -1; } + _PyObject_SetDeferredRefcount(func); if (PyObject_SetAttrString(module, fdef->ml_name, func) != 0) { Py_DECREF(func); return -1;