aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomi Valkeinen2017-11-24 02:51:31 -0600
committerTomi Valkeinen2017-11-24 02:51:31 -0600
commitc13047e3f7674a5a05b107ef3fd97d9ff4165639 (patch)
tree161d1e36c62809810407d4f4b54bf65152443142
parent650fb54ae66cb43f939034771f85d6afab86f1fb (diff)
downloadexternal-kmsxx-c13047e3f7674a5a05b107ef3fd97d9ff4165639.tar.gz
external-kmsxx-c13047e3f7674a5a05b107ef3fd97d9ff4165639.tar.xz
external-kmsxx-c13047e3f7674a5a05b107ef3fd97d9ff4165639.zip
pykms: keep Card alive until Blob is gone
-rw-r--r--py/pykms/pykmsbase.cpp12
1 files changed, 7 insertions, 5 deletions
diff --git a/py/pykms/pykmsbase.cpp b/py/pykms/pykmsbase.cpp
index aae5ece..96ebe7a 100644
--- a/py/pykms/pykmsbase.cpp
+++ b/py/pykms/pykmsbase.cpp
@@ -105,12 +105,14 @@ void init_pykmsbase(py::module &m)
105 105
106 py::class_<Blob>(m, "Blob") 106 py::class_<Blob>(m, "Blob")
107 .def("__init__", [](Blob& instance, Card& card, py::buffer buf) { 107 .def("__init__", [](Blob& instance, Card& card, py::buffer buf) {
108 py::buffer_info info = buf.request(); 108 py::buffer_info info = buf.request();
109 if (info.ndim != 1) 109 if (info.ndim != 1)
110 throw std::runtime_error("Incompatible buffer dimension!"); 110 throw std::runtime_error("Incompatible buffer dimension!");
111
112 new (&instance) Blob(card, info.ptr, info.size * info.itemsize);
113 },
114 py::keep_alive<1, 3>()) // Keep Card alive until this is destructed
111 115
112 new (&instance) Blob(card, info.ptr, info.size * info.itemsize);
113 })
114 .def_property_readonly("data", &Blob::data) 116 .def_property_readonly("data", &Blob::data)
115 117
116 // XXX pybind11 doesn't support a base object (DrmObject) with custom holder-type, 118 // XXX pybind11 doesn't support a base object (DrmObject) with custom holder-type,