@@ -1579,70 +1579,6 @@ PyTokenizer_Get(struct tok_state *tok, char **p_start, char **p_end)
15791579 return result ;
15801580}
15811581
1582- /* This function is only called from parsetok. However, it cannot live
1583- there, as it must be empty for PGEN, and we can check for PGEN only
1584- in this file. */
1585-
1586- #ifdef PGEN
1587- char *
1588- PyTokenizer_RestoreEncoding (struct tok_state * tok , int len , int * offset )
1589- {
1590- return NULL ;
1591- }
1592- #else
1593- static PyObject *
1594- dec_utf8 (const char * enc , const char * text , size_t len ) {
1595- PyObject * ret = NULL ;
1596- PyObject * unicode_text = PyUnicode_DecodeUTF8 (text , len , "replace" );
1597- if (unicode_text ) {
1598- ret = PyUnicode_AsEncodedString (unicode_text , enc , "replace" );
1599- Py_DECREF (unicode_text );
1600- }
1601- if (!ret ) {
1602- PyErr_Clear ();
1603- }
1604- else {
1605- assert (PyString_Check (ret ));
1606- }
1607- return ret ;
1608- }
1609-
1610- char *
1611- PyTokenizer_RestoreEncoding (struct tok_state * tok , int len , int * offset )
1612- {
1613- char * text = NULL ;
1614- if (tok -> encoding ) {
1615- /* convert source to original encondig */
1616- PyObject * lineobj = dec_utf8 (tok -> encoding , tok -> buf , len );
1617- if (lineobj != NULL ) {
1618- int linelen = PyString_GET_SIZE (lineobj );
1619- const char * line = PyString_AS_STRING (lineobj );
1620- text = PyObject_MALLOC (linelen + 1 );
1621- if (text != NULL && line != NULL ) {
1622- if (linelen )
1623- strncpy (text , line , linelen );
1624- text [linelen ] = '\0' ;
1625- }
1626- Py_DECREF (lineobj );
1627-
1628- /* adjust error offset */
1629- if (* offset > 1 ) {
1630- PyObject * offsetobj = dec_utf8 (tok -> encoding ,
1631- tok -> buf ,
1632- * offset - 1 );
1633- if (offsetobj ) {
1634- * offset = 1 + Py_SIZE (offsetobj );
1635- Py_DECREF (offsetobj );
1636- }
1637- }
1638-
1639- }
1640- }
1641- return text ;
1642-
1643- }
1644- #endif
1645-
16461582/* Get -*- encoding -*- from a Python file.
16471583
16481584 PyTokenizer_FindEncoding returns NULL when it can't find the encoding in
0 commit comments