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
adc2cdd5
Unverified
Commit
adc2cdd5
authored
Nov 09, 2018
by
Wenzel Jakob
Committed by
GitHub
Nov 09, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed regression in STL type caster RVPs (fixes #1561) (#1603)
parent
9f73060c
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
31 additions
and
3 deletions
+31
-3
.appveyor.yml
+1
-0
include/pybind11/cast.h
+2
-1
include/pybind11/stl.h
+8
-2
tests/test_stl.cpp
+12
-0
tests/test_stl.py
+8
-0
No files found.
.appveyor.yml
View file @
adc2cdd5
...
...
@@ -3,6 +3,7 @@ image:
-
Visual Studio 2017
-
Visual Studio 2015
test
:
off
skip_branch_with_pr
:
true
build
:
parallel
:
true
platform
:
...
...
include/pybind11/cast.h
View file @
adc2cdd5
...
...
@@ -1614,7 +1614,8 @@ template <typename Return, typename SFINAE = void> struct return_value_policy_ov
template
<
typename
Return
>
struct
return_value_policy_override
<
Return
,
detail
::
enable_if_t
<
std
::
is_base_of
<
type_caster_generic
,
make_caster
<
Return
>>::
value
,
void
>>
{
static
return_value_policy
policy
(
return_value_policy
p
)
{
return
!
std
::
is_lvalue_reference
<
Return
>::
value
&&
!
std
::
is_pointer
<
Return
>::
value
return
!
std
::
is_lvalue_reference
<
Return
>::
value
&&
!
std
::
is_pointer
<
Return
>::
value
?
return_value_policy
::
move
:
p
;
}
};
...
...
include/pybind11/stl.h
View file @
adc2cdd5
...
...
@@ -83,6 +83,7 @@ template <typename Type, typename Key> struct set_caster {
template
<
typename
T
>
static
handle
cast
(
T
&&
src
,
return_value_policy
policy
,
handle
parent
)
{
if
(
!
std
::
is_lvalue_reference
<
T
>::
value
)
policy
=
return_value_policy_override
<
Key
>::
policy
(
policy
);
pybind11
::
set
s
;
for
(
auto
&&
value
:
src
)
{
...
...
@@ -119,8 +120,12 @@ template <typename Type, typename Key, typename Value> struct map_caster {
template
<
typename
T
>
static
handle
cast
(
T
&&
src
,
return_value_policy
policy
,
handle
parent
)
{
dict
d
;
return_value_policy
policy_key
=
return_value_policy_override
<
Key
>::
policy
(
policy
);
return_value_policy
policy_value
=
return_value_policy_override
<
Value
>::
policy
(
policy
);
return_value_policy
policy_key
=
policy
;
return_value_policy
policy_value
=
policy
;
if
(
!
std
::
is_lvalue_reference
<
T
>::
value
)
{
policy_key
=
return_value_policy_override
<
Key
>::
policy
(
policy_key
);
policy_value
=
return_value_policy_override
<
Value
>::
policy
(
policy_value
);
}
for
(
auto
&&
kv
:
src
)
{
auto
key
=
reinterpret_steal
<
object
>
(
key_conv
::
cast
(
forward_like
<
T
>
(
kv
.
first
),
policy_key
,
parent
));
auto
value
=
reinterpret_steal
<
object
>
(
value_conv
::
cast
(
forward_like
<
T
>
(
kv
.
second
),
policy_value
,
parent
));
...
...
@@ -161,6 +166,7 @@ private:
public
:
template
<
typename
T
>
static
handle
cast
(
T
&&
src
,
return_value_policy
policy
,
handle
parent
)
{
if
(
!
std
::
is_lvalue_reference
<
T
>::
value
)
policy
=
return_value_policy_override
<
Value
>::
policy
(
policy
);
list
l
(
src
.
size
());
size_t
index
=
0
;
...
...
tests/test_stl.cpp
View file @
adc2cdd5
...
...
@@ -265,4 +265,16 @@ TEST_SUBMODULE(stl, m) {
py
::
return_value_policy
::
take_ownership
);
m
.
def
(
"array_cast_sequence"
,
[](
std
::
array
<
int
,
3
>
x
)
{
return
x
;
});
/// test_issue_1561
struct
Issue1561Inner
{
std
::
string
data
;
};
struct
Issue1561Outer
{
std
::
vector
<
Issue1561Inner
>
list
;
};
py
::
class_
<
Issue1561Inner
>
(
m
,
"Issue1561Inner"
)
.
def
(
py
::
init
<
std
::
string
>
())
.
def_readwrite
(
"data"
,
&
Issue1561Inner
::
data
);
py
::
class_
<
Issue1561Outer
>
(
m
,
"Issue1561Outer"
)
.
def
(
py
::
init
<>
())
.
def_readwrite
(
"list"
,
&
Issue1561Outer
::
list
);
}
tests/test_stl.py
View file @
adc2cdd5
...
...
@@ -220,3 +220,11 @@ def test_stl_ownership():
def
test_array_cast_sequence
():
assert
m
.
array_cast_sequence
((
1
,
2
,
3
))
==
[
1
,
2
,
3
]
def
test_issue_1561
():
""" check fix for issue #1561 """
bar
=
m
.
Issue1561Outer
()
bar
.
list
=
[
m
.
Issue1561Inner
(
'bar'
)]
bar
.
list
assert
bar
.
list
[
0
]
.
data
==
'bar'
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