]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-118527: Use deferred reference counting for C functions on modules (#118529)
authorSam Gross <colesbury@gmail.com>
Fri, 3 May 2024 15:33:05 +0000 (11:33 -0400)
committerGitHub <noreply@github.com>
Fri, 3 May 2024 15:33:05 +0000 (11:33 -0400)
This addresses a scaling bottleneck in the free-threaded build when
calling functions like `math.floor()` concurrently from multiple
threads.

Objects/moduleobject.c

index d877edaf5453e10d1e279953bba1f5d5adfb506e..a570b13e1208637d2413a18a246eb72c1314d69f 100644 (file)
@@ -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;