There was an error while loading. Please reload this page.
1 parent 50aff5f commit c575172Copy full SHA for c575172
1 file changed
Python/initconfig.c
@@ -3688,6 +3688,44 @@ PyConfig_SetWideStringList(PyConfig *config, PyWideStringList *list,
3688
}
3689
3690
3691
+#ifdef __CYGWIN__
3692
+// Cygwin strips ".exe" suffix from argv[0].
3693
+// Add again the ".exe" suffix.
3694
+static PyStatus
3695
+config_argv0_add_exe(PyConfig *config)
3696
+{
3697
+ if (config->argv.length < 1) {
3698
+ return _PyStatus_OK();
3699
+ }
3700
+ const wchar_t *argv0 = config->argv.items[0];
3701
+ size_t len = wcslen(argv0);
3702
+ if (len >= 5 && wcscmp(argv0 + len - 4, L".exe") == 0) {
3703
3704
3705
+
3706
+ wchar_t *exe = PyMem_RawMalloc((len + 4 + 1) * sizeof(wchar_t));
3707
+ if (exe == NULL) {
3708
+ return _PyStatus_NO_MEMORY();
3709
3710
+ wcscpy(exe, argv0);
3711
+ wcscat(exe, L".exe");
3712
3713
+ FILE *fp = _Py_wfopen(exe, L"rb");
3714
+ if (fp != NULL) {
3715
+ fclose(fp);
3716
3717
+ PyMem_RawFree(config->argv.items[0]);
3718
+ config->argv.items[0] = exe;
3719
3720
+ else {
3721
+ PyMem_RawFree(exe);
3722
3723
3724
3725
+}
3726
+#endif
3727
3728
3729
/* Read the configuration into PyConfig from:
3730
3731
* Command line arguments
@@ -3707,6 +3745,13 @@ _PyConfig_Read(PyConfig *config, int compute_path_config)
3745
3746
config_get_global_vars(config);
3747
3748
3749
+ status = config_argv0_add_exe(config);
3750
+ if (_PyStatus_EXCEPTION(status)) {
3751
+ return status;
3752
3753
3754
3755
if (config->orig_argv.length == 0
3756
&& !(config->argv.length == 1
3757
&& wcscmp(config->argv.items[0], L"") == 0))
0 commit comments