From 6dde573ed9cf74556d6fce68652a745b1acdde1f Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 10 Jan 2018 08:31:22 +0530 Subject: [PATCH] Fix __name__ != __main__ when using runpy in the osx-bundle --- linux-launcher.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/linux-launcher.c b/linux-launcher.c index c5c9acdc9..4f7ca6f94 100644 --- a/linux-launcher.c +++ b/linux-launcher.c @@ -47,15 +47,17 @@ static int run_embedded(const char* exe_dir_, int argc, wchar_t **argv) { if (num < 0 || num >= PATH_MAX) { fprintf(stderr, "Failed to create path to kitty lib\n"); return 1; } Py_Initialize(); PySys_SetArgvEx(argc - 1, argv + 1, 0); - PySys_SetObject("frozen", Py_True); // dont care if this fails + PySys_SetObject("frozen", Py_True); // dont care if this fails if (ed) { PySys_SetObject("bundle_exe_dir", ed); Py_CLEAR(ed); } PyObject *kitty = PyUnicode_FromWideChar(stdlib, -1); 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); - if (res == NULL) PyErr_Print(); + 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: if (Py_FinalizeEx() < 0) ret = 120;