2
2
/* Function object implementation */
3
3
4
4
#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()
10
11
11
12
12
13
static const char *
@@ -863,13 +864,16 @@ static PyObject *
863
864
func_get_annotations (PyObject * self , void * Py_UNUSED (ignored ))
864
865
{
865
866
PyFunctionObject * op = _PyFunction_CAST (self );
867
+ PyObject * d ;
868
+ Py_BEGIN_CRITICAL_SECTION (self );
866
869
if (op -> func_annotations == NULL &&
867
870
(op -> func_annotate == NULL || !PyCallable_Check (op -> func_annotate ))) {
868
871
op -> func_annotations = PyDict_New ();
869
872
if (op -> func_annotations == NULL )
870
873
return NULL ;
871
874
}
872
- PyObject * d = func_get_annotation_dict (op );
875
+ d = func_get_annotation_dict (op );
876
+ Py_END_CRITICAL_SECTION ();
873
877
return Py_XNewRef (d );
874
878
}
875
879
@@ -887,8 +891,10 @@ func_set_annotations(PyObject *self, PyObject *value, void *Py_UNUSED(ignored))
887
891
"__annotations__ must be set to a dict object" );
888
892
return -1 ;
889
893
}
894
+ Py_BEGIN_CRITICAL_SECTION (self );
890
895
Py_XSETREF (op -> func_annotations , Py_XNewRef (value ));
891
896
Py_CLEAR (op -> func_annotate );
897
+ Py_END_CRITICAL_SECTION ();
892
898
return 0 ;
893
899
}
894
900
0 commit comments