]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Simplify interp_look_up_id() (#134257)
authorVictor Stinner <vstinner@python.org>
Mon, 19 May 2025 18:09:10 +0000 (14:09 -0400)
committerGitHub <noreply@github.com>
Mon, 19 May 2025 18:09:10 +0000 (18:09 +0000)
Don't use PyInterpreterState_GetID() but get directly the interpreter
'id' member which cannot fail.

Python/pystate.c

index 14ae2748b0bc99296a905bf93ddfbdb1f77894f4..4757a8c3d1476c95f030237e80c9ab829d76675d 100644 (file)
@@ -1393,10 +1393,8 @@ interp_look_up_id(_PyRuntimeState *runtime, int64_t requested_id)
 {
     PyInterpreterState *interp = runtime->interpreters.head;
     while (interp != NULL) {
-        int64_t id = PyInterpreterState_GetID(interp);
-        if (id < 0) {
-            return NULL;
-        }
+        int64_t id = interp->id;
+        assert(id >= 0);
         if (requested_id == id) {
             return interp;
         }