gh-98608: Fix Failure-handling in new_interpreter() (gh-102658)

The error-handling code in new_interpreter() has been broken for a while.  We hadn't noticed because those code mostly doesn't fail.  (I noticed while working on gh-101660.)  The problem is that we try to clear/delete the newly-created thread/interpreter using itself, which just failed.  The solution is to switch back to the calling thread state first.

(cherry picked from commit d1b883b52a)

Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
https: //github.com/python/cpython/issues/98608
This commit is contained in:
Miss Islington (bot) 2023-03-21 12:10:36 -07:00 committed by GitHub
parent e732a85934
commit d5fdc3f07e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1962,10 +1962,10 @@ error:
/* Oops, it didn't work. Undo it all. */
PyErr_PrintEx(0);
PyThreadState_Swap(save_tstate);
PyThreadState_Clear(tstate);
PyThreadState_Delete(tstate);
PyInterpreterState_Delete(interp);
PyThreadState_Swap(save_tstate);
return status;
}