summaryrefslogtreecommitdiffstats
path: root/Python/bltinmodule.c
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2009-03-02 23:31:26 (GMT)
committerBenjamin Peterson <benjamin@python.org>2009-03-02 23:31:26 (GMT)
commitf5b52246ed8a1191c3aa1da7d3c63bbe11aee020 (patch)
treedcac9a1daca7f583ff958cb61f73e9ed11b5564b /Python/bltinmodule.c
parent0663a1ed793c164fb11d3dd62bebc677e260891e (diff)
downloadcpython-f5b52246ed8a1191c3aa1da7d3c63bbe11aee020.zip
cpython-f5b52246ed8a1191c3aa1da7d3c63bbe11aee020.tar.gz
cpython-f5b52246ed8a1191c3aa1da7d3c63bbe11aee020.tar.bz2
ignore the coding cookie in compile(), exec(), and eval() if the source is a string #4626
Diffstat (limited to 'Python/bltinmodule.c')
-rw-r--r--Python/bltinmodule.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c
index 9805697..7a27fba 100644
--- a/Python/bltinmodule.c
+++ b/Python/bltinmodule.c
@@ -494,12 +494,13 @@ PyDoc_STR(
static char *
-source_as_string(PyObject *cmd, char *funcname, char *what)
+source_as_string(PyObject *cmd, char *funcname, char *what, PyCompilerFlags *cf)
{
char *str;
Py_ssize_t size;
if (PyUnicode_Check(cmd)) {
+ cf->cf_flags |= PyCF_IGNORE_COOKIE;
cmd = _PyUnicode_AsDefaultEncodedString(cmd, NULL);
if (cmd == NULL)
return NULL;
@@ -591,7 +592,7 @@ builtin_compile(PyObject *self, PyObject *args, PyObject *kwds)
return result;
}
- str = source_as_string(cmd, "compile", "string, bytes, AST or code");
+ str = source_as_string(cmd, "compile", "string, bytes, AST or code", &cf);
if (str == NULL)
return NULL;
@@ -703,14 +704,14 @@ builtin_eval(PyObject *self, PyObject *args)
return PyEval_EvalCode((PyCodeObject *) cmd, globals, locals);
}
- str = source_as_string(cmd, "eval", "string, bytes or code");
+ cf.cf_flags = PyCF_SOURCE_IS_UTF8;
+ str = source_as_string(cmd, "eval", "string, bytes or code", &cf);
if (str == NULL)
return NULL;
while (*str == ' ' || *str == '\t')
str++;
- cf.cf_flags = PyCF_SOURCE_IS_UTF8;
(void)PyEval_MergeCompilerFlags(&cf);
result = PyRun_StringFlags(str, Py_eval_input, globals, locals, &cf);
Py_XDECREF(tmp);
@@ -779,12 +780,13 @@ builtin_exec(PyObject *self, PyObject *args)
v = PyEval_EvalCode((PyCodeObject *) prog, globals, locals);
}
else {
- char *str = source_as_string(prog, "exec",
- "string, bytes or code");
+ char *str;
PyCompilerFlags cf;
+ cf.cf_flags = PyCF_SOURCE_IS_UTF8;
+ str = source_as_string(prog, "exec",
+ "string, bytes or code", &cf);
if (str == NULL)
return NULL;
- cf.cf_flags = PyCF_SOURCE_IS_UTF8;
if (PyEval_MergeCompilerFlags(&cf))
v = PyRun_StringFlags(str, Py_file_input, globals,
locals, &cf);