* Helper function to clear a strided memory (normally or always contiguous) * from all Python (or other) references. The function does nothing if the * array dtype does not indicate holding references. * * It is safe to call this function more than once, failing here is usually * critical (during cleanup) and should be set up to minimize the risk or * avoid it fully. */
| 33 | * avoid it fully. |
| 34 | */ |
| 35 | NPY_NO_EXPORT int |
| 36 | PyArray_ClearBuffer( |
| 37 | PyArray_Descr *descr, char *data, |
| 38 | npy_intp stride, npy_intp size, int aligned) |
| 39 | { |
| 40 | if (!PyDataType_REFCHK(descr)) { |
| 41 | return 0; |
| 42 | } |
| 43 | |
| 44 | NPY_traverse_info clear_info; |
| 45 | /* Flags unused: float errors do not matter and we do not release GIL */ |
| 46 | NPY_ARRAYMETHOD_FLAGS flags_unused; |
| 47 | if (PyArray_GetClearFunction( |
| 48 | aligned, stride, descr, &clear_info, &flags_unused) < 0) { |
| 49 | return -1; |
| 50 | } |
| 51 | |
| 52 | int res = clear_info.func( |
| 53 | NULL, clear_info.descr, data, size, stride, clear_info.auxdata); |
| 54 | NPY_traverse_info_xfree(&clear_info); |
| 55 | return res; |
| 56 | } |
| 57 | |
| 58 | |
| 59 | /* |
no test coverage detected