mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-22 21:25:13 +00:00
add field for ownership
This commit is contained in:
parent
3718c38e68
commit
514c6dad70
@ -225,9 +225,9 @@ struct buffer_info {
|
|||||||
: buffer_info(ptr, itemsize, format, 1, std::vector<size_t> { size },
|
: buffer_info(ptr, itemsize, format, 1, std::vector<size_t> { size },
|
||||||
std::vector<size_t> { itemsize }) { }
|
std::vector<size_t> { itemsize }) { }
|
||||||
|
|
||||||
buffer_info(Py_buffer *view)
|
buffer_info(Py_buffer *view, bool ownview = true)
|
||||||
: ptr(view->buf), itemsize((size_t) view->itemsize), size(1), format(view->format),
|
: ptr(view->buf), itemsize((size_t) view->itemsize), size(1), format(view->format),
|
||||||
ndim((size_t) view->ndim), shape((size_t) view->ndim), strides((size_t) view->ndim), view(view) {
|
ndim((size_t) view->ndim), shape((size_t) view->ndim), strides((size_t) view->ndim), view(view), ownview(ownview) {
|
||||||
for (size_t i = 0; i < (size_t) view->ndim; ++i) {
|
for (size_t i = 0; i < (size_t) view->ndim; ++i) {
|
||||||
shape[i] = (size_t) view->shape[i];
|
shape[i] = (size_t) view->shape[i];
|
||||||
strides[i] = (size_t) view->strides[i];
|
strides[i] = (size_t) view->strides[i];
|
||||||
@ -236,11 +236,12 @@ struct buffer_info {
|
|||||||
}
|
}
|
||||||
|
|
||||||
~buffer_info() {
|
~buffer_info() {
|
||||||
if (view) { PyBuffer_Release(view); delete view; }
|
if (view && ownview) { PyBuffer_Release(view); delete view; }
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Py_buffer *view = nullptr;
|
Py_buffer *view = nullptr;
|
||||||
|
bool ownview = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
NAMESPACE_BEGIN(detail)
|
NAMESPACE_BEGIN(detail)
|
||||||
|
Loading…
Reference in New Issue
Block a user