Skip to content

Commit 79f1043

Browse files
committed
use critical sections for C APIs
1 parent 8875af1 commit 79f1043

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

Objects/funcobject.c

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -409,46 +409,63 @@ PyFunction_New(PyObject *code, PyObject *globals)
409409
PyObject *
410410
PyFunction_GetCode(PyObject *op)
411411
{
412+
PyObject *code = NULL;
413+
Py_BEGIN_CRITICAL_SECTION(op);
412414
if (!PyFunction_Check(op)) {
413415
PyErr_BadInternalCall();
414416
return NULL;
415417
}
416-
return ((PyFunctionObject *) op) -> func_code;
418+
code = ((PyFunctionObject *) op) ->func_code;
419+
Py_END_CRITICAL_SECTION();
420+
return code;
417421
}
418422

419423
PyObject *
420424
PyFunction_GetGlobals(PyObject *op)
421425
{
426+
PyObject *globals = NULL;
427+
Py_BEGIN_CRITICAL_SECTION(op);
422428
if (!PyFunction_Check(op)) {
423429
PyErr_BadInternalCall();
424430
return NULL;
425431
}
426-
return ((PyFunctionObject *) op) -> func_globals;
432+
globals = ((PyFunctionObject *) op) ->func_globals;
433+
Py_END_CRITICAL_SECTION();
434+
return globals;
427435
}
428436

429437
PyObject *
430438
PyFunction_GetModule(PyObject *op)
431439
{
440+
PyObject *module = NULL;
441+
Py_BEGIN_CRITICAL_SECTION(op);
432442
if (!PyFunction_Check(op)) {
433443
PyErr_BadInternalCall();
434444
return NULL;
435445
}
436-
return ((PyFunctionObject *) op) -> func_module;
446+
module = ((PyFunctionObject *) op) ->func_module;
447+
Py_END_CRITICAL_SECTION();
448+
return module;
437449
}
438450

439451
PyObject *
440452
PyFunction_GetDefaults(PyObject *op)
441453
{
454+
PyObject *defaults = NULL;
455+
Py_BEGIN_CRITICAL_SECTION(op);
442456
if (!PyFunction_Check(op)) {
443457
PyErr_BadInternalCall();
444458
return NULL;
445459
}
446-
return ((PyFunctionObject *) op) -> func_defaults;
460+
defaults = ((PyFunctionObject *) op) ->func_defaults;
461+
Py_END_CRITICAL_SECTION();
462+
return defaults;
447463
}
448464

449465
int
450466
PyFunction_SetDefaults(PyObject *op, PyObject *defaults)
451467
{
468+
Py_BEGIN_CRITICAL_SECTION(op);
452469
if (!PyFunction_Check(op)) {
453470
PyErr_BadInternalCall();
454471
return -1;
@@ -462,7 +479,6 @@ PyFunction_SetDefaults(PyObject *op, PyObject *defaults)
462479
PyErr_SetString(PyExc_SystemError, "non-tuple default args");
463480
return -1;
464481
}
465-
Py_BEGIN_CRITICAL_SECTION(op);
466482
handle_func_event(PyFunction_EVENT_MODIFY_DEFAULTS,
467483
(PyFunctionObject *) op, defaults);
468484
_PyFunction_ClearVersion((PyFunctionObject *)op);
@@ -976,14 +992,13 @@ static PyObject *
976992
function___annotations___get_impl(PyFunctionObject *self)
977993
/*[clinic end generated code: output=a4cf4c884c934cbb input=92643d7186c1ad0c]*/
978994
{
979-
PyObject *d = NULL;
980995
if (self->func_annotations == NULL &&
981996
(self->func_annotate == NULL || !PyCallable_Check(self->func_annotate))) {
982997
self->func_annotations = PyDict_New();
983998
if (self->func_annotations == NULL)
984999
return NULL;
9851000
}
986-
d = func_get_annotation_dict(self);
1001+
PyObject *d = func_get_annotation_dict(self);
9871002
return Py_XNewRef(d);
9881003
}
9891004

@@ -1244,9 +1259,8 @@ static PyObject*
12441259
func_repr(PyObject *self)
12451260
{
12461261
PyFunctionObject *op = _PyFunction_CAST(self);
1247-
PyObject *func_name = FT_ATOMIC_LOAD_PTR(op->func_qualname);
12481262
return PyUnicode_FromFormat("<function %U at %p>",
1249-
func_name, op);
1263+
op->func_qualname, op);
12501264
}
12511265

12521266
static int

0 commit comments

Comments
 (0)