Skip to content

Commit 6a05c90

Browse files
committed
Fix some test things.
1 parent e042656 commit 6a05c90

1 file changed

Lines changed: 6 additions & 19 deletions

File tree

Modules/_testcapimodule.c

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2640,10 +2640,7 @@ test_interpreter_guards(PyObject *self, PyObject *unused)
26402640

26412641
PyThreadState *isolated_interp_tstate;
26422642
PyStatus status = Py_NewInterpreterFromConfig(&isolated_interp_tstate, &config);
2643-
if (PyStatus_Exception(status)) {
2644-
PyErr_SetString(PyExc_RuntimeError, "interpreter creation failed");
2645-
return NULL;
2646-
}
2643+
assert(!PyStatus_Exception(status));
26472644

26482645
test_interp_guards_common();
26492646
Py_EndInterpreter(isolated_interp_tstate);
@@ -2655,20 +2652,16 @@ static PyObject *
26552652
test_thread_state_ensure_nested(PyObject *self, PyObject *unused)
26562653
{
26572654
PyInterpreterGuard *guard = PyInterpreterGuard_FromCurrent();
2658-
if (guard == NULL) {
2659-
return NULL;
2660-
}
2655+
assert(guard != NULL);
2656+
26612657
PyThreadState *save_tstate = PyThreadState_Swap(NULL);
26622658
assert(PyGILState_GetThisThreadState() == save_tstate);
26632659
PyThreadState *thread_states[10];
26642660

26652661
for (int i = 0; i < 10; ++i) {
26662662
// Test reactivation of the detached tstate.
26672663
thread_states[i] = PyThreadState_Ensure(guard);
2668-
if (thread_states[i] == 0) {
2669-
PyInterpreterGuard_Close(guard);
2670-
return PyErr_NoMemory();
2671-
}
2664+
assert(thread_states[i] != NULL);
26722665

26732666
// No new thread state should've been created.
26742667
assert(PyThreadState_Get() == save_tstate);
@@ -2682,17 +2675,11 @@ test_thread_state_ensure_nested(PyObject *self, PyObject *unused)
26822675
// create a new thread state.
26832676
for (int i = 0; i < 10; ++i) {
26842677
thread_states[i] = PyThreadState_Ensure(guard);
2685-
if (thread_states[i] == 0) {
2686-
// This will technically leak other thread states, but it doesn't
2687-
// matter because this is a test.
2688-
PyInterpreterGuard_Close(guard);
2689-
return PyErr_NoMemory();
2690-
}
2691-
2678+
assert(thread_states[i] != NULL);
26922679
assert(PyThreadState_Get() == save_tstate);
26932680
}
26942681

2695-
for (int i = 0; i < 10; ++i) {
2682+
for (int i = 9; i >= 0; --i) {
26962683
assert(PyThreadState_Get() == save_tstate);
26972684
PyThreadState_Release(thread_states[i]);
26982685
}

0 commit comments

Comments
 (0)