@@ -687,55 +687,6 @@ builtin_chr_impl(PyObject *module, int i)
687687}
688688
689689
690- static const char *
691- source_as_string (PyObject * cmd , const char * funcname , const char * what , PyCompilerFlags * cf , PyObject * * cmd_copy )
692- {
693- const char * str ;
694- Py_ssize_t size ;
695- Py_buffer view ;
696-
697- * cmd_copy = NULL ;
698- if (PyUnicode_Check (cmd )) {
699- cf -> cf_flags |= PyCF_IGNORE_COOKIE ;
700- str = PyUnicode_AsUTF8AndSize (cmd , & size );
701- if (str == NULL )
702- return NULL ;
703- }
704- else if (PyBytes_Check (cmd )) {
705- str = PyBytes_AS_STRING (cmd );
706- size = PyBytes_GET_SIZE (cmd );
707- }
708- else if (PyByteArray_Check (cmd )) {
709- str = PyByteArray_AS_STRING (cmd );
710- size = PyByteArray_GET_SIZE (cmd );
711- }
712- else if (PyObject_GetBuffer (cmd , & view , PyBUF_SIMPLE ) == 0 ) {
713- /* Copy to NUL-terminated buffer. */
714- * cmd_copy = PyBytes_FromStringAndSize (
715- (const char * )view .buf , view .len );
716- PyBuffer_Release (& view );
717- if (* cmd_copy == NULL ) {
718- return NULL ;
719- }
720- str = PyBytes_AS_STRING (* cmd_copy );
721- size = PyBytes_GET_SIZE (* cmd_copy );
722- }
723- else {
724- PyErr_Format (PyExc_TypeError ,
725- "%s() arg 1 must be a %s object" ,
726- funcname , what );
727- return NULL ;
728- }
729-
730- if (strlen (str ) != (size_t )size ) {
731- PyErr_SetString (PyExc_ValueError ,
732- "source code string cannot contain null bytes" );
733- Py_CLEAR (* cmd_copy );
734- return NULL ;
735- }
736- return str ;
737- }
738-
739690/*[clinic input]
740691compile as builtin_compile
741692
@@ -855,7 +806,7 @@ builtin_compile_impl(PyObject *module, PyObject *source, PyObject *filename,
855806 goto finally ;
856807 }
857808
858- str = source_as_string (source , "compile" , "string, bytes or AST" , & cf , & source_copy );
809+ str = _Py_SourceAsString (source , "compile" , "string, bytes or AST" , & cf , & source_copy );
859810 if (str == NULL )
860811 goto error ;
861812
@@ -991,7 +942,7 @@ builtin_eval_impl(PyObject *module, PyObject *source, PyObject *globals,
991942
992943 cf .cf_flags = PyCF_SOURCE_IS_UTF8 ;
993944 cf .cf_feature_version = PY_MINOR_VERSION ;
994- str = source_as_string (source , "eval" , "string, bytes or code" , & cf , & source_copy );
945+ str = _Py_SourceAsString (source , "eval" , "string, bytes or code" , & cf , & source_copy );
995946 if (str == NULL )
996947 return NULL ;
997948
@@ -1083,7 +1034,7 @@ builtin_exec_impl(PyObject *module, PyObject *source, PyObject *globals,
10831034 PyCompilerFlags cf ;
10841035 cf .cf_flags = PyCF_SOURCE_IS_UTF8 ;
10851036 cf .cf_feature_version = PY_MINOR_VERSION ;
1086- str = source_as_string (source , "exec" ,
1037+ str = _Py_SourceAsString (source , "exec" ,
10871038 "string, bytes or code" , & cf ,
10881039 & source_copy );
10891040 if (str == NULL )
0 commit comments