-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Fix for Issue #1258 #1298
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix for Issue #1258 #1298
Conversation
Looks fine, but can you add a simple test case for this to the PR (i.e. something that goes to the wrong overload when passed a string). |
Could any of you guys help me on making these automated tests pass? This is a just minor change in pybind11 to fix issue #1258. |
@allanleal can you rebase this PR? I appreciate if this is fixed as well for one of my projects :) |
tests/test_stl.py
Outdated
def test_stl_ownership(): | ||
cstats = ConstructorStats.get(m.Placeholder) | ||
assert cstats.alive() == 0 | ||
r = m.test_stl_ownership() | ||
assert len(r) == 1 | ||
del r | ||
assert cstats.alive() == 0 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unnecessary white space change, please remove :)
@allanleal please really rebase this branch, |
@ax3l Could you please take the lead on this? This is a very simple bug fix, yet, for some reason, it does not go though during the CI phase, and I'm not able to fix this right now. Thanks. |
@allanleal I can try :) Can you add me as a collaborator with I am not a pybind11 maintainer and can due to that not push to your branch. |
Thanks, @ax3l - just added you. |
Current status is: "Awaiting ax3l's response". I was given no option -
just the name of the user. Maybe you need to accept it first.
…On 04.09.2018 14:12, Axel Huebl wrote:
@allanleal <https://github.com/allanleal> hm, still can't write? Did
you add "write" access? Otherwise, just create a team that has write
access to your repo and add me there.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1298 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AFjkNN3fw4a3xJ_bacfmmVvL25Oq_Grbks5uXm4pgaJpZM4SS6P5>.
|
I can locally verify the failing test in debug mode. Also, there is a violation of the one definition rule in |
tests/test_stl.cpp
Outdated
@@ -237,6 +237,10 @@ TEST_SUBMODULE(stl, m) { | |||
// test_stl_pass_by_pointer | |||
m.def("stl_pass_by_pointer", [](std::vector<int>* v) { return *v; }, "v"_a=nullptr); | |||
|
|||
// #1258: pybind11/stl.h converts string to vector<string> | |||
m.def("func_with_string_or_vector_string_arg_overload", [](std::vector<std::string>) { return 0; }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this line triggers a ODR warning:
include/pybind11/stl.h:179:49: warning: type ‘struct type_caster’ violates the C++ One Definition Rule [-Wodr]
template <typename Type, typename Alloc> struct type_caster<std::vector<Type, Alloc>>
^
tests/test_opaque_types.cpp:19:1: note: a type with the same name but different base type is defined in another translation unit
PYBIND11_MAKE_OPAQUE(std::vector<std::string, std::allocator<std::string>>);
^
include/pybind11/stl.h:137:49: note: type name ‘pybind11::detail::list_caster<std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >’ should match type name ‘pybind11::detail::type_caster_base<std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >’
template <typename Type, typename Value> struct list_caster {
^
include/pybind11/cast.h:814:32: note: the incompatible type is defined here
template <typename type> class type_caster_base : public type_caster_generic {
^
tests/test_opaque_types.cpp:19:1: note: type ‘struct type_caster’ itself violate the C++ One Definition Rule
PYBIND11_MAKE_OPAQUE(std::vector<std::string, std::allocator<std::string>>);
^
include/pybind11/stl.h:179:49: note: the incompatible type is defined here
template <typename Type, typename Alloc> struct type_caster<std::vector<Type, Alloc>>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably a
PYBIND11_MAKE_OPAQUE(std::vector<std::string, std::allocator<std::string>>);
missing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hm, now both py arrays and py lists are std::list< std::string >( )
...
@allanleal shouldn't the same treatment go to the |
@allanleal yep, sorry I don't know what's off here |
There is an ODR violation happening (you can see the warning in the gcc-7 build) because the |
Thanks a lot, I did not see that. Will fix it and push again. |
Yay, that fixed it! :) |
This looks good to me. @wjakob ? |
Oh, one last request -- can you add a changelog entry for it to |
@jagerman shall I start a |
2.3.0; it seems like more than just a minor .x bug fix. |
@jagerman alright, added the changelog and CI is green :) |
Looks good, thanks! |
Great, thanks!
|
list_caster::load method will now check for a Python string and prevent its automatic conversion to a list.
This should fix the issue "pybind11/stl.h converts string to vector #1258" (#1258)