Skip to content

Commit

Permalink
pythongh-112070: make functools.lru_cache threadsafe in --disable-g…
Browse files Browse the repository at this point in the history
…il build (pythongh-112111)

* pythongh-112070: make `functools.lrucacle` threadsafe in --disable-gil build

* pythongh-112070: update generate `functoolsmodule` files

* pythongh-112070: add NEWS file

* Delete Misc/NEWS.d/next/Library/2023-11-15-20-19-45.gh-issue-112070.q6OhcU.rst

* pythongh-112070: reformat functoolsmodule.c

---------

Co-authored-by: Sam Gross <[email protected]>
  • Loading branch information
2 people authored and aisk committed Feb 11, 2024
1 parent d0b5576 commit d132795
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
13 changes: 10 additions & 3 deletions Modules/_functoolsmodule.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "Python.h"
#include "pycore_call.h" // _PyObject_CallNoArgs()
#include "pycore_critical_section.h" // Py_BEGIN_CRITICAL_SECTION
#include "pycore_dict.h" // _PyDict_Pop_KnownHash()
#include "pycore_long.h" // _PyLong_GetZero()
#include "pycore_moduleobject.h" // _PyModule_GetState()
Expand Down Expand Up @@ -1274,7 +1275,11 @@ lru_cache_dealloc(lru_cache_object *obj)
static PyObject *
lru_cache_call(lru_cache_object *self, PyObject *args, PyObject *kwds)
{
return self->wrapper(self, args, kwds);
PyObject *result;
Py_BEGIN_CRITICAL_SECTION(self);
result = self->wrapper(self, args, kwds);
Py_END_CRITICAL_SECTION();
return result;
}

static PyObject *
Expand All @@ -1287,14 +1292,15 @@ lru_cache_descr_get(PyObject *self, PyObject *obj, PyObject *type)
}

/*[clinic input]
@critical_section
_functools._lru_cache_wrapper.cache_info
Report cache statistics
[clinic start generated code]*/

static PyObject *
_functools__lru_cache_wrapper_cache_info_impl(PyObject *self)
/*[clinic end generated code: output=cc796a0b06dbd717 input=f05e5b6ebfe38645]*/
/*[clinic end generated code: output=cc796a0b06dbd717 input=00e1acb31aa21ecc]*/
{
lru_cache_object *_self = (lru_cache_object *) self;
if (_self->maxsize == -1) {
Expand All @@ -1308,14 +1314,15 @@ _functools__lru_cache_wrapper_cache_info_impl(PyObject *self)
}

/*[clinic input]
@critical_section
_functools._lru_cache_wrapper.cache_clear
Clear the cache and cache statistics
[clinic start generated code]*/

static PyObject *
_functools__lru_cache_wrapper_cache_clear_impl(PyObject *self)
/*[clinic end generated code: output=58423b35efc3e381 input=6ca59dba09b12584]*/
/*[clinic end generated code: output=58423b35efc3e381 input=dfa33acbecf8b4b2]*/
{
lru_cache_object *_self = (lru_cache_object *) self;
lru_list_elem *list = lru_cache_unlink_list(_self);
Expand Down
18 changes: 15 additions & 3 deletions Modules/clinic/_functoolsmodule.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d132795

Please sign in to comment.