@@ -2609,18 +2609,15 @@ create_managed_weakref_nogc_type(PyObject *self, PyObject *Py_UNUSED(args))
26092609static void
26102610test_interp_guards_common (void )
26112611{
2612- PyInterpreterState * interp = PyInterpreterState_Get ();
2613- PyInterpreterGuard guard = PyInterpreterGuard_FromCurrent ();
2614- assert (guard != 0 );
2615- assert (PyInterpreterGuard_GetInterpreter (guard ) == interp );
2612+ PyInterpreterGuard * guard = PyInterpreterGuard_FromCurrent ();
2613+ assert (guard != NULL );
26162614
2617- PyInterpreterGuard guard_2 = PyInterpreterGuard_Copy (guard );
2618- assert (guard_2 != 0 );
2619- assert (PyInterpreterGuard_GetInterpreter (guard_2 ) == interp );
2615+ PyInterpreterGuard * guard_2 = PyInterpreterGuard_FromCurrent ();
2616+ assert (guard_2 != NULL );
26202617
2621- // We can close the references in any order
2622- PyInterpreterGuard_Release (guard_2 );
2623- PyInterpreterGuard_Release (guard );
2618+ // We can close the guards in any order
2619+ PyInterpreterGuard_Close (guard_2 );
2620+ PyInterpreterGuard_Close (guard );
26242621}
26252622
26262623static PyObject *
@@ -2657,25 +2654,25 @@ test_interpreter_guards(PyObject *self, PyObject *unused)
26572654static PyObject *
26582655test_thread_state_ensure_nested (PyObject * self , PyObject * unused )
26592656{
2660- PyInterpreterGuard guard = PyInterpreterGuard_FromCurrent ();
2661- if (guard == 0 ) {
2657+ PyInterpreterGuard * guard = PyInterpreterGuard_FromCurrent ();
2658+ if (guard == NULL ) {
26622659 return NULL ;
26632660 }
26642661 PyThreadState * save_tstate = PyThreadState_Swap (NULL );
26652662 assert (PyGILState_GetThisThreadState () == save_tstate );
2666- PyThreadState * thread_views [10 ];
2663+ PyThreadState * thread_states [10 ];
26672664
26682665 for (int i = 0 ; i < 10 ; ++ i ) {
26692666 // Test reactivation of the detached tstate.
2670- thread_views [i ] = PyThreadState_Ensure (guard );
2671- if (thread_views [i ] == 0 ) {
2672- PyInterpreterGuard_Release (guard );
2667+ thread_states [i ] = PyThreadState_Ensure (guard );
2668+ if (thread_states [i ] == 0 ) {
2669+ PyInterpreterGuard_Close (guard );
26732670 return PyErr_NoMemory ();
26742671 }
26752672
26762673 // No new thread state should've been created.
26772674 assert (PyThreadState_Get () == save_tstate );
2678- PyThreadState_Release (thread_views [i ]);
2675+ PyThreadState_Release (thread_states [i ]);
26792676 }
26802677
26812678 assert (PyThreadState_GetUnchecked () == NULL );
@@ -2684,11 +2681,11 @@ test_thread_state_ensure_nested(PyObject *self, PyObject *unused)
26842681 // If the (detached) gilstate matches the interpreter, then it shouldn't
26852682 // create a new thread state.
26862683 for (int i = 0 ; i < 10 ; ++ i ) {
2687- thread_views [i ] = PyThreadState_Ensure (guard );
2688- if (thread_views [i ] == 0 ) {
2684+ thread_states [i ] = PyThreadState_Ensure (guard );
2685+ if (thread_states [i ] == 0 ) {
26892686 // This will technically leak other thread states, but it doesn't
26902687 // matter because this is a test.
2691- PyInterpreterGuard_Release (guard );
2688+ PyInterpreterGuard_Close (guard );
26922689 return PyErr_NoMemory ();
26932690 }
26942691
@@ -2697,23 +2694,23 @@ test_thread_state_ensure_nested(PyObject *self, PyObject *unused)
26972694
26982695 for (int i = 0 ; i < 10 ; ++ i ) {
26992696 assert (PyThreadState_Get () == save_tstate );
2700- PyThreadState_Release (thread_views [i ]);
2697+ PyThreadState_Release (thread_states [i ]);
27012698 }
27022699
27032700 assert (PyThreadState_GetUnchecked () == NULL );
2704- PyInterpreterGuard_Release (guard );
2701+ PyInterpreterGuard_Close (guard );
27052702 PyThreadState_Swap (save_tstate );
27062703 Py_RETURN_NONE ;
27072704}
27082705
27092706static PyObject *
27102707test_thread_state_ensure_crossinterp (PyObject * self , PyObject * unused )
27112708{
2712- PyInterpreterGuard guard = PyInterpreterGuard_FromCurrent ();
2709+ PyInterpreterGuard * guard = PyInterpreterGuard_FromCurrent ();
27132710 PyThreadState * save_tstate = PyThreadState_Swap (NULL );
27142711 PyThreadState * interp_tstate = Py_NewInterpreter ();
27152712 if (interp_tstate == NULL ) {
2716- PyInterpreterGuard_Release (guard );
2713+ PyInterpreterGuard_Close (guard );
27172714 return PyErr_NoMemory ();
27182715 }
27192716
@@ -2730,37 +2727,36 @@ test_thread_state_ensure_crossinterp(PyObject *self, PyObject *unused)
27302727 interp = interpreters.create()
27312728 interp.exec(some_func)
27322729 */
2733- PyThreadState * thread_view = PyThreadState_Ensure (guard );
2734- if (thread_view == 0 ) {
2735- PyInterpreterGuard_Release (guard );
2730+ PyThreadState * thread_state = PyThreadState_Ensure (guard );
2731+ if (thread_state == NULL ) {
2732+ PyInterpreterGuard_Close (guard );
27362733 return PyErr_NoMemory ();
27372734 }
27382735
27392736 PyThreadState * ensured_tstate = PyThreadState_Get ();
27402737 assert (ensured_tstate != save_tstate );
2741- assert (PyInterpreterState_Get () == PyInterpreterGuard_GetInterpreter (guard ));
27422738 assert (PyGILState_GetThisThreadState () == ensured_tstate );
27432739
27442740 // Now though, we should reactivate the thread state
2745- PyThreadState * other_thread_view = PyThreadState_Ensure (guard );
2746- if (other_thread_view == 0 ) {
2747- PyThreadState_Release (thread_view );
2748- PyInterpreterGuard_Release (guard );
2741+ PyThreadState * other_thread_state = PyThreadState_Ensure (guard );
2742+ if (other_thread_state == NULL ) {
2743+ PyThreadState_Release (thread_state );
2744+ PyInterpreterGuard_Close (guard );
27492745 return PyErr_NoMemory ();
27502746 }
27512747
27522748 assert (PyThreadState_Get () == ensured_tstate );
2753- PyThreadState_Release (other_thread_view );
2749+ PyThreadState_Release (other_thread_state );
27542750
27552751 // Ensure that we're restoring the prior thread state
2756- PyThreadState_Release (thread_view );
2752+ PyThreadState_Release (thread_state );
27572753 assert (PyThreadState_Get () == interp_tstate );
27582754 assert (PyGILState_GetThisThreadState () == interp_tstate );
27592755
27602756 PyThreadState_Swap (interp_tstate );
27612757 Py_EndInterpreter (interp_tstate );
27622758
2763- PyInterpreterGuard_Release (guard );
2759+ PyInterpreterGuard_Close (guard );
27642760 PyThreadState_Swap (save_tstate );
27652761 Py_RETURN_NONE ;
27662762}
@@ -2774,20 +2770,20 @@ test_interp_view_after_shutdown(PyObject *self, PyObject *unused)
27742770 return PyErr_NoMemory ();
27752771 }
27762772
2777- PyInterpreterView view = PyInterpreterView_FromCurrent ();
2778- if (view == 0 ) {
2773+ PyInterpreterView * view = PyInterpreterView_FromCurrent ();
2774+ if (view == NULL ) {
27792775 return PyErr_NoMemory ();
27802776 }
27812777
27822778 // As a sanity check, ensure that the view actually works
2783- PyInterpreterGuard guard = PyInterpreterGuard_FromView (view );
2784- PyInterpreterGuard_Release (guard );
2779+ PyInterpreterGuard * guard = PyInterpreterGuard_FromView (view );
2780+ PyInterpreterGuard_Close (guard );
27852781
27862782 // Now, destroy the interpreter and try to acquire a lock from a view.
27872783 // It should fail.
27882784 Py_EndInterpreter (interp_tstate );
27892785 guard = PyInterpreterGuard_FromView (view );
2790- assert (guard == 0 );
2786+ assert (guard == NULL );
27912787
27922788 PyThreadState_Swap (save_tstate );
27932789 Py_RETURN_NONE ;
0 commit comments