File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -645,13 +645,40 @@ file_readinto(PyFileObject *f, PyObject *args)
645645static PyObject *
646646get_line (PyFileObject * f , int n )
647647{
648- register FILE * fp ;
648+ register FILE * fp = f -> f_fp ;
649649 register int c ;
650- register char * buf , * end ;
650+ char * buf , * end ;
651651 size_t n1 , n2 ;
652652 PyObject * v ;
653653
654- fp = f -> f_fp ;
654+ #ifdef HAVE_GETLINE
655+ /* Use GNU libc extension getline() for arbitrary-sized lines */
656+ if (n == 0 ) {
657+ size_t size = 0 ;
658+ buf = NULL ;
659+ Py_BEGIN_ALLOW_THREADS
660+ n1 = getline (& buf , & size , fp );
661+ Py_END_ALLOW_THREADS
662+ if (n1 == -1 ) {
663+ clearerr (fp );
664+ if (PyErr_CheckSignals ()) {
665+ return NULL ;
666+ }
667+ if (n < 0 && feof (fp )) {
668+ PyErr_SetString (PyExc_EOFError ,
669+ "EOF when reading a line" );
670+ return NULL ;
671+ }
672+ return PyString_FromStringAndSize (NULL , 0 );
673+ }
674+ /* No error */
675+
676+ v = PyString_FromStringAndSize (buf , n1 );
677+ free (buf );
678+ return v ;
679+ }
680+ #endif
681+
655682 n2 = n > 0 ? n : 100 ;
656683 v = PyString_FromStringAndSize ((char * )NULL , n2 );
657684 if (v == NULL )
You can’t perform that action at this time.
0 commit comments