]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-125517: Fix unreachable code warnings in `_testembed.c` (#125518)
authorsobolevn <mail@sobolevn.me>
Tue, 15 Oct 2024 13:12:32 +0000 (16:12 +0300)
committerGitHub <noreply@github.com>
Tue, 15 Oct 2024 13:12:32 +0000 (13:12 +0000)
Doc/c-api/init_config.rst
Programs/_testembed.c

index 66e845df2e6aa5545f35ac60f356175052e2f097..6194d7446c73e45a1b800a43e55c1c64a897f997 100644 (file)
@@ -1825,14 +1825,18 @@ return ``-1`` on error:
         PyInitConfig_Free(config);
         return 0;
 
-        // Display the error message
-        const char *err_msg;
     error:
-        (void)PyInitConfig_GetError(config, &err_msg);
-        printf("PYTHON INIT ERROR: %s\n", err_msg);
-        PyInitConfig_Free(config);
+        {
+            // Display the error message
+            // This uncommon braces style is used, because you cannot make
+            // goto targets point to variable declarations.
+            const char *err_msg;
+            (void)PyInitConfig_GetError(config, &err_msg);
+            printf("PYTHON INIT ERROR: %s\n", err_msg);
+            PyInitConfig_Free(config);
 
-        return -1;
+            return -1;
+        }
     }
 
 
index 0fb45b2265e3c695aff6cb35b99b310065ab7325..d15dd519dbf6aff3e8f13e01561427b40afbd47a 100644 (file)
@@ -1902,11 +1902,13 @@ static int test_initconfig_api(void)
     Py_Finalize();
     return 0;
 
-    const char *err_msg;
 error:
-    (void)PyInitConfig_GetError(config, &err_msg);
-    printf("Python init failed: %s\n", err_msg);
-    exit(1);
+    {
+        const char *err_msg;
+        (void)PyInitConfig_GetError(config, &err_msg);
+        printf("Python init failed: %s\n", err_msg);
+        exit(1);
+    }
 }
 
 
@@ -2050,11 +2052,13 @@ static int test_initconfig_module(void)
     Py_Finalize();
     return 0;
 
-    const char *err_msg;
 error:
-    (void)PyInitConfig_GetError(config, &err_msg);
-    printf("Python init failed: %s\n", err_msg);
-    exit(1);
+    {
+        const char *err_msg;
+        (void)PyInitConfig_GetError(config, &err_msg);
+        printf("Python init failed: %s\n", err_msg);
+        exit(1);
+    }
 }