external_module.cpp 554 B

123456789101112131415161718192021222324
  1. #include <pybind11/pybind11.h>
  2. namespace py = pybind11;
  3. /* Simple test module/test class to check that the referenced internals data of external pybind11
  4. * modules aren't preserved over a finalize/initialize.
  5. */
  6. PYBIND11_MODULE(external_module, m) {
  7. class A {
  8. public:
  9. A(int value) : v{value} {};
  10. int v;
  11. };
  12. py::class_<A>(m, "A")
  13. .def(py::init<int>())
  14. .def_readwrite("value", &A::v);
  15. m.def("internals_at", []() {
  16. return reinterpret_cast<uintptr_t>(&py::detail::get_internals());
  17. });
  18. }