Issue #9425: Create run_file() subfunction
* Call Py_MakePendingCalls() before converting the filename from wchar_t* to char* * Use PyUnicode_AsUTF8String() instead of _PyUnicode_AsString()
This commit is contained in:
parent
af43e9a288
commit
0a3ddad666
|
@ -275,6 +275,40 @@ error:
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
run_file(FILE *fp, const wchar_t *filename, PyCompilerFlags *p_cf)
|
||||||
|
{
|
||||||
|
PyObject *unicode, *bytes = NULL;
|
||||||
|
char *filename_str;
|
||||||
|
int run;
|
||||||
|
|
||||||
|
/* call pending calls like signal handlers (SIGINT) */
|
||||||
|
if (Py_MakePendingCalls() == -1) {
|
||||||
|
PyErr_Print();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filename) {
|
||||||
|
unicode = PyUnicode_FromWideChar(filename, wcslen(filename));
|
||||||
|
if (unicode != NULL) {
|
||||||
|
bytes = PyUnicode_AsUTF8String(unicode);
|
||||||
|
Py_DECREF(unicode);
|
||||||
|
}
|
||||||
|
if (bytes != NULL)
|
||||||
|
filename_str = PyBytes_AsString(bytes);
|
||||||
|
else {
|
||||||
|
PyErr_Clear();
|
||||||
|
filename_str = "<decoding error>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
filename_str = "<stdin>";
|
||||||
|
|
||||||
|
run = PyRun_AnyFileExFlags(fp, filename_str, filename != NULL, p_cf);
|
||||||
|
Py_XDECREF(bytes);
|
||||||
|
return run != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Main program */
|
/* Main program */
|
||||||
|
|
||||||
|
@ -644,30 +678,8 @@ Py_Main(int argc, wchar_t **argv)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sts==-1) {
|
if (sts == -1)
|
||||||
PyObject *filenameObj = NULL;
|
sts = run_file(fp, filename, &cf);
|
||||||
char *p_cfilename = "<stdin>";
|
|
||||||
if (filename) {
|
|
||||||
filenameObj = PyUnicode_FromWideChar(
|
|
||||||
filename, wcslen(filename));
|
|
||||||
if (filenameObj != NULL)
|
|
||||||
p_cfilename = _PyUnicode_AsString(filenameObj);
|
|
||||||
else
|
|
||||||
p_cfilename = "<decoding error>";
|
|
||||||
}
|
|
||||||
/* call pending calls like signal handlers (SIGINT) */
|
|
||||||
if (Py_MakePendingCalls() == -1) {
|
|
||||||
PyErr_Print();
|
|
||||||
sts = 1;
|
|
||||||
} else {
|
|
||||||
sts = PyRun_AnyFileExFlags(
|
|
||||||
fp,
|
|
||||||
p_cfilename,
|
|
||||||
filename != NULL, &cf) != 0;
|
|
||||||
}
|
|
||||||
Py_XDECREF(filenameObj);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check this environment variable at the end, to give programs the
|
/* Check this environment variable at the end, to give programs the
|
||||||
|
|
Loading…
Reference in New Issue