bpo-36763: _PyInitError always use int for exitcode (GH-13360) · python/cpython@dbacfc2
@@ -130,25 +130,21 @@ pymain_sys_path_add_path0(PyInterpreterState *interp, PyObject *path0)
130130if (sysdict != NULL) {
131131sys_path = _PyDict_GetItemIdWithError(sysdict, &PyId_path);
132132if (sys_path == NULL && PyErr_Occurred()) {
133-goto error;
133+return -1;
134134 }
135135 }
136136else {
137137sys_path = NULL;
138138 }
139139if (sys_path == NULL) {
140140PyErr_SetString(PyExc_RuntimeError, "unable to get sys.path");
141-goto error;
141+return -1;
142142 }
143143144144if (PyList_Insert(sys_path, 0, path0)) {
145-goto error;
145+return -1;
146146 }
147147return 0;
148-149-error:
150-PyErr_Print();
151-return -1;
152148}
153149154150@@ -443,11 +439,9 @@ pymain_repl(_PyCoreConfig *config, PyCompilerFlags *cf, int *exitcode)
443439}
444440445441446-static _PyInitError
442+static void
447443pymain_run_python(int *exitcode)
448444{
449-_PyInitError err;
450-451445PyInterpreterState *interp = _PyInterpreterState_GET_UNSAFE();
452446/* pymain_run_stdin() modify the config */
453447_PyCoreConfig *config = &interp->core_config;
@@ -464,22 +458,20 @@ pymain_run_python(int *exitcode)
464458465459if (main_importer_path != NULL) {
466460if (pymain_sys_path_add_path0(interp, main_importer_path) < 0) {
467-err = _Py_INIT_EXIT(1);
468- goto done;
461+ goto error;
469462 }
470463 }
471464else if (!config->isolated) {
472465PyObject *path0 = NULL;
473-if (_PyPathConfig_ComputeSysPath0(&config->argv, &path0)) {
474-if (path0 == NULL) {
475-err = _Py_INIT_NO_MEMORY();
476- goto done;
477- }
466+int res = _PyPathConfig_ComputeSysPath0(&config->argv, &path0);
467+if (res < 0) {
468+ goto error;
469+ }
478470471+if (res > 0) {
479472if (pymain_sys_path_add_path0(interp, path0) < 0) {
480473Py_DECREF(path0);
481-err = _Py_INIT_EXIT(1);
482- goto done;
474+ goto error;
483475 }
484476Py_DECREF(path0);
485477 }
@@ -508,11 +500,14 @@ pymain_run_python(int *exitcode)
508500 }
509501510502pymain_repl(config, &cf, exitcode);
511-err = _Py_INIT_OK();
503+ goto done;
504+505+error:
506+PyErr_Print();
507+*exitcode = 1;
512508513509done:
514510Py_XDECREF(main_importer_path);
515-return err;
516511}
517512518513@@ -578,17 +573,14 @@ _Py_RunMain(void)
578573{
579574int exitcode = 0;
580575581-_PyInitError err = pymain_run_python(&exitcode);
582-if (_Py_INIT_FAILED(err)) {
583-pymain_exit_error(err);
584- }
585-576+pymain_run_python(&exitcode);
586577if (Py_FinalizeEx() < 0) {
587578/* Value unlikely to be confused with a non-error exit status or
588579 other special meaning */
589580exitcode = 120;
590581 }
591582583+done:
592584pymain_free();
593585594586if (_Py_UnhandledKeyboardInterrupt) {
@@ -603,6 +595,10 @@ static int
603595pymain_main(_PyArgv *args)
604596{
605597_PyInitError err = pymain_init(args);
598+if (_Py_INIT_IS_EXIT(err)) {
599+pymain_free();
600+return err.exitcode;
601+ }
606602if (_Py_INIT_FAILED(err)) {
607603pymain_exit_error(err);
608604 }