Fix __name__ != __main__ when using runpy in the osx-bundle

This commit is contained in:
Kovid Goyal 2018-01-10 08:31:22 +05:30
parent 566e641be1
commit 6dde573ed9
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -53,8 +53,10 @@ static int run_embedded(const char* exe_dir_, int argc, wchar_t **argv) {
if (kitty == NULL) { fprintf(stderr, "Failed to allocate python kitty lib object\n"); goto end; }
PyObject *runpy = PyImport_ImportModule("runpy");
if (runpy == NULL) { PyErr_Print(); fprintf(stderr, "Unable to import runpy\n"); Py_CLEAR(kitty); goto end; }
PyObject *res = PyObject_CallMethod(runpy, "run_path", "O", kitty);
Py_CLEAR(runpy); Py_CLEAR(kitty);
PyObject *run_name = PyUnicode_FromString("__main__");
if (run_name == NULL) { fprintf(stderr, "Failed to allocate run_name\n"); goto end; }
PyObject *res = PyObject_CallMethod(runpy, "run_path", "OOO", kitty, Py_None, run_name);
Py_CLEAR(runpy); Py_CLEAR(kitty); Py_CLEAR(run_name);
if (res == NULL) PyErr_Print();
else { ret = 0; Py_CLEAR(res); }
end: