[PyROOT] Fix std::vector<char> iteration#9708
Conversation
As part of the implementation of std.vector.__iter__, the vector's data() method is called. In the case of a vector<char>, data() returns a char*, which is converted by cppyy to a Python string. The issue is that the conversion char*->str expects that the sequence of characters to convert is null-terminated, e.g. in Python3 the following function is used for the conversion: https://docs.python.org/3/c-api/unicode.html#c.PyUnicode_FromString In the case of the data pointed by the char* returned by data(), there is no guarantee that the sequence of characters will be null-terminated, and this results in unpredictable and erroneous behaviour. The fix of this commit adds a pythonization for vector<char>::data() that temporarily adds a null character to the vector before calling the actual data(), so that the conversion is done correctly and the returned Python string contains the characters of the vector. This also fixes the vector<char> iteration, which relies on data().
|
Starting build on |
|
Build failed on ROOT-ubuntu16/nortcxxmod. Failing tests: |
eguiraud
left a comment
There was a problem hiding this comment.
I'm worried this might have unexpected consequences on performance and behavior, but after discussion with Enric and due to my lack of better ideas... :)
|
To leave here some details of the discussion: the use of |
Fixes #9632 (see the text of the first commit for more details).