1818*/
1919#if defined(MS_WINDOWS ) && defined(HAVE_USABLE_WCHAR_T )
2020const char * Py_FileSystemDefaultEncoding = "mbcs" ;
21+ #elif defined(__APPLE__ )
22+ const char * Py_FileSystemDefaultEncoding = "utf-8" ;
2123#else
2224const 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