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