22/* Function object implementation */
33
44#include "Python.h"
5- #include "pycore_dict.h" // _Py_INCREF_DICT()
6- #include "pycore_long.h" // _PyLong_GetOne()
7- #include "pycore_modsupport.h" // _PyArg_NoKeywords()
8- #include "pycore_object.h" // _PyObject_GC_UNTRACK()
9- #include "pycore_pyerrors.h" // _PyErr_Occurred()
5+ #include "pycore_dict.h" // _Py_INCREF_DICT()
6+ #include "pycore_long.h" // _PyLong_GetOne()
7+ #include "pycore_modsupport.h" // _PyArg_NoKeywords()
8+ #include "pycore_object.h" // _PyObject_GC_UNTRACK()
9+ #include "pycore_pyerrors.h" // _PyErr_Occurred()
10+ #include "pycore_critical_section.h" // Py_BEGIN_CRITICAL_SECTION()
1011
1112
1213static const char *
@@ -863,13 +864,16 @@ static PyObject *
863864func_get_annotations (PyObject * self , void * Py_UNUSED (ignored ))
864865{
865866 PyFunctionObject * op = _PyFunction_CAST (self );
867+ PyObject * d ;
868+ Py_BEGIN_CRITICAL_SECTION (self );
866869 if (op -> func_annotations == NULL &&
867870 (op -> func_annotate == NULL || !PyCallable_Check (op -> func_annotate ))) {
868871 op -> func_annotations = PyDict_New ();
869872 if (op -> func_annotations == NULL )
870873 return NULL ;
871874 }
872- PyObject * d = func_get_annotation_dict (op );
875+ d = func_get_annotation_dict (op );
876+ Py_END_CRITICAL_SECTION ();
873877 return Py_XNewRef (d );
874878}
875879
@@ -887,8 +891,10 @@ func_set_annotations(PyObject *self, PyObject *value, void *Py_UNUSED(ignored))
887891 "__annotations__ must be set to a dict object" );
888892 return -1 ;
889893 }
894+ Py_BEGIN_CRITICAL_SECTION (self );
890895 Py_XSETREF (op -> func_annotations , Py_XNewRef (value ));
891896 Py_CLEAR (op -> func_annotate );
897+ Py_END_CRITICAL_SECTION ();
892898 return 0 ;
893899}
894900
0 commit comments