@@ -101,8 +101,8 @@ mpl_PyFile_Dup(PyObject *file, char *mode, mpl_off_t *orig_pos)
101
101
/* Record the original raw file handle position */
102
102
* orig_pos = npy_ftell (handle );
103
103
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 ;
106
106
}
107
107
108
108
/* Seek raw handle to the Python-side position */
@@ -145,22 +145,19 @@ mpl_PyFile_DupClose(PyObject *file, FILE* handle, mpl_off_t orig_pos)
145
145
if (fd == -1 ) {
146
146
return -1 ;
147
147
}
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
+ }
157
153
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 );
162
160
}
163
- Py_DECREF (ret );
164
161
return 0 ;
165
162
}
166
163
0 commit comments