@@ -497,16 +497,12 @@ fp_readl(char *s, int size, struct tok_state *tok)
497
497
static int
498
498
fp_setreadl (struct tok_state * tok , const char * enc )
499
499
{
500
- PyObject * readline = NULL , * stream = NULL , * io = NULL ;
500
+ PyObject * readline , * io , * stream ;
501
501
_Py_IDENTIFIER (open );
502
502
_Py_IDENTIFIER (readline );
503
503
int fd ;
504
504
long pos ;
505
505
506
- io = PyImport_ImportModuleNoBlock ("io" );
507
- if (io == NULL )
508
- goto cleanup ;
509
-
510
506
fd = fileno (tok -> fp );
511
507
/* Due to buffering the file offset for fd can be different from the file
512
508
* position of tok->fp. If tok->fp was opened in text mode on Windows,
@@ -517,27 +513,33 @@ fp_setreadl(struct tok_state *tok, const char* enc)
517
513
if (pos == -1 ||
518
514
lseek (fd , (off_t )(pos > 0 ? pos - 1 : pos ), SEEK_SET ) == (off_t )- 1 ) {
519
515
PyErr_SetFromErrnoWithFilename (PyExc_OSError , NULL );
520
- goto cleanup ;
516
+ return 0 ;
521
517
}
522
518
519
+ io = PyImport_ImportModuleNoBlock ("io" );
520
+ if (io == NULL )
521
+ return 0 ;
522
+
523
523
stream = _PyObject_CallMethodId (io , & PyId_open , "isisOOO" ,
524
524
fd , "r" , -1 , enc , Py_None , Py_None , Py_False );
525
+ Py_DECREF (io );
525
526
if (stream == NULL )
526
- goto cleanup ;
527
+ return 0 ;
527
528
528
529
readline = _PyObject_GetAttrId (stream , & PyId_readline );
530
+ Py_DECREF (stream );
531
+ if (readline == NULL )
532
+ return 0 ;
529
533
Py_XSETREF (tok -> decoding_readline , readline );
534
+
530
535
if (pos > 0 ) {
531
- if ( PyObject_CallObject (readline , NULL ) == NULL ) {
532
- readline = NULL ;
533
- goto cleanup ;
534
- }
536
+ PyObject * bufobj = PyObject_CallObject (readline , NULL );
537
+ if ( bufobj == NULL )
538
+ return 0 ;
539
+ Py_DECREF ( bufobj );
535
540
}
536
541
537
- cleanup :
538
- Py_XDECREF (stream );
539
- Py_XDECREF (io );
540
- return readline != NULL ;
542
+ return 1 ;
541
543
}
542
544
543
545
/* Fetch the next byte from TOK. */
0 commit comments