mirror of
https://github.com/pybind/pybind11.git
synced 2026-03-14 20:27:47 +00:00
fix py::cast<void *> (#1605)
Pybind11 provides a cast operator between opaque void* pointers on the
C++ side and capsules on the Python side. The py::cast<void *>
expression was not aware of this possibility and incorrectly triggered a
compile-time assertion ("Unable to cast type to reference: value is
local to type caster") that is now fixed.
This commit is contained in:
@@ -160,4 +160,11 @@ TEST_SUBMODULE(builtin_casters, m) {
|
||||
m.def("int_cast", []() {return (int) 42;});
|
||||
m.def("long_cast", []() {return (long) 42;});
|
||||
m.def("longlong_cast", []() {return ULLONG_MAX;});
|
||||
|
||||
/// test void* cast operator
|
||||
m.def("test_void_caster", []() -> bool {
|
||||
void *v = (void *) 0xabcd;
|
||||
py::object o = py::cast(v);
|
||||
return py::cast<void *>(o) == v;
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user