Skip to content

Commit 608192e

Browse files
authored
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.
1 parent c2627d6 commit 608192e

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

Objects/moduleobject.c

+1
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ _add_methods_to_object(PyObject *module, PyObject *name, PyMethodDef *functions)
183183
if (func == NULL) {
184184
return -1;
185185
}
186+
_PyObject_SetDeferredRefcount(func);
186187
if (PyObject_SetAttrString(module, fdef->ml_name, func) != 0) {
187188
Py_DECREF(func);
188189
return -1;

0 commit comments

Comments
 (0)