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)

130130

if (sysdict != NULL) {

131131

sys_path = _PyDict_GetItemIdWithError(sysdict, &PyId_path);

132132

if (sys_path == NULL && PyErr_Occurred()) {

133-

goto error;

133+

return -1;

134134

}

135135

}

136136

else {

137137

sys_path = NULL;

138138

}

139139

if (sys_path == NULL) {

140140

PyErr_SetString(PyExc_RuntimeError, "unable to get sys.path");

141-

goto error;

141+

return -1;

142142

}

143143144144

if (PyList_Insert(sys_path, 0, path0)) {

145-

goto error;

145+

return -1;

146146

}

147147

return 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

447443

pymain_run_python(int *exitcode)

448444

{

449-

_PyInitError err;

450-451445

PyInterpreterState *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)

464458465459

if (main_importer_path != NULL) {

466460

if (pymain_sys_path_add_path0(interp, main_importer_path) < 0) {

467-

err = _Py_INIT_EXIT(1);

468-

goto done;

461+

goto error;

469462

}

470463

}

471464

else if (!config->isolated) {

472465

PyObject *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) {

479472

if (pymain_sys_path_add_path0(interp, path0) < 0) {

480473

Py_DECREF(path0);

481-

err = _Py_INIT_EXIT(1);

482-

goto done;

474+

goto error;

483475

}

484476

Py_DECREF(path0);

485477

}

@@ -508,11 +500,14 @@ pymain_run_python(int *exitcode)

508500

}

509501510502

pymain_repl(config, &cf, exitcode);

511-

err = _Py_INIT_OK();

503+

goto done;

504+505+

error:

506+

PyErr_Print();

507+

*exitcode = 1;

512508513509

done:

514510

Py_XDECREF(main_importer_path);

515-

return err;

516511

}

517512518513

@@ -578,17 +573,14 @@ _Py_RunMain(void)

578573

{

579574

int 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);

586577

if (Py_FinalizeEx() < 0) {

587578

/* Value unlikely to be confused with a non-error exit status or

588579

other special meaning */

589580

exitcode = 120;

590581

}

591582583+

done:

592584

pymain_free();

593585594586

if (_Py_UnhandledKeyboardInterrupt) {

@@ -603,6 +595,10 @@ static int

603595

pymain_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+

}

606602

if (_Py_INIT_FAILED(err)) {

607603

pymain_exit_error(err);

608604

}