Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0ee2d77

Browse filesBrowse files
gh-112070: make functools.lru_cache threadsafe in --disable-gil build (gh-112111)
* gh-112070: make `functools.lrucacle` threadsafe in --disable-gil build * gh-112070: update generate `functoolsmodule` files * gh-112070: add NEWS file * Delete Misc/NEWS.d/next/Library/2023-11-15-20-19-45.gh-issue-112070.q6OhcU.rst * gh-112070: reformat functoolsmodule.c --------- Co-authored-by: Sam Gross <colesbury@gmail.com>
1 parent 8cd70ee commit 0ee2d77
Copy full SHA for 0ee2d77

File tree

2 files changed

+25
-6
lines changed
Filter options

2 files changed

+25
-6
lines changed

‎Modules/_functoolsmodule.c

Copy file name to clipboardExpand all lines: Modules/_functoolsmodule.c
+10-3Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "Python.h"
22
#include "pycore_call.h" // _PyObject_CallNoArgs()
3+
#include "pycore_critical_section.h" // Py_BEGIN_CRITICAL_SECTION
34
#include "pycore_dict.h" // _PyDict_Pop_KnownHash()
45
#include "pycore_long.h" // _PyLong_GetZero()
56
#include "pycore_moduleobject.h" // _PyModule_GetState()
@@ -1274,7 +1275,11 @@ lru_cache_dealloc(lru_cache_object *obj)
12741275
static PyObject *
12751276
lru_cache_call(lru_cache_object *self, PyObject *args, PyObject *kwds)
12761277
{
1277-
return self->wrapper(self, args, kwds);
1278+
PyObject *result;
1279+
Py_BEGIN_CRITICAL_SECTION(self);
1280+
result = self->wrapper(self, args, kwds);
1281+
Py_END_CRITICAL_SECTION();
1282+
return result;
12781283
}
12791284

12801285
static PyObject *
@@ -1287,14 +1292,15 @@ lru_cache_descr_get(PyObject *self, PyObject *obj, PyObject *type)
12871292
}
12881293

12891294
/*[clinic input]
1295+
@critical_section
12901296
_functools._lru_cache_wrapper.cache_info
12911297
12921298
Report cache statistics
12931299
[clinic start generated code]*/
12941300

12951301
static PyObject *
12961302
_functools__lru_cache_wrapper_cache_info_impl(PyObject *self)
1297-
/*[clinic end generated code: output=cc796a0b06dbd717 input=f05e5b6ebfe38645]*/
1303+
/*[clinic end generated code: output=cc796a0b06dbd717 input=00e1acb31aa21ecc]*/
12981304
{
12991305
lru_cache_object *_self = (lru_cache_object *) self;
13001306
if (_self->maxsize == -1) {
@@ -1308,14 +1314,15 @@ _functools__lru_cache_wrapper_cache_info_impl(PyObject *self)
13081314
}
13091315

13101316
/*[clinic input]
1317+
@critical_section
13111318
_functools._lru_cache_wrapper.cache_clear
13121319
13131320
Clear the cache and cache statistics
13141321
[clinic start generated code]*/
13151322

13161323
static PyObject *
13171324
_functools__lru_cache_wrapper_cache_clear_impl(PyObject *self)
1318-
/*[clinic end generated code: output=58423b35efc3e381 input=6ca59dba09b12584]*/
1325+
/*[clinic end generated code: output=58423b35efc3e381 input=dfa33acbecf8b4b2]*/
13191326
{
13201327
lru_cache_object *_self = (lru_cache_object *) self;
13211328
lru_list_elem *list = lru_cache_unlink_list(_self);

‎Modules/clinic/_functoolsmodule.c.h

Copy file name to clipboardExpand all lines: Modules/clinic/_functoolsmodule.c.h
+15-3Lines changed: 15 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.