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
3d80ad57
Commit
3d80ad57
authored
Dec 03, 2020
by
Ralf W. Grosse-Kunstleve
Browse files
github current snapshot
parent
028812ae
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
11 additions
and
1 deletion
+11
-1
include/pybind11/stl.h
include/pybind11/stl.h
+1
-1
tests/test_stl.cpp
tests/test_stl.cpp
+3
-0
tests/test_stl.py
tests/test_stl.py
+7
-0
No files found.
include/pybind11/stl.h
View file @
3d80ad57
...
@@ -144,7 +144,7 @@ template <typename Type, typename Value> struct list_caster {
...
@@ -144,7 +144,7 @@ template <typename Type, typename Value> struct list_caster {
using
value_conv
=
make_caster
<
Value
>
;
using
value_conv
=
make_caster
<
Value
>
;
bool
load
(
handle
src
,
bool
convert
)
{
bool
load
(
handle
src
,
bool
convert
)
{
if
(
!
isinstance
<
sequence
>
(
src
)
||
isinstance
<
str
>
(
src
))
if
(
!
isinstance
<
sequence
>
(
src
)
||
(
!
isinstance
<
bytes
>
(
src
)
&&
isinstance
<
str
>
(
src
))
)
return
false
;
return
false
;
auto
s
=
reinterpret_borrow
<
sequence
>
(
src
);
auto
s
=
reinterpret_borrow
<
sequence
>
(
src
);
value
.
clear
();
value
.
clear
();
...
...
tests/test_stl.cpp
View file @
3d80ad57
...
@@ -291,6 +291,9 @@ TEST_SUBMODULE(stl, m) {
...
@@ -291,6 +291,9 @@ TEST_SUBMODULE(stl, m) {
m
.
def
(
"func_with_string_or_vector_string_arg_overload"
,
[](
std
::
list
<
std
::
string
>
)
{
return
2
;
});
m
.
def
(
"func_with_string_or_vector_string_arg_overload"
,
[](
std
::
list
<
std
::
string
>
)
{
return
2
;
});
m
.
def
(
"func_with_string_or_vector_string_arg_overload"
,
[](
std
::
string
)
{
return
3
;
});
m
.
def
(
"func_with_string_or_vector_string_arg_overload"
,
[](
std
::
string
)
{
return
3
;
});
// #1807: 2.3.0 regression: <class 'bytes'> is not converted to std::vector<uint8_t> anymore
m
.
def
(
"func_with_vector_uint8_t_arg"
,
[](
std
::
vector
<
uint8_t
>
v
)
{
return
v
.
size
();
});
class
Placeholder
{
class
Placeholder
{
public:
public:
Placeholder
()
{
print_created
(
this
);
}
Placeholder
()
{
print_created
(
this
);
}
...
...
tests/test_stl.py
View file @
3d80ad57
...
@@ -245,6 +245,13 @@ def test_function_with_string_and_vector_string_arg():
...
@@ -245,6 +245,13 @@ def test_function_with_string_and_vector_string_arg():
assert
m
.
func_with_string_or_vector_string_arg_overload
(
"A"
)
==
3
assert
m
.
func_with_string_or_vector_string_arg_overload
(
"A"
)
==
3
def
test_bytes_to_vector_uint8_t
():
"""Check if a bytes is implicitly converted to std::vector<uint8_t>, issue #1807"""
assert
m
.
func_with_vector_uint8_t_arg
(
b
'abc'
)
==
3
with
pytest
.
raises
(
TypeError
):
m
.
func_with_vector_uint8_t_arg
(
'stringval'
)
def
test_stl_ownership
():
def
test_stl_ownership
():
cstats
=
ConstructorStats
.
get
(
m
.
Placeholder
)
cstats
=
ConstructorStats
.
get
(
m
.
Placeholder
)
assert
cstats
.
alive
()
==
0
assert
cstats
.
alive
()
==
0
...
...
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