@@ -1808,10 +1808,9 @@ pymarshal_write_long_to_file(PyObject* self, PyObject *args)
18081808 }
18091809
18101810 PyMarshal_WriteLongToFile (value , fp , version );
1811+ assert (!PyErr_Occurred ());
18111812
18121813 fclose (fp );
1813- if (PyErr_Occurred ())
1814- return NULL ;
18151814 Py_RETURN_NONE ;
18161815}
18171816
@@ -1834,10 +1833,9 @@ pymarshal_write_object_to_file(PyObject* self, PyObject *args)
18341833 }
18351834
18361835 PyMarshal_WriteObjectToFile (obj , fp , version );
1836+ assert (!PyErr_Occurred ());
18371837
18381838 fclose (fp );
1839- if (PyErr_Occurred ())
1840- return NULL ;
18411839 Py_RETURN_NONE ;
18421840}
18431841
@@ -1895,48 +1893,46 @@ pymarshal_read_long_from_file(PyObject* self, PyObject *args)
18951893static PyObject *
18961894pymarshal_read_last_object_from_file (PyObject * self , PyObject * args )
18971895{
1898- PyObject * obj ;
1899- long pos ;
19001896 PyObject * filename ;
1901- FILE * fp ;
1902-
19031897 if (!PyArg_ParseTuple (args , "O:pymarshal_read_last_object_from_file" , & filename ))
19041898 return NULL ;
19051899
1906- fp = _Py_fopen_obj (filename , "rb" );
1900+ FILE * fp = _Py_fopen_obj (filename , "rb" );
19071901 if (fp == NULL ) {
19081902 PyErr_SetFromErrno (PyExc_OSError );
19091903 return NULL ;
19101904 }
19111905
1912- obj = PyMarshal_ReadLastObjectFromFile (fp );
1913- pos = ftell (fp );
1906+ PyObject * obj = PyMarshal_ReadLastObjectFromFile (fp );
1907+ long pos = ftell (fp );
19141908
19151909 fclose (fp );
1910+ if (obj == NULL ) {
1911+ return NULL ;
1912+ }
19161913 return Py_BuildValue ("Nl" , obj , pos );
19171914}
19181915
19191916static PyObject *
19201917pymarshal_read_object_from_file (PyObject * self , PyObject * args )
19211918{
1922- PyObject * obj ;
1923- long pos ;
19241919 PyObject * filename ;
1925- FILE * fp ;
1926-
19271920 if (!PyArg_ParseTuple (args , "O:pymarshal_read_object_from_file" , & filename ))
19281921 return NULL ;
19291922
1930- fp = _Py_fopen_obj (filename , "rb" );
1923+ FILE * fp = _Py_fopen_obj (filename , "rb" );
19311924 if (fp == NULL ) {
19321925 PyErr_SetFromErrno (PyExc_OSError );
19331926 return NULL ;
19341927 }
19351928
1936- obj = PyMarshal_ReadObjectFromFile (fp );
1937- pos = ftell (fp );
1929+ PyObject * obj = PyMarshal_ReadObjectFromFile (fp );
1930+ long pos = ftell (fp );
19381931
19391932 fclose (fp );
1933+ if (obj == NULL ) {
1934+ return NULL ;
1935+ }
19401936 return Py_BuildValue ("Nl" , obj , pos );
19411937}
19421938
0 commit comments