Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf0f01ae

Browse files
committed
test purpose,revert please
1 parent5d61911 commitf0f01ae

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

‎bindings/support/BlockCache.cpp‎

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,32 @@ py::class_<BBlockCache>(m, "BBlockCache")
3636
.def(py::init<uint32,size_t, uint32>(),"",py::arg("blockCount"),py::arg("blockSize"),py::arg("allocationType"))
3737
//.def("Get", &BBlockCache::Get, "", py::arg("blockSize"))//TODO this returns a void * -- let's return a py::bytes or a py::buffer
3838
.def("Get", &Get_wrapper2,"",py::arg("blockSize"))
39-
.def("Save", &BBlockCache::Save,"",py::arg("pointer"),py::arg("blockSize"))//TODO: pointer is a void * -> python can't use void *
39+
.def("Get2", [](BBlockCache& self,size_t blockSize)->py::tuple{
40+
std::vector<char>buffer(blockSize);
41+
void* data = self.Get(blockSize);
42+
if (data !=nullptr) {
43+
std::memcpy(buffer.data(), data, blockSize);
44+
}
45+
py::bytespyBytes(buffer.data(),blockSize);
46+
returnpy::make_tuple(pyBytes, blockSize);
47+
},"",py::arg("blockSize"))
48+
//.def("Save", &BBlockCache::Save, "", py::arg("pointer"), py::arg("blockSize"))//TODO: pointer is a void * -> python can't use void *
49+
.def("Save", [](BBlockCache& self, py::bytes data) {//if we pass a py::bytes we already pass the size along with data right?
50+
/*std::string byt = py::str(data);
51+
void* pointer = static_cast<void*>(const_cast<char*>(byt.data()));
52+
self.Save(pointer, byt.size());*/
53+
char* pointer;
54+
ssize_t size;
55+
PYBIND11_BYTES_AS_STRING_AND_SIZE(data.ptr(), &pointer, &size);
56+
self.Save(static_cast<void*>(pointer),static_cast<size_t>(size));
57+
},"",py::arg("data"))
58+
.def("Save_from_buffer", [](BBlockCache& self, py::buffer py_buffer){
59+
py::buffer_info buf_info = py_buffer.request();
60+
void* pointer = buf_info.ptr;
61+
//size_t blockSize = buf_info.size * buf_info.itemsize;
62+
size_t blockSize = buf_info.size;
63+
self.Save(pointer, blockSize);
64+
},"",py::arg("py_buffer"))
4065
;
4166

4267

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp