mirror of
https://github.com/RYDE-WORK/pybind11.git
synced 2026-02-05 15:03:18 +08:00
Example of bug in functions returning bool overriden in python
This commit is contained in:
parent
347e6eaf68
commit
9cfa71f411
@ -27,6 +27,7 @@ public:
|
|||||||
return state + value;
|
return state + value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual bool run_bool() = 0;
|
||||||
virtual void pure_virtual() = 0;
|
virtual void pure_virtual() = 0;
|
||||||
private:
|
private:
|
||||||
int state;
|
int state;
|
||||||
@ -47,6 +48,14 @@ public:
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual bool run_bool() {
|
||||||
|
PYBIND11_OVERLOAD_PURE(
|
||||||
|
bool,
|
||||||
|
Example12,
|
||||||
|
run_bool
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
virtual void pure_virtual() {
|
virtual void pure_virtual() {
|
||||||
PYBIND11_OVERLOAD_PURE(
|
PYBIND11_OVERLOAD_PURE(
|
||||||
void, /* Return type */
|
void, /* Return type */
|
||||||
@ -61,6 +70,10 @@ int runExample12(Example12 *ex, int value) {
|
|||||||
return ex->run(value);
|
return ex->run(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool runExample12Bool(Example12* ex) {
|
||||||
|
return ex->run_bool();
|
||||||
|
}
|
||||||
|
|
||||||
void runExample12Virtual(Example12 *ex) {
|
void runExample12Virtual(Example12 *ex) {
|
||||||
ex->pure_virtual();
|
ex->pure_virtual();
|
||||||
}
|
}
|
||||||
@ -75,8 +88,10 @@ void init_ex12(py::module &m) {
|
|||||||
.def(py::init<int>())
|
.def(py::init<int>())
|
||||||
/* Reference original class in function definitions */
|
/* Reference original class in function definitions */
|
||||||
.def("run", &Example12::run)
|
.def("run", &Example12::run)
|
||||||
|
.def("run_bool", &Example12::run_bool)
|
||||||
.def("pure_virtual", &Example12::pure_virtual);
|
.def("pure_virtual", &Example12::pure_virtual);
|
||||||
|
|
||||||
m.def("runExample12", &runExample12);
|
m.def("runExample12", &runExample12);
|
||||||
|
m.def("runExample12Bool", &runExample12Bool);
|
||||||
m.def("runExample12Virtual", &runExample12Virtual);
|
m.def("runExample12Virtual", &runExample12Virtual);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,7 +3,7 @@ from __future__ import print_function
|
|||||||
import sys
|
import sys
|
||||||
sys.path.append('.')
|
sys.path.append('.')
|
||||||
|
|
||||||
from example import Example12, runExample12, runExample12Virtual
|
from example import Example12, runExample12, runExample12Virtual, runExample12Bool
|
||||||
|
|
||||||
|
|
||||||
class ExtendedExample12(Example12):
|
class ExtendedExample12(Example12):
|
||||||
@ -15,6 +15,10 @@ class ExtendedExample12(Example12):
|
|||||||
print('ExtendedExample12::run(%i), calling parent..' % value)
|
print('ExtendedExample12::run(%i), calling parent..' % value)
|
||||||
return super(ExtendedExample12, self).run(value + 1)
|
return super(ExtendedExample12, self).run(value + 1)
|
||||||
|
|
||||||
|
def run_bool(self):
|
||||||
|
print('ExtendedExample12::run_bool()')
|
||||||
|
return False
|
||||||
|
|
||||||
def pure_virtual(self):
|
def pure_virtual(self):
|
||||||
print('ExtendedExample12::pure_virtual(): %s' % self.data)
|
print('ExtendedExample12::pure_virtual(): %s' % self.data)
|
||||||
|
|
||||||
@ -28,4 +32,5 @@ except Exception as e:
|
|||||||
|
|
||||||
ex12p = ExtendedExample12(10)
|
ex12p = ExtendedExample12(10)
|
||||||
print(runExample12(ex12p, 20))
|
print(runExample12(ex12p, 20))
|
||||||
|
print(runExample12Bool(ex12p))
|
||||||
runExample12Virtual(ex12p)
|
runExample12Virtual(ex12p)
|
||||||
|
|||||||
@ -6,6 +6,8 @@ Constructing Example12..
|
|||||||
ExtendedExample12::run(20), calling parent..
|
ExtendedExample12::run(20), calling parent..
|
||||||
Original implementation of Example12::run(state=11, value=21)
|
Original implementation of Example12::run(state=11, value=21)
|
||||||
32
|
32
|
||||||
|
ExtendedExample12::run_bool()
|
||||||
|
False
|
||||||
ExtendedExample12::pure_virtual(): Hello world
|
ExtendedExample12::pure_virtual(): Hello world
|
||||||
Destructing Example12..
|
Destructing Example12..
|
||||||
Destructing Example12..
|
Destructing Example12..
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user