NUMPY_API * * If WRITEBACKIFCOPY and self has data, reset the base WRITEABLE flag, * copy the local data to base, release the local data, and set flags * appropriately. Return 0 if not relevant, 1 if success, < 0 on failure */
| 360 | * appropriately. Return 0 if not relevant, 1 if success, < 0 on failure |
| 361 | */ |
| 362 | NPY_NO_EXPORT int |
| 363 | PyArray_ResolveWritebackIfCopy(PyArrayObject * self) |
| 364 | { |
| 365 | PyArrayObject_fields *fa = (PyArrayObject_fields *)self; |
| 366 | if (fa && fa->base) { |
| 367 | if (fa->flags & NPY_ARRAY_WRITEBACKIFCOPY) { |
| 368 | /* |
| 369 | * WRITEBACKIFCOPY means that fa->base's data |
| 370 | * should be updated with the contents |
| 371 | * of self. |
| 372 | * fa->base->flags is not WRITEABLE to protect the relationship |
| 373 | * unlock it. |
| 374 | */ |
| 375 | int retval = 0; |
| 376 | PyArray_ENABLEFLAGS(((PyArrayObject *)fa->base), |
| 377 | NPY_ARRAY_WRITEABLE); |
| 378 | PyArray_CLEARFLAGS(self, NPY_ARRAY_WRITEBACKIFCOPY); |
| 379 | retval = PyArray_CopyAnyInto((PyArrayObject *)fa->base, self); |
| 380 | Py_DECREF(fa->base); |
| 381 | fa->base = NULL; |
| 382 | if (retval < 0) { |
| 383 | /* this should never happen, how did the two copies of data |
| 384 | * get out of sync? |
| 385 | */ |
| 386 | return retval; |
| 387 | } |
| 388 | return 1; |
| 389 | } |
| 390 | } |
| 391 | return 0; |
| 392 | } |
| 393 | |
| 394 | /*********************** end C-API functions **********************/ |
| 395 |
no test coverage detected