Skip to content

Commit 4c99feb

Browse files
committed
change to single line fix adding main_module decref
1 parent cdf1ef3 commit 4c99feb

1 file changed

Lines changed: 10 additions & 16 deletions

File tree

Python/pythonrun.c

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -554,39 +554,33 @@ PyRun_SimpleFileExFlags(FILE *fp, const char *filename, int closeit,
554554

555555
int
556556
_PyRun_SimpleStringFlagsWithName(const char *command, const char* name, PyCompilerFlags *flags) {
557-
int ret = -1;
558-
559557
PyObject *main_module = PyImport_AddModuleRef("__main__");
560558
if (main_module == NULL) {
561-
return ret;
559+
return -1;
562560
}
563561
PyObject *dict = PyModule_GetDict(main_module); // borrowed ref
564562

565-
PyObject *the_name = NULL;
566563
PyObject *res = NULL;
567564
if (name == NULL) {
568565
res = PyRun_StringFlags(command, Py_file_input, dict, dict, flags);
569566
} else {
570-
the_name = PyUnicode_FromString(name);
571-
if (the_name == NULL) {
567+
PyObject* the_name = PyUnicode_FromString(name);
568+
if (!the_name) {
572569
PyErr_Print();
573-
goto done;
570+
Py_DECREF(main_module);
571+
return -1;
574572
}
575573
res = _PyRun_StringFlagsWithName(command, the_name, Py_file_input, dict, dict, flags, 0);
574+
Py_DECREF(the_name);
576575
}
576+
Py_DECREF(main_module);
577577
if (res == NULL) {
578578
PyErr_Print();
579-
goto done;
579+
return -1;
580580
}
581581

582-
ret = 0;
583-
584-
done:
585-
Py_DECREF(main_module);
586-
Py_XDECREF(the_name);
587-
Py_XDECREF(res);
588-
589-
return ret;
582+
Py_DECREF(res);
583+
return 0;
590584
}
591585

592586
int

0 commit comments

Comments
 (0)