Skip to content

Commit cca0721

Browse files
committed
fix critical section positions
1 parent 79f1043 commit cca0721

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

Objects/funcobject.c

Lines changed: 15 additions & 7 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;
@@ -424,11 +424,11 @@ PyObject *
424424
PyFunction_GetGlobals(PyObject *op)
425425
{
426426
PyObject *globals = NULL;
427-
Py_BEGIN_CRITICAL_SECTION(op);
428427
if (!PyFunction_Check(op)) {
429428
PyErr_BadInternalCall();
430429
return NULL;
431430
}
431+
Py_BEGIN_CRITICAL_SECTION(op);
432432
globals = ((PyFunctionObject *) op) ->func_globals;
433433
Py_END_CRITICAL_SECTION();
434434
return globals;
@@ -438,11 +438,11 @@ PyObject *
438438
PyFunction_GetModule(PyObject *op)
439439
{
440440
PyObject *module = NULL;
441-
Py_BEGIN_CRITICAL_SECTION(op);
442441
if (!PyFunction_Check(op)) {
443442
PyErr_BadInternalCall();
444443
return NULL;
445444
}
445+
Py_BEGIN_CRITICAL_SECTION(op);
446446
module = ((PyFunctionObject *) op) ->func_module;
447447
Py_END_CRITICAL_SECTION();
448448
return module;
@@ -452,11 +452,11 @@ PyObject *
452452
PyFunction_GetDefaults(PyObject *op)
453453
{
454454
PyObject *defaults = NULL;
455-
Py_BEGIN_CRITICAL_SECTION(op);
456455
if (!PyFunction_Check(op)) {
457456
PyErr_BadInternalCall();
458457
return NULL;
459458
}
459+
Py_BEGIN_CRITICAL_SECTION(op);
460460
defaults = ((PyFunctionObject *) op) ->func_defaults;
461461
Py_END_CRITICAL_SECTION();
462462
return defaults;
@@ -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);
@@ -500,11 +500,15 @@ PyFunction_SetVectorcall(PyFunctionObject *func, vectorcallfunc vectorcall)
500500
PyObject *
501501
PyFunction_GetKwDefaults(PyObject *op)
502502
{
503+
PyObject * kwdefaults = NULL;
503504
if (!PyFunction_Check(op)) {
504505
PyErr_BadInternalCall();
505506
return NULL;
506507
}
507-
return FT_ATOMIC_LOAD_PTR(((PyFunctionObject *) op) -> func_kwdefaults);
508+
Py_BEGIN_CRITICAL_SECTION(op);
509+
kwdefaults = ((PyFunctionObject *) op) -> func_kwdefaults;
510+
Py_END_CRITICAL_SECTION();
511+
return kwdefaults;
508512
}
509513

510514
int
@@ -536,11 +540,15 @@ PyFunction_SetKwDefaults(PyObject *op, PyObject *defaults)
536540
PyObject *
537541
PyFunction_GetClosure(PyObject *op)
538542
{
543+
PyObject* closure = NULL;
539544
if (!PyFunction_Check(op)) {
540545
PyErr_BadInternalCall();
541546
return NULL;
542547
}
543-
return FT_ATOMIC_LOAD_PTR(((PyFunctionObject *) op) -> func_closure);
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)