Skip to content

Commit 44e5b89

Browse files
committed
fix critical section positions
1 parent ba595d6 commit 44e5b89

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

Objects/funcobject.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -410,11 +410,11 @@ PyObject *
410410
PyFunction_GetCode(PyObject *op)
411411
{
412412
PyObject *code = NULL;
413-
Py_BEGIN_CRITICAL_SECTION(op);
414413
if (!PyFunction_Check(op)) {
415414
PyErr_BadInternalCall();
416415
return NULL;
417416
}
417+
Py_BEGIN_CRITICAL_SECTION(op);
418418
code = ((PyFunctionObject *) op) ->func_code;
419419
Py_END_CRITICAL_SECTION();
420420
return code;
@@ -465,7 +465,6 @@ PyFunction_GetDefaults(PyObject *op)
465465
int
466466
PyFunction_SetDefaults(PyObject *op, PyObject *defaults)
467467
{
468-
Py_BEGIN_CRITICAL_SECTION(op);
469468
if (!PyFunction_Check(op)) {
470469
PyErr_BadInternalCall();
471470
return -1;
@@ -479,6 +478,7 @@ PyFunction_SetDefaults(PyObject *op, PyObject *defaults)
479478
PyErr_SetString(PyExc_SystemError, "non-tuple default args");
480479
return -1;
481480
}
481+
Py_BEGIN_CRITICAL_SECTION(op);
482482
handle_func_event(PyFunction_EVENT_MODIFY_DEFAULTS,
483483
(PyFunctionObject *) op, defaults);
484484
_PyFunction_ClearVersion((PyFunctionObject *)op);
@@ -504,7 +504,11 @@ PyFunction_GetKwDefaults(PyObject *op)
504504
PyErr_BadInternalCall();
505505
return NULL;
506506
}
507-
return FT_ATOMIC_LOAD_PTR(((PyFunctionObject *) op) -> func_kwdefaults);
507+
PyObject *kwdefaults = NULL;
508+
Py_BEGIN_CRITICAL_SECTION(op);
509+
kwdefaults = ((PyFunctionObject *) op) -> func_kwdefaults;
510+
Py_END_CRITICAL_SECTION();
511+
return kwdefaults;
508512
}
509513

510514
int
@@ -540,7 +544,11 @@ PyFunction_GetClosure(PyObject *op)
540544
PyErr_BadInternalCall();
541545
return NULL;
542546
}
543-
return FT_ATOMIC_LOAD_PTR(((PyFunctionObject *) op) -> func_closure);
547+
PyObject *closure = NULL;
548+
Py_BEGIN_CRITICAL_SECTION(op);
549+
closure = ((PyFunctionObject *) op) -> func_closure;
550+
Py_END_CRITICAL_SECTION();
551+
return closure;
544552
}
545553

546554
int

0 commit comments

Comments
 (0)