@@ -101,8 +101,8 @@ mpl_PyFile_Dup(PyObject *file, char *mode, mpl_off_t *orig_pos)
101101 /* Record the original raw file handle position */
102102 * orig_pos = npy_ftell (handle );
103103 if (* orig_pos == -1 ) {
104- PyErr_SetString ( PyExc_IOError , "obtaining file position failed" );
105- return NULL ;
104+ // handle is a stream, so we don't have to worry about this
105+ return handle ;
106106 }
107107
108108 /* Seek raw handle to the Python-side position */
@@ -145,22 +145,19 @@ mpl_PyFile_DupClose(PyObject *file, FILE* handle, mpl_off_t orig_pos)
145145 if (fd == -1 ) {
146146 return -1 ;
147147 }
148- if (npy_lseek (fd , orig_pos , SEEK_SET ) == -1 ) {
149- PyErr_SetString (PyExc_IOError , "seeking file failed" );
150- return -1 ;
151- }
152-
153- if (position == -1 ) {
154- PyErr_SetString (PyExc_IOError , "obtaining file position failed" );
155- return -1 ;
156- }
148+ if (npy_lseek (fd , orig_pos , SEEK_SET ) != -1 ) {
149+ if (position == -1 ) {
150+ PyErr_SetString (PyExc_IOError , "obtaining file position failed" );
151+ return -1 ;
152+ }
157153
158- /* Seek Python-side handle to the FILE* handle position */
159- ret = PyObject_CallMethod (file , "seek" , MPL_OFF_T_PYFMT "i" , position , 0 );
160- if (ret == NULL ) {
161- return -1 ;
154+ /* Seek Python-side handle to the FILE* handle position */
155+ ret = PyObject_CallMethod (file , "seek" , MPL_OFF_T_PYFMT "i" , position , 0 );
156+ if (ret == NULL ) {
157+ return -1 ;
158+ }
159+ Py_DECREF (ret );
162160 }
163- Py_DECREF (ret );
164161 return 0 ;
165162}
166163
0 commit comments