@@ -1610,13 +1610,19 @@ builtin_input(PyObject *self, PyObject *args)
16101610 char * prompt ;
16111611 char * s ;
16121612 PyObject * stdin_encoding ;
1613+ char * stdin_encoding_str ;
16131614 PyObject * result ;
16141615
16151616 stdin_encoding = PyObject_GetAttrString (fin , "encoding" );
16161617 if (!stdin_encoding )
16171618 /* stdin is a text stream, so it must have an
16181619 encoding. */
16191620 return NULL ;
1621+ stdin_encoding_str = _PyUnicode_AsString (stdin_encoding );
1622+ if (stdin_encoding_str == NULL ) {
1623+ Py_DECREF (stdin_encoding );
1624+ return NULL ;
1625+ }
16201626 tmp = PyObject_CallMethod (fout , "flush" , "" );
16211627 if (tmp == NULL )
16221628 PyErr_Clear ();
@@ -1625,20 +1631,26 @@ builtin_input(PyObject *self, PyObject *args)
16251631 if (promptarg != NULL ) {
16261632 PyObject * stringpo ;
16271633 PyObject * stdout_encoding ;
1628- stdout_encoding = PyObject_GetAttrString ( fout ,
1629- "encoding" );
1634+ char * stdout_encoding_str ;
1635+ stdout_encoding = PyObject_GetAttrString ( fout , "encoding" );
16301636 if (stdout_encoding == NULL ) {
16311637 Py_DECREF (stdin_encoding );
16321638 return NULL ;
16331639 }
1640+ stdout_encoding_str = _PyUnicode_AsString (stdout_encoding );
1641+ if (stdout_encoding_str == NULL ) {
1642+ Py_DECREF (stdin_encoding );
1643+ Py_DECREF (stdout_encoding );
1644+ return NULL ;
1645+ }
16341646 stringpo = PyObject_Str (promptarg );
16351647 if (stringpo == NULL ) {
16361648 Py_DECREF (stdin_encoding );
16371649 Py_DECREF (stdout_encoding );
16381650 return NULL ;
16391651 }
16401652 po = PyUnicode_AsEncodedString (stringpo ,
1641- _PyUnicode_AsString ( stdout_encoding ) , NULL );
1653+ stdout_encoding_str , NULL );
16421654 Py_DECREF (stdout_encoding );
16431655 Py_DECREF (stringpo );
16441656 if (po == NULL ) {
@@ -1676,10 +1688,7 @@ builtin_input(PyObject *self, PyObject *args)
16761688 result = NULL ;
16771689 }
16781690 else {
1679- result = PyUnicode_Decode
1680- (s , len - 1 ,
1681- _PyUnicode_AsString (stdin_encoding ),
1682- NULL );
1691+ result = PyUnicode_Decode (s , len - 1 , stdin_encoding_str , NULL );
16831692 }
16841693 }
16851694 Py_DECREF (stdin_encoding );
0 commit comments