| 38 | namespace py { |
| 39 | |
| 40 | NumPyBuffer::NumPyBuffer(PyObject* ao) : Buffer(nullptr, 0) { |
| 41 | PyAcquireGIL lock; |
| 42 | arr_ = ao; |
| 43 | Py_INCREF(ao); |
| 44 | |
| 45 | if (PyArray_Check(ao)) { |
| 46 | PyArrayObject* ndarray = reinterpret_cast<PyArrayObject*>(ao); |
| 47 | auto ptr = reinterpret_cast<uint8_t*>(PyArray_DATA(ndarray)); |
| 48 | data_ = const_cast<const uint8_t*>(ptr); |
| 49 | size_ = PyArray_NBYTES(ndarray); |
| 50 | capacity_ = size_; |
| 51 | is_mutable_ = !!(PyArray_FLAGS(ndarray) & NPY_ARRAY_WRITEABLE); |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | NumPyBuffer::~NumPyBuffer() { |
| 56 | // GH-38626: destructor may be called after the Python interpreter is finalized. |
nothing calls this directly
no outgoing calls
no test coverage detected