Commit d4080a99 authored by Just van Rossum's avatar Just van Rossum

My previous checkin caused compile() to no longer accept buffers, as noted

my MAL. Fixed. (Btw. eval() still doesn't take buffers, but that was so
even before my patch.)
parent 8f88ae53
...@@ -18,6 +18,8 @@ ...@@ -18,6 +18,8 @@
*/ */
#if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T) #if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T)
const char *Py_FileSystemDefaultEncoding = "mbcs"; const char *Py_FileSystemDefaultEncoding = "mbcs";
#elif defined(__APPLE__)
const char *Py_FileSystemDefaultEncoding = "utf-8";
#else #else
const char *Py_FileSystemDefaultEncoding = NULL; /* use default */ const char *Py_FileSystemDefaultEncoding = NULL; /* use default */
#endif #endif
...@@ -341,6 +343,7 @@ builtin_compile(PyObject *self, PyObject *args) ...@@ -341,6 +343,7 @@ builtin_compile(PyObject *self, PyObject *args)
int supplied_flags = 0; int supplied_flags = 0;
PyCompilerFlags cf; PyCompilerFlags cf;
PyObject *result, *cmd, *tmp = NULL; PyObject *result, *cmd, *tmp = NULL;
int length;
if (!PyArg_ParseTuple(args, "Oss|ii:compile", &cmd, &filename, if (!PyArg_ParseTuple(args, "Oss|ii:compile", &cmd, &filename,
&startstr, &supplied_flags, &dont_inherit)) &startstr, &supplied_flags, &dont_inherit))
...@@ -357,15 +360,14 @@ builtin_compile(PyObject *self, PyObject *args) ...@@ -357,15 +360,14 @@ builtin_compile(PyObject *self, PyObject *args)
cf.cf_flags |= PyCF_SOURCE_IS_UTF8; cf.cf_flags |= PyCF_SOURCE_IS_UTF8;
} }
#endif #endif
if (!PyString_Check(cmd)) { if (PyObject_AsReadBuffer(cmd, (const void **)&str, &length))
return NULL;
if (length != strlen(str)) {
PyErr_SetString(PyExc_TypeError, PyErr_SetString(PyExc_TypeError,
"compile() arg 1 must be a string"); "expected string without null bytes");
return NULL; return NULL;
} }
if (PyString_AsStringAndSize(cmd, &str, NULL))
return NULL;
if (strcmp(startstr, "exec") == 0) if (strcmp(startstr, "exec") == 0)
start = Py_file_input; start = Py_file_input;
else if (strcmp(startstr, "eval") == 0) else if (strcmp(startstr, "eval") == 0)
......
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