@@ -417,7 +417,7 @@ add a line to the history buffer");
417417static PyObject *
418418get_completer_delims (PyObject * self , PyObject * noarg )
419419{
420- return PyString_FromString (rl_completer_word_break_characters );
420+ return PyUnicode_FromString (rl_completer_word_break_characters );
421421}
422422
423423PyDoc_STRVAR (doc_get_completer_delims ,
@@ -468,7 +468,7 @@ get_history_item(PyObject *self, PyObject *args)
468468 if (!PyArg_ParseTuple (args , "i:index" , & idx ))
469469 return NULL ;
470470 if ((hist_ent = history_get (idx )))
471- return PyString_FromString (hist_ent -> line );
471+ return PyUnicode_FromString (hist_ent -> line );
472472 else {
473473 Py_INCREF (Py_None );
474474 return Py_None ;
@@ -501,7 +501,7 @@ return the current (not the maximum) length of history.");
501501static PyObject *
502502get_line_buffer (PyObject * self , PyObject * noarg )
503503{
504- return PyString_FromString (rl_line_buffer );
504+ return PyUnicode_FromString (rl_line_buffer );
505505}
506506
507507PyDoc_STRVAR (doc_get_line_buffer ,
@@ -620,7 +620,7 @@ on_hook(PyObject *func)
620620 int result = 0 ;
621621 if (func != NULL ) {
622622 PyObject * r ;
623- #ifdef WITH_THREAD
623+ #ifdef WITH_THREAD
624624 PyGILState_STATE gilstate = PyGILState_Ensure ();
625625#endif
626626 r = PyObject_CallFunction (func , NULL );
@@ -670,21 +670,25 @@ on_completion_display_matches_hook(char **matches,
670670{
671671 if (completion_display_matches_hook != NULL ) {
672672 int i ;
673- PyObject * m , * s ;
673+ PyObject * m , * s , * match ;
674674 PyObject * r ;
675- #ifdef WITH_THREAD
675+ #ifdef WITH_THREAD
676676 PyGILState_STATE gilstate = PyGILState_Ensure ();
677677#endif
678678 m = PyList_New (num_matches );
679679 for (i = 0 ; i < num_matches ; i ++ ) {
680- s = PyString_FromString (matches [i + 1 ]);
681- PyList_SetItem (m , i , s );
680+ s = PyUnicode_FromString (matches [i + 1 ]);
681+ if (s ) {
682+ PyList_SetItem (m , i , s );
683+ }
684+ else {
685+ goto error ;
686+ }
682687 }
683-
684688 r = PyObject_CallFunction (completion_display_matches_hook ,
685689 "sOi" , matches [0 ], m , max_length );
686690
687- Py_DECREF (m );
691+ Py_DECREF (m ), m = NULL ;
688692
689693 if (r == NULL ||
690694 (r != Py_None && PyInt_AsLong (r ) == -1 && PyErr_Occurred ())) {
@@ -695,9 +699,10 @@ on_completion_display_matches_hook(char **matches,
695699 goto done ;
696700 error :
697701 PyErr_Clear ();
702+ Py_XDECREF (m );
698703 Py_XDECREF (r );
699704 done :
700- #ifdef WITH_THREAD
705+ #ifdef WITH_THREAD
701706 PyGILState_Release (gilstate );
702707#endif
703708 }
@@ -712,7 +717,7 @@ on_completion(const char *text, int state)
712717 char * result = NULL ;
713718 if (completer != NULL ) {
714719 PyObject * r ;
715- #ifdef WITH_THREAD
720+ #ifdef WITH_THREAD
716721 PyGILState_STATE gilstate = PyGILState_Ensure ();
717722#endif
718723 rl_attempted_completion_over = 1 ;
@@ -723,7 +728,7 @@ on_completion(const char *text, int state)
723728 result = NULL ;
724729 }
725730 else {
726- char * s = PyString_AsString (r );
731+ char * s = PyUnicode_AsString (r );
727732 if (s == NULL )
728733 goto error ;
729734 result = strdup (s );
@@ -734,7 +739,7 @@ on_completion(const char *text, int state)
734739 PyErr_Clear ();
735740 Py_XDECREF (r );
736741 done :
737- #ifdef WITH_THREAD
742+ #ifdef WITH_THREAD
738743 PyGILState_Release (gilstate );
739744#endif
740745 return result ;
0 commit comments