Skip to content

Commit c8a1818

Browse files
authored
gh-125517: Fix unreachable code warnings in _testembed.c (#125518)
1 parent cc5a225 commit c8a1818

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

Doc/c-api/init_config.rst

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1825,14 +1825,18 @@ return ``-1`` on error:
18251825
PyInitConfig_Free(config);
18261826
return 0;
18271827
1828-
// Display the error message
1829-
const char *err_msg;
18301828
error:
1831-
(void)PyInitConfig_GetError(config, &err_msg);
1832-
printf("PYTHON INIT ERROR: %s\n", err_msg);
1833-
PyInitConfig_Free(config);
1829+
{
1830+
// Display the error message
1831+
// This uncommon braces style is used, because you cannot make
1832+
// goto targets point to variable declarations.
1833+
const char *err_msg;
1834+
(void)PyInitConfig_GetError(config, &err_msg);
1835+
printf("PYTHON INIT ERROR: %s\n", err_msg);
1836+
PyInitConfig_Free(config);
18341837
1835-
return -1;
1838+
return -1;
1839+
}
18361840
}
18371841
18381842

Programs/_testembed.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1902,11 +1902,13 @@ static int test_initconfig_api(void)
19021902
Py_Finalize();
19031903
return 0;
19041904

1905-
const char *err_msg;
19061905
error:
1907-
(void)PyInitConfig_GetError(config, &err_msg);
1908-
printf("Python init failed: %s\n", err_msg);
1909-
exit(1);
1906+
{
1907+
const char *err_msg;
1908+
(void)PyInitConfig_GetError(config, &err_msg);
1909+
printf("Python init failed: %s\n", err_msg);
1910+
exit(1);
1911+
}
19101912
}
19111913

19121914

@@ -2050,11 +2052,13 @@ static int test_initconfig_module(void)
20502052
Py_Finalize();
20512053
return 0;
20522054

2053-
const char *err_msg;
20542055
error:
2055-
(void)PyInitConfig_GetError(config, &err_msg);
2056-
printf("Python init failed: %s\n", err_msg);
2057-
exit(1);
2056+
{
2057+
const char *err_msg;
2058+
(void)PyInitConfig_GetError(config, &err_msg);
2059+
printf("Python init failed: %s\n", err_msg);
2060+
exit(1);
2061+
}
20582062
}
20592063

20602064

0 commit comments

Comments
 (0)