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
c84b37b5
Commit
c84b37b5
authored
Sep 07, 2016
by
Wenzel Jakob
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix bogus return value policy fallbacks (fixes #389)
parent
a3dbdc67
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
3 deletions
+32
-3
include/pybind11/cast.h
+5
-3
tests/test_issues.cpp
+19
-0
tests/test_issues.py
+8
-0
No files found.
include/pybind11/cast.h
View file @
c84b37b5
...
@@ -220,14 +220,16 @@ public:
...
@@ -220,14 +220,16 @@ public:
policy
=
return_value_policy
::
reference
;
policy
=
return_value_policy
::
reference
;
if
(
policy
==
return_value_policy
::
copy
)
{
if
(
policy
==
return_value_policy
::
copy
)
{
if
(
copy_constructor
)
wrapper
->
value
=
copy_constructor
(
wrapper
->
value
);
wrapper
->
value
=
copy_constructor
(
wrapper
->
value
);
if
(
wrapper
->
value
==
nullptr
)
else
throw
cast_error
(
"return_value_policy = copy, but the object is non-copyable!"
);
throw
cast_error
(
"return_value_policy = copy, but the object is non-copyable!"
);
}
else
if
(
policy
==
return_value_policy
::
move
)
{
}
else
if
(
policy
==
return_value_policy
::
move
)
{
if
(
move_constructor
)
wrapper
->
value
=
move_constructor
(
wrapper
->
value
);
wrapper
->
value
=
move_constructor
(
wrapper
->
value
);
if
(
wrapper
->
value
==
nullpt
r
)
else
if
(
copy_constructo
r
)
wrapper
->
value
=
copy_constructor
(
wrapper
->
value
);
wrapper
->
value
=
copy_constructor
(
wrapper
->
value
);
if
(
wrapper
->
value
==
nullptr
)
else
throw
cast_error
(
"return_value_policy = move, but the object is neither movable nor copyable!"
);
throw
cast_error
(
"return_value_policy = move, but the object is neither movable nor copyable!"
);
}
else
if
(
policy
==
return_value_policy
::
reference
)
{
}
else
if
(
policy
==
return_value_policy
::
reference
)
{
wrapper
->
owned
=
false
;
wrapper
->
owned
=
false
;
...
...
tests/test_issues.cpp
View file @
c84b37b5
...
@@ -172,6 +172,25 @@ void init_issues(py::module &m) {
...
@@ -172,6 +172,25 @@ void init_issues(py::module &m) {
m2
.
def
(
"get_NestA"
,
[](
const
NestA
&
a
)
{
return
a
.
value
;
});
m2
.
def
(
"get_NestA"
,
[](
const
NestA
&
a
)
{
return
a
.
value
;
});
m2
.
def
(
"get_NestB"
,
[](
const
NestB
&
b
)
{
return
b
.
value
;
});
m2
.
def
(
"get_NestB"
,
[](
const
NestB
&
b
)
{
return
b
.
value
;
});
m2
.
def
(
"get_NestC"
,
[](
const
NestC
&
c
)
{
return
c
.
value
;
});
m2
.
def
(
"get_NestC"
,
[](
const
NestC
&
c
)
{
return
c
.
value
;
});
// Issue 389: r_v_p::move should fall-through to copy on non-movable objects
class
MoveIssue1
{
public:
MoveIssue1
(
int
v
)
:
v
{
v
}
{}
MoveIssue1
(
const
MoveIssue1
&
c
)
{
std
::
cerr
<<
"copy ctor
\n
"
;
v
=
c
.
v
;
}
MoveIssue1
(
MoveIssue1
&&
)
=
delete
;
int
v
;
};
class
MoveIssue2
{
public:
MoveIssue2
(
int
v
)
:
v
{
v
}
{}
MoveIssue2
(
MoveIssue2
&&
)
=
default
;
int
v
;
};
py
::
class_
<
MoveIssue1
>
(
m2
,
"MoveIssue1"
).
def
(
py
::
init
<
int
>
()).
def_readwrite
(
"value"
,
&
MoveIssue1
::
v
);
py
::
class_
<
MoveIssue2
>
(
m2
,
"MoveIssue2"
).
def
(
py
::
init
<
int
>
()).
def_readwrite
(
"value"
,
&
MoveIssue2
::
v
);
m2
.
def
(
"get_moveissue1"
,
[](
int
i
)
->
MoveIssue1
*
{
return
new
MoveIssue1
(
i
);
},
py
::
return_value_policy
::
move
);
m2
.
def
(
"get_moveissue2"
,
[](
int
i
)
{
return
MoveIssue2
(
i
);
},
py
::
return_value_policy
::
move
);
}
}
// MSVC workaround: trying to use a lambda here crashes MSCV
// MSVC workaround: trying to use a lambda here crashes MSCV
...
...
tests/test_issues.py
View file @
c84b37b5
...
@@ -158,3 +158,11 @@ def test_nested():
...
@@ -158,3 +158,11 @@ def test_nested():
assert
abase
.
value
==
42
assert
abase
.
value
==
42
del
abase
,
b
del
abase
,
b
gc
.
collect
()
gc
.
collect
()
def
test_move_fallback
():
from
pybind11_tests.issues
import
get_moveissue1
,
get_moveissue2
m2
=
get_moveissue2
(
2
)
assert
m2
.
value
==
2
m1
=
get_moveissue1
(
1
)
assert
m1
.
value
==
1
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