Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
pybind11
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open
pybind11
Commits
9cfa71f4
Commit
9cfa71f4
authored
Feb 23, 2016
by
jmabille
Committed by
Wenzel Jakob
Feb 23, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Example of bug in functions returning bool overriden in python
parent
347e6eaf
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
1 deletions
+23
-1
example/example12.cpp
+15
-0
example/example12.py
+6
-1
example/example12.ref
+2
-0
No files found.
example/example12.cpp
View file @
9cfa71f4
...
...
@@ -27,6 +27,7 @@ public:
return
state
+
value
;
}
virtual
bool
run_bool
()
=
0
;
virtual
void
pure_virtual
()
=
0
;
private
:
int
state
;
...
...
@@ -47,6 +48,14 @@ public:
);
}
virtual
bool
run_bool
()
{
PYBIND11_OVERLOAD_PURE
(
bool
,
Example12
,
run_bool
);
}
virtual
void
pure_virtual
()
{
PYBIND11_OVERLOAD_PURE
(
void
,
/* Return type */
...
...
@@ -61,6 +70,10 @@ int runExample12(Example12 *ex, int value) {
return
ex
->
run
(
value
);
}
bool
runExample12Bool
(
Example12
*
ex
)
{
return
ex
->
run_bool
();
}
void
runExample12Virtual
(
Example12
*
ex
)
{
ex
->
pure_virtual
();
}
...
...
@@ -75,8 +88,10 @@ void init_ex12(py::module &m) {
.
def
(
py
::
init
<
int
>
())
/* Reference original class in function definitions */
.
def
(
"run"
,
&
Example12
::
run
)
.
def
(
"run_bool"
,
&
Example12
::
run_bool
)
.
def
(
"pure_virtual"
,
&
Example12
::
pure_virtual
);
m
.
def
(
"runExample12"
,
&
runExample12
);
m
.
def
(
"runExample12Bool"
,
&
runExample12Bool
);
m
.
def
(
"runExample12Virtual"
,
&
runExample12Virtual
);
}
example/example12.py
View file @
9cfa71f4
...
...
@@ -3,7 +3,7 @@ from __future__ import print_function
import
sys
sys
.
path
.
append
(
'.'
)
from
example
import
Example12
,
runExample12
,
runExample12Virtual
from
example
import
Example12
,
runExample12
,
runExample12Virtual
,
runExample12Bool
class
ExtendedExample12
(
Example12
):
...
...
@@ -15,6 +15,10 @@ class ExtendedExample12(Example12):
print
(
'ExtendedExample12::run(
%
i), calling parent..'
%
value
)
return
super
(
ExtendedExample12
,
self
)
.
run
(
value
+
1
)
def
run_bool
(
self
):
print
(
'ExtendedExample12::run_bool()'
)
return
False
def
pure_virtual
(
self
):
print
(
'ExtendedExample12::pure_virtual():
%
s'
%
self
.
data
)
...
...
@@ -28,4 +32,5 @@ except Exception as e:
ex12p
=
ExtendedExample12
(
10
)
print
(
runExample12
(
ex12p
,
20
))
print
(
runExample12Bool
(
ex12p
))
runExample12Virtual
(
ex12p
)
example/example12.ref
View file @
9cfa71f4
...
...
@@ -6,6 +6,8 @@ Constructing Example12..
ExtendedExample12::run(20), calling parent..
Original implementation of Example12::run(state=11, value=21)
32
ExtendedExample12::run_bool()
False
ExtendedExample12::pure_virtual(): Hello world
Destructing Example12..
Destructing Example12..
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment