@@ -1694,25 +1694,30 @@ _Unpickler_SetInputStream(UnpicklerObject *self, PyObject *file)
1694
1694
{
1695
1695
/* Optional file methods */
1696
1696
if (_PyObject_LookupAttr (file , & _Py_ID (peek ), & self -> peek ) < 0 ) {
1697
- return -1 ;
1697
+ goto error ;
1698
1698
}
1699
1699
if (_PyObject_LookupAttr (file , & _Py_ID (readinto ), & self -> readinto ) < 0 ) {
1700
- return -1 ;
1700
+ goto error ;
1701
+ }
1702
+ if (_PyObject_LookupAttr (file , & _Py_ID (read ), & self -> read ) < 0 ) {
1703
+ goto error ;
1704
+ }
1705
+ if (_PyObject_LookupAttr (file , & _Py_ID (readline ), & self -> readline ) < 0 ) {
1706
+ goto error ;
1701
1707
}
1702
- (void )_PyObject_LookupAttr (file , & _Py_ID (read ), & self -> read );
1703
- (void )_PyObject_LookupAttr (file , & _Py_ID (readline ), & self -> readline );
1704
1708
if (!self -> readline || !self -> read ) {
1705
- if (!PyErr_Occurred ()) {
1706
- PyErr_SetString (PyExc_TypeError ,
1707
- "file must have 'read' and 'readline' attributes" );
1708
- }
1709
- Py_CLEAR (self -> read );
1710
- Py_CLEAR (self -> readinto );
1711
- Py_CLEAR (self -> readline );
1712
- Py_CLEAR (self -> peek );
1713
- return -1 ;
1709
+ PyErr_SetString (PyExc_TypeError ,
1710
+ "file must have 'read' and 'readline' attributes" );
1711
+ goto error ;
1714
1712
}
1715
1713
return 0 ;
1714
+
1715
+ error :
1716
+ Py_CLEAR (self -> read );
1717
+ Py_CLEAR (self -> readinto );
1718
+ Py_CLEAR (self -> readline );
1719
+ Py_CLEAR (self -> peek );
1720
+ return -1 ;
1716
1721
}
1717
1722
1718
1723
/* Returns -1 (with an exception set) on failure, 0 on success. This may
0 commit comments