-
Notifications
You must be signed in to change notification settings - Fork 20
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
Wrong passing of arguments when function takes multiple args of type string_view
#13
Comments
The problem is here: https://github.com/wlav/CPyCppyy/blob/master/src/Converters.cxx#L1821 Contrary to the other string classes, using an |
Note that the simpler option of adding an |
There are two possible fixes to the problem with string lifetimes and `std::string_view` arguments: * setting a lifeline * copying the string Copying the string is supposedly faster on average, at least in the ROOT usecase the strings that are passed around are not very long (RDataFrame filter and variable definitions). This commit fixes the following reproducer: ```Python import cppyy cppyy.cppdef(""" void foo(std::string_view s1, std::string_view s2) { std::cout << s1 << std::endl; std::cout << s2 << std::endl; std::cout << std::endl; } void bar(std::initializer_list<std::string_view> sl) { for (auto const& s : sl) { std::cout << s << std::endl; } std::cout << std::endl; } """) cppyy.gbl.foo("hello", "world") ``` Closes wlav#13.
Thank you very much for your comments! I have opened a PR that suggests the copying fix. I will also do the change in the ROOT PR, so it can be tested. |
There are two possible fixes to the problem with string lifetimes and `std::string_view` arguments: * setting a lifeline * copying the string Copying the string is supposedly faster on average, at least in the ROOT usecase the strings that are passed around are not very long (RDataFrame filter and variable definitions). This commit fixes the following reproducer: ```Python import cppyy cppyy.cppdef(""" void foo(std::string_view s1, std::string_view s2) { std::cout << s1 << std::endl; std::cout << s2 << std::endl; std::cout << std::endl; } void bar(std::initializer_list<std::string_view> sl) { for (auto const& s : sl) { std::cout << s << std::endl; } std::cout << std::endl; } """) cppyy.gbl.foo("hello", "world") ``` Closes wlav#13.
There are two possible fixes to the problem with string lifetimes and `std::string_view` arguments: * setting a lifeline * copying the string Copying the string is supposedly faster on average, at least in the ROOT usecase the strings that are passed around are not very long (RDataFrame filter and variable definitions). This commit fixes the following reproducer: ```Python import cppyy cppyy.cppdef(""" void foo(std::string_view s1, std::string_view s2) { std::cout << s1 << std::endl; std::cout << s2 << std::endl; std::cout << std::endl; } void bar(std::initializer_list<std::string_view> sl) { for (auto const& s : sl) { std::cout << s << std::endl; } std::cout << std::endl; } """) cppyy.gbl.foo("hello", "world") ``` Closes wlav#13.
There are two possible fixes to the problem with string lifetimes and `std::string_view` arguments: * setting a lifeline * copying the string Copying the string is supposedly faster on average, at least in the ROOT usecase the strings that are passed around are not very long (RDataFrame filter and variable definitions). This commit fixes the following reproducer: ```Python import cppyy cppyy.cppdef(""" void foo(std::string_view s1, std::string_view s2) { std::cout << s1 << std::endl; std::cout << s2 << std::endl; std::cout << std::endl; } void bar(std::initializer_list<std::string_view> sl) { for (auto const& s : sl) { std::cout << s << std::endl; } std::cout << std::endl; } """) cppyy.gbl.foo("hello", "world") ``` Closes wlav#13.
There are two possible fixes to the problem with string lifetimes and `std::string_view` arguments: * setting a lifeline * copying the string Copying the string is supposedly faster on average, at least in the ROOT usecase the strings that are passed around are not very long (RDataFrame filter and variable definitions). This commit fixes the following reproducer: ```Python import cppyy cppyy.cppdef(""" void foo(std::string_view s1, std::string_view s2) { std::cout << s1 << std::endl; std::cout << s2 << std::endl; std::cout << std::endl; } void bar(std::initializer_list<std::string_view> sl) { for (auto const& s : sl) { std::cout << s << std::endl; } std::cout << std::endl; } """) cppyy.gbl.foo("hello", "world") ``` Closes wlav#13.
The reproducer regressed with fce87d5. |
Fixed again; different method: doesn't use a buffer in the converter. |
Reproducer:
Output:
I opened this in the CPyCppyy repo, because I first observed this problem when trying to use the new CPyCppyy in PyROOT:
root-project/root#14507
The text was updated successfully, but these errors were encountered: