wjakob / nanobind

nanobind: tiny and efficient C++/Python bindings
BSD 3-Clause "New" or "Revised" License
2.29k stars 191 forks source link

Add nb::bytes::data() accessor #584

Closed nurpax closed 4 months ago

nurpax commented 4 months ago

Add nb::bytes::data() accessor as discussed in https://github.com/wjakob/nanobind/discussions/569#discussioncomment-9420765

Note: I couldn't get the tests to build on Windows due to this error:

C:\Users\janne\dev\nanobind\src\nb_internals.h(22,1): fatal error C1189: #error:  nanobind depends on tsl::robin_map, i
n particular version >= 1.3.0, <2.0.0 [C:\Users\janne\dev\nanobind\build\tests\nanobind-mydomain.vcxproj]
  Generating Code...

So trying if I can get test this with CI.

wjakob commented 4 months ago

Can you replace test_functions_ext.pyi.ref with your generated test_functions_ext.pyi? If you get the robin_map error message locally, you probably need to update your subrepository.

nurpax commented 4 months ago

Ahh, of course, that was it. All those years using git yet zero success in committing git submodules into CLI muscle memory.

If the change looks otherwise ok, I can add another commit for docs too.

wjakob commented 4 months ago

The change looks good, please go ahead.

nurpax commented 4 months ago

Added docs. Also updated the docs for nb::bytes(const void * buf, size_t n) constructor to match the actual code.

Hopefully the rst syntax is not too wrong in my change.

wjakob commented 4 months ago

Looks all good, thanks!