Skip to content

Commit 8262c96

Browse files
bpo-46008: Return void from _PyEval_InitState(). (gh-29970)
This falls into the category of keep-allocation-and-initialization separate. It also allows us to use _PyEval_InitState() safely in functions that return void. https://bugs.python.org/issue46008
1 parent 91b59a3 commit 8262c96

File tree

3 files changed

+7
-10
lines changed

3 files changed

+7
-10
lines changed

Include/internal/pycore_ceval.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ struct _ceval_runtime_state;
1717

1818
extern void _Py_FinishPendingCalls(PyThreadState *tstate);
1919
extern void _PyEval_InitRuntimeState(struct _ceval_runtime_state *);
20-
extern int _PyEval_InitState(struct _ceval_state *ceval);
20+
extern void _PyEval_InitState(struct _ceval_state *, PyThread_type_lock);
2121
extern void _PyEval_FiniState(struct _ceval_state *ceval);
2222
PyAPI_FUNC(void) _PyEval_SignalReceived(PyInterpreterState *interp);
2323
PyAPI_FUNC(int) _PyEval_AddPendingCall(

Python/ceval.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -747,24 +747,19 @@ _PyEval_InitRuntimeState(struct _ceval_runtime_state *ceval)
747747
#endif
748748
}
749749

750-
int
751-
_PyEval_InitState(struct _ceval_state *ceval)
750+
void
751+
_PyEval_InitState(struct _ceval_state *ceval, PyThread_type_lock pending_lock)
752752
{
753753
ceval->recursion_limit = Py_DEFAULT_RECURSION_LIMIT;
754754

755755
struct _pending_calls *pending = &ceval->pending;
756756
assert(pending->lock == NULL);
757757

758-
pending->lock = PyThread_allocate_lock();
759-
if (pending->lock == NULL) {
760-
return -1;
761-
}
758+
pending->lock = pending_lock;
762759

763760
#ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
764761
_gil_initialize(&ceval->gil);
765762
#endif
766-
767-
return 0;
768763
}
769764

770765
void

Python/pystate.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,12 @@ PyInterpreterState_New(void)
225225
_PyRuntimeState *runtime = &_PyRuntime;
226226
interp->runtime = runtime;
227227

228-
if (_PyEval_InitState(&interp->ceval) < 0) {
228+
PyThread_type_lock pending_lock = PyThread_allocate_lock();
229+
if (pending_lock == NULL) {
229230
goto out_of_memory;
230231
}
231232

233+
_PyEval_InitState(&interp->ceval, pending_lock);
232234
_PyGC_InitState(&interp->gc);
233235
PyConfig_InitPythonConfig(&interp->config);
234236
_PyType_InitCache(interp);

0 commit comments

Comments
 (0)