@@ -1666,25 +1666,30 @@ _Unpickler_SetInputStream(UnpicklerObject *self, PyObject *file)
1666
1666
{
1667
1667
/* Optional file methods */
1668
1668
if (_PyObject_LookupAttr (file , & _Py_ID (peek ), & self -> peek ) < 0 ) {
1669
- return -1 ;
1669
+ goto error ;
1670
1670
}
1671
1671
if (_PyObject_LookupAttr (file , & _Py_ID (readinto ), & self -> readinto ) < 0 ) {
1672
- return -1 ;
1672
+ goto error ;
1673
+ }
1674
+ if (_PyObject_LookupAttr (file , & _Py_ID (read ), & self -> read ) < 0 ) {
1675
+ goto error ;
1676
+ }
1677
+ if (_PyObject_LookupAttr (file , & _Py_ID (readline ), & self -> readline ) < 0 ) {
1678
+ goto error ;
1673
1679
}
1674
- (void )_PyObject_LookupAttr (file , & _Py_ID (read ), & self -> read );
1675
- (void )_PyObject_LookupAttr (file , & _Py_ID (readline ), & self -> readline );
1676
1680
if (!self -> readline || !self -> read ) {
1677
- if (!PyErr_Occurred ()) {
1678
- PyErr_SetString (PyExc_TypeError ,
1679
- "file must have 'read' and 'readline' attributes" );
1680
- }
1681
- Py_CLEAR (self -> read );
1682
- Py_CLEAR (self -> readinto );
1683
- Py_CLEAR (self -> readline );
1684
- Py_CLEAR (self -> peek );
1685
- return -1 ;
1681
+ PyErr_SetString (PyExc_TypeError ,
1682
+ "file must have 'read' and 'readline' attributes" );
1683
+ goto error ;
1686
1684
}
1687
1685
return 0 ;
1686
+
1687
+ error :
1688
+ Py_CLEAR (self -> read );
1689
+ Py_CLEAR (self -> readinto );
1690
+ Py_CLEAR (self -> readline );
1691
+ Py_CLEAR (self -> peek );
1692
+ return -1 ;
1688
1693
}
1689
1694
1690
1695
/* Returns -1 (with an exception set) on failure, 0 on success. This may
0 commit comments