This array creation function does not steal the reference to dtype. */
| 3304 | |
| 3305 | /* This array creation function does not steal the reference to dtype. */ |
| 3306 | static PyArrayObject * |
| 3307 | array_fromfile_binary(FILE *fp, PyArray_Descr *dtype, npy_intp num, size_t *nread) |
| 3308 | { |
| 3309 | PyArrayObject *r; |
| 3310 | npy_off_t start, numbytes; |
| 3311 | int elsize; |
| 3312 | |
| 3313 | if (num < 0) { |
| 3314 | int fail = 0; |
| 3315 | start = npy_ftell(fp); |
| 3316 | if (start < 0) { |
| 3317 | fail = 1; |
| 3318 | } |
| 3319 | if (npy_fseek(fp, 0, SEEK_END) < 0) { |
| 3320 | fail = 1; |
| 3321 | } |
| 3322 | numbytes = npy_ftell(fp); |
| 3323 | if (numbytes < 0) { |
| 3324 | fail = 1; |
| 3325 | } |
| 3326 | numbytes -= start; |
| 3327 | if (npy_fseek(fp, start, SEEK_SET) < 0) { |
| 3328 | fail = 1; |
| 3329 | } |
| 3330 | if (fail) { |
| 3331 | PyErr_SetString(PyExc_OSError, |
| 3332 | "could not seek in file"); |
| 3333 | return NULL; |
| 3334 | } |
| 3335 | num = numbytes / dtype->elsize; |
| 3336 | } |
| 3337 | |
| 3338 | /* |
| 3339 | * Array creation may move sub-array dimensions from the dtype to array |
| 3340 | * dimensions, so we need to use the original element size when reading. |
| 3341 | */ |
| 3342 | elsize = dtype->elsize; |
| 3343 | |
| 3344 | Py_INCREF(dtype); /* do not steal the original dtype. */ |
| 3345 | r = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, dtype, 1, &num, |
| 3346 | NULL, NULL, 0, NULL); |
| 3347 | if (r == NULL) { |
| 3348 | return NULL; |
| 3349 | } |
| 3350 | |
| 3351 | NPY_BEGIN_ALLOW_THREADS; |
| 3352 | *nread = fread(PyArray_DATA(r), elsize, num, fp); |
| 3353 | NPY_END_ALLOW_THREADS; |
| 3354 | return r; |
| 3355 | } |
| 3356 | |
| 3357 | /* |
| 3358 | * Create an array by reading from the given stream, using the passed |
no test coverage detected