You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.2 KiB

  1. /*
  2. example/issues.cpp -- collection of testcases for miscellaneous issues
  3. Copyright (c) 2015 Wenzel Jakob <wenzel@inf.ethz.ch>
  4. All rights reserved. Use of this source code is governed by a
  5. BSD-style license that can be found in the LICENSE file.
  6. */
  7. #include "example.h"
  8. struct Base {
  9. virtual void dispatch(void) const = 0;
  10. };
  11. struct DispatchIssue : Base {
  12. virtual void dispatch(void) const {
  13. PYBIND11_OVERLOAD_PURE(void, Base, dispatch);
  14. }
  15. };
  16. void dispatch_issue_go(const Base * b) { b->dispatch(); }
  17. PYBIND11_PLUGIN(mytest)
  18. {
  19. pybind11::module m("mytest", "A test");
  20. return m.ptr();
  21. }
  22. void init_issues(py::module &m) {
  23. py::module m2 = m.def_submodule("issues");
  24. // #137: const char* isn't handled properly
  25. m2.def("print_cchar", [](const char *string) { std::cout << string << std::endl; });
  26. // #150: char bindings broken
  27. m2.def("print_char", [](char c) { std::cout << c << std::endl; });
  28. // #159: virtual function dispatch has problems with similar-named functions
  29. pybind11::class_<DispatchIssue> base(m2, "DispatchIssue");
  30. base.alias<Base>()
  31. .def(pybind11::init<>())
  32. .def("dispatch", &Base::dispatch);
  33. m2.def("dispatch_issue_go", &dispatch_issue_go);
  34. }