Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
gaoqiong
pybind11
Commits
adc2cdd5
Unverified
Commit
adc2cdd5
authored
Nov 09, 2018
by
Wenzel Jakob
Committed by
GitHub
Nov 09, 2018
Browse files
fixed regression in STL type caster RVPs (fixes #1561) (#1603)
parent
9f73060c
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
34 additions
and
6 deletions
+34
-6
.appveyor.yml
.appveyor.yml
+1
-0
include/pybind11/cast.h
include/pybind11/cast.h
+3
-2
include/pybind11/stl.h
include/pybind11/stl.h
+10
-4
tests/test_stl.cpp
tests/test_stl.cpp
+12
-0
tests/test_stl.py
tests/test_stl.py
+8
-0
No files found.
.appveyor.yml
View file @
adc2cdd5
...
@@ -3,6 +3,7 @@ image:
...
@@ -3,6 +3,7 @@ image:
-
Visual Studio
2017
-
Visual Studio
2017
-
Visual Studio
2015
-
Visual Studio
2015
test
:
off
test
:
off
skip_branch_with_pr
:
true
build
:
build
:
parallel
:
true
parallel
:
true
platform
:
platform
:
...
...
include/pybind11/cast.h
View file @
adc2cdd5
...
@@ -1614,8 +1614,9 @@ template <typename Return, typename SFINAE = void> struct return_value_policy_ov
...
@@ -1614,8 +1614,9 @@ template <typename Return, typename SFINAE = void> struct return_value_policy_ov
template
<
typename
Return
>
struct
return_value_policy_override
<
Return
,
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
>>
{
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
)
{
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
&&
?
return_value_policy
::
move
:
p
;
!
std
::
is_pointer
<
Return
>::
value
?
return_value_policy
::
move
:
p
;
}
}
};
};
...
...
include/pybind11/stl.h
View file @
adc2cdd5
...
@@ -83,7 +83,8 @@ template <typename Type, typename Key> struct set_caster {
...
@@ -83,7 +83,8 @@ template <typename Type, typename Key> struct set_caster {
template
<
typename
T
>
template
<
typename
T
>
static
handle
cast
(
T
&&
src
,
return_value_policy
policy
,
handle
parent
)
{
static
handle
cast
(
T
&&
src
,
return_value_policy
policy
,
handle
parent
)
{
policy
=
return_value_policy_override
<
Key
>::
policy
(
policy
);
if
(
!
std
::
is_lvalue_reference
<
T
>::
value
)
policy
=
return_value_policy_override
<
Key
>::
policy
(
policy
);
pybind11
::
set
s
;
pybind11
::
set
s
;
for
(
auto
&&
value
:
src
)
{
for
(
auto
&&
value
:
src
)
{
auto
value_
=
reinterpret_steal
<
object
>
(
key_conv
::
cast
(
forward_like
<
T
>
(
value
),
policy
,
parent
));
auto
value_
=
reinterpret_steal
<
object
>
(
key_conv
::
cast
(
forward_like
<
T
>
(
value
),
policy
,
parent
));
...
@@ -119,8 +120,12 @@ template <typename Type, typename Key, typename Value> struct map_caster {
...
@@ -119,8 +120,12 @@ template <typename Type, typename Key, typename Value> struct map_caster {
template
<
typename
T
>
template
<
typename
T
>
static
handle
cast
(
T
&&
src
,
return_value_policy
policy
,
handle
parent
)
{
static
handle
cast
(
T
&&
src
,
return_value_policy
policy
,
handle
parent
)
{
dict
d
;
dict
d
;
return_value_policy
policy_key
=
return_value_policy_override
<
Key
>::
policy
(
policy
);
return_value_policy
policy_key
=
policy
;
return_value_policy
policy_value
=
return_value_policy_override
<
Value
>::
policy
(
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
)
{
for
(
auto
&&
kv
:
src
)
{
auto
key
=
reinterpret_steal
<
object
>
(
key_conv
::
cast
(
forward_like
<
T
>
(
kv
.
first
),
policy_key
,
parent
));
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
));
auto
value
=
reinterpret_steal
<
object
>
(
value_conv
::
cast
(
forward_like
<
T
>
(
kv
.
second
),
policy_value
,
parent
));
...
@@ -161,7 +166,8 @@ private:
...
@@ -161,7 +166,8 @@ private:
public:
public:
template
<
typename
T
>
template
<
typename
T
>
static
handle
cast
(
T
&&
src
,
return_value_policy
policy
,
handle
parent
)
{
static
handle
cast
(
T
&&
src
,
return_value_policy
policy
,
handle
parent
)
{
policy
=
return_value_policy_override
<
Value
>::
policy
(
policy
);
if
(
!
std
::
is_lvalue_reference
<
T
>::
value
)
policy
=
return_value_policy_override
<
Value
>::
policy
(
policy
);
list
l
(
src
.
size
());
list
l
(
src
.
size
());
size_t
index
=
0
;
size_t
index
=
0
;
for
(
auto
&&
value
:
src
)
{
for
(
auto
&&
value
:
src
)
{
...
...
tests/test_stl.cpp
View file @
adc2cdd5
...
@@ -265,4 +265,16 @@ TEST_SUBMODULE(stl, m) {
...
@@ -265,4 +265,16 @@ TEST_SUBMODULE(stl, m) {
py
::
return_value_policy
::
take_ownership
);
py
::
return_value_policy
::
take_ownership
);
m
.
def
(
"array_cast_sequence"
,
[](
std
::
array
<
int
,
3
>
x
)
{
return
x
;
});
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():
...
@@ -220,3 +220,11 @@ def test_stl_ownership():
def
test_array_cast_sequence
():
def
test_array_cast_sequence
():
assert
m
.
array_cast_sequence
((
1
,
2
,
3
))
==
[
1
,
2
,
3
]
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