From 514c6dad7065a77f7fc1a0b93c7c4983b8f35fb8 Mon Sep 17 00:00:00 2001 From: Jason Newton Date: Fri, 2 Sep 2016 17:10:25 -0400 Subject: [PATCH] add field for ownership --- include/pybind11/common.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/include/pybind11/common.h b/include/pybind11/common.h index 32e245b46..9e9af98d8 100644 --- a/include/pybind11/common.h +++ b/include/pybind11/common.h @@ -225,9 +225,9 @@ struct buffer_info { : buffer_info(ptr, itemsize, format, 1, std::vector { size }, std::vector { 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), - 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) { shape[i] = (size_t) view->shape[i]; strides[i] = (size_t) view->strides[i]; @@ -236,11 +236,12 @@ struct buffer_info { } ~buffer_info() { - if (view) { PyBuffer_Release(view); delete view; } + if (view && ownview) { PyBuffer_Release(view); delete view; } } private: Py_buffer *view = nullptr; + bool ownview = false; }; NAMESPACE_BEGIN(detail)