Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b9b8e9c

Browse files
committed
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.)
1 parent 3aaf42c commit b9b8e9c

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

Python/bltinmodule.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
*/
1919
#if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T)
2020
const char *Py_FileSystemDefaultEncoding = "mbcs";
21+
#elif defined(__APPLE__)
22+
const char *Py_FileSystemDefaultEncoding = "utf-8";
2123
#else
2224
const char *Py_FileSystemDefaultEncoding = NULL; /* use default */
2325
#endif
@@ -341,6 +343,7 @@ builtin_compile(PyObject *self, PyObject *args)
341343
int supplied_flags = 0;
342344
PyCompilerFlags cf;
343345
PyObject *result, *cmd, *tmp = NULL;
346+
int length;
344347

345348
if (!PyArg_ParseTuple(args, "Oss|ii:compile", &cmd, &filename,
346349
&startstr, &supplied_flags, &dont_inherit))
@@ -357,15 +360,14 @@ builtin_compile(PyObject *self, PyObject *args)
357360
cf.cf_flags |= PyCF_SOURCE_IS_UTF8;
358361
}
359362
#endif
360-
if (!PyString_Check(cmd)) {
363+
if (PyObject_AsReadBuffer(cmd, (const void **)&str, &length))
364+
return NULL;
365+
if (length != strlen(str)) {
361366
PyErr_SetString(PyExc_TypeError,
362-
"compile() arg 1 must be a string");
367+
"expected string without null bytes");
363368
return NULL;
364369
}
365370

366-
if (PyString_AsStringAndSize(cmd, &str, NULL))
367-
return NULL;
368-
369371
if (strcmp(startstr, "exec") == 0)
370372
start = Py_file_input;
371373
else if (strcmp(startstr, "eval") == 0)

0 commit comments

Comments
 (0)