-
Notifications
You must be signed in to change notification settings - Fork 24
Carry a copy of the string also in the std::string_view converter and consider statefulness in InitializerListConverter
#14
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
Conversation
137b29e to
975b3c0
Compare
|
The same patch is also now part of my syncing PR in ROOT: edit: indeed, the RDataFrame tutorials pass now |
|
Also: what is the most appropriate place for a unit test? I guess somewhere here? |
A class with a virtual destructor should also define copying and assignment. In the case of the converter class, both should be forbidden. This would have helped me understanding the code if it would have been done before.
975b3c0 to
c97dbf3
Compare
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.
If they have state, a separate converter needs to be created for each
element in the initializer list.
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")
cppyy.gbl.bar(["hello", "world"])
```
c97dbf3 to
8b7145f
Compare
std::string_view converterstd::string_view converter and consider statefulness in InitializerListConverter
|
This one actually breaks two existing The problem is that in |
|
Thank you very much for following up! Sorry, I didn't think of this case. It's more common to use |
There are two possible fixes to the problem with string lifetimes and
std::string_viewarguments: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).
Also, the
InitializerListConverteris changed such that it creates separate converters for each element if the converters have state.This PR fixes the following reproducer:
Closes #13.