summaryrefslogtreecommitdiffstats
path: root/Modules/main.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2010-08-07 10:57:17 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2010-08-07 10:57:17 (GMT)
commita62207c5847948b83d698b5fb4b2c1a03434a5a6 (patch)
treecb44e1bb560d8042d3d838a473d472ce90bffce0 /Modules/main.c
parent6c6f851eae204c3a4f85108c3d564133d58c887a (diff)
downloadcpython-a62207c5847948b83d698b5fb4b2c1a03434a5a6.zip
cpython-a62207c5847948b83d698b5fb4b2c1a03434a5a6.tar.gz
cpython-a62207c5847948b83d698b5fb4b2c1a03434a5a6.tar.bz2
Issue #9425: Create run_command() subfunction
Use PyUnicode_AsUTF8String() instead of _PyUnicode_AsString()
Diffstat (limited to 'Modules/main.c')
-rw-r--r--Modules/main.c38
1 files changed, 23 insertions, 15 deletions
diff --git a/Modules/main.c b/Modules/main.c
index 29f5fc8..bebaab5 100644
--- a/Modules/main.c
+++ b/Modules/main.c
@@ -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 */
@@ -564,22 +586,8 @@ Py_Main(int argc, wchar_t **argv)
}
if (command) {
- char *commandStr;
- PyObject *commandObj = PyUnicode_FromWideChar(
- command, wcslen(command));
+ sts = run_command(command, &cf);
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) {
sts = RunModule(module, 1);
}