Kaydet (Commit) a62207c5 authored tarafından Victor Stinner's avatar Victor Stinner

Issue #9425: Create run_command() subfunction

Use PyUnicode_AsUTF8String() instead of _PyUnicode_AsString()
üst 6c6f851e
...@@ -253,6 +253,28 @@ static int RunMainFromImporter(wchar_t *filename) ...@@ -253,6 +253,28 @@ static int RunMainFromImporter(wchar_t *filename)
} }
} }
static int
run_command(wchar_t *command, PyCompilerFlags *cf)
{
PyObject *unicode, *bytes;
int ret;
unicode = PyUnicode_FromWideChar(command, -1);
if (unicode == NULL)
goto error;
bytes = PyUnicode_AsUTF8String(unicode);
Py_DECREF(unicode);
if (bytes == NULL)
goto error;
ret = PyRun_SimpleStringFlags(PyBytes_AsString(bytes), cf);
Py_DECREF(bytes);
return ret != 0;
error:
PyErr_Print();
return 1;
}
/* Main program */ /* Main program */
...@@ -564,22 +586,8 @@ Py_Main(int argc, wchar_t **argv) ...@@ -564,22 +586,8 @@ Py_Main(int argc, wchar_t **argv)
} }
if (command) { if (command) {
char *commandStr; sts = run_command(command, &cf);
PyObject *commandObj = PyUnicode_FromWideChar(
command, wcslen(command));
free(command); free(command);
if (commandObj != NULL)
commandStr = _PyUnicode_AsString(commandObj);
else
commandStr = NULL;
if (commandStr != NULL) {
sts = PyRun_SimpleStringFlags(commandStr, &cf) != 0;
Py_DECREF(commandObj);
}
else {
PyErr_Print();
sts = 1;
}
} else if (module) { } else if (module) {
sts = RunModule(module, 1); sts = RunModule(module, 1);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment