| 651 | } |
| 652 | |
| 653 | void ndarray_dec_ref(ndarray_handle* th) noexcept |
| 654 | { |
| 655 | if (!th) |
| 656 | return; |
| 657 | size_t rc_value = th->refcount--; |
| 658 | |
| 659 | if (rc_value == 0) |
| 660 | { |
| 661 | pybind11_fail("ndarray_dec_ref(): reference count became negative!"); |
| 662 | } |
| 663 | else if (rc_value == 1) |
| 664 | { |
| 665 | Py_XDECREF(th->owner); |
| 666 | managed_dltensor* mt = th->ndarray; |
| 667 | if (th->free_shape) |
| 668 | { |
| 669 | PyMem_Free(mt->dltensor.shape); |
| 670 | mt->dltensor.shape = nullptr; |
| 671 | } |
| 672 | if (th->free_strides) |
| 673 | { |
| 674 | PyMem_Free(mt->dltensor.strides); |
| 675 | mt->dltensor.strides = nullptr; |
| 676 | } |
| 677 | if (th->call_deleter) |
| 678 | { |
| 679 | if (mt->deleter) |
| 680 | mt->deleter(mt); |
| 681 | } |
| 682 | else |
| 683 | { |
| 684 | PyMem_Free(mt); |
| 685 | } |
| 686 | PyMem_Free(th); |
| 687 | } |
| 688 | } |
| 689 | |
| 690 | ndarray_handle* ndarray_create( |
| 691 | void* value, |
no outgoing calls
no test coverage detected