MCPcopy Create free account
hub / github.com/pybind/pybind11 / initialize_inherited_virtuals

Function initialize_inherited_virtuals

tests/test_virtual_functions.cpp:560–591  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

558*/
559
560void initialize_inherited_virtuals(py::module_ &m) {
561 // test_inherited_virtuals
562
563 // Method 1: repeat
564 py::class_<A_Repeat, PyA_Repeat>(m, "A_Repeat")
565 .def(py::init<>())
566 .def("unlucky_number", &A_Repeat::unlucky_number)
567 .def("say_something", &A_Repeat::say_something)
568 .def("say_everything", &A_Repeat::say_everything);
569 py::class_<B_Repeat, A_Repeat, PyB_Repeat>(m, "B_Repeat")
570 .def(py::init<>())
571 .def("lucky_number", &B_Repeat::lucky_number);
572 py::class_<C_Repeat, B_Repeat, PyC_Repeat>(m, "C_Repeat").def(py::init<>());
573 py::class_<D_Repeat, C_Repeat, PyD_Repeat>(m, "D_Repeat").def(py::init<>());
574
575 // test_
576 // Method 2: Templated trampolines
577 py::class_<A_Tpl, PyA_Tpl<>>(m, "A_Tpl")
578 .def(py::init<>())
579 .def("unlucky_number", &A_Tpl::unlucky_number)
580 .def("say_something", &A_Tpl::say_something)
581 .def("say_everything", &A_Tpl::say_everything);
582 py::class_<B_Tpl, A_Tpl, PyB_Tpl<>>(m, "B_Tpl")
583 .def(py::init<>())
584 .def("lucky_number", &B_Tpl::lucky_number);
585 py::class_<C_Tpl, B_Tpl, PyB_Tpl<C_Tpl>>(m, "C_Tpl").def(py::init<>());
586 py::class_<D_Tpl, C_Tpl, PyB_Tpl<D_Tpl>>(m, "D_Tpl").def(py::init<>());
587
588 // Fix issue #1454 (crash when acquiring/releasing GIL on another thread in Python 2.7)
589 m.def("test_gil", &test_gil);
590 m.def("test_gil_from_thread", &test_gil_from_thread);
591}

Callers 1

TEST_SUBMODULEFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected