Skip to content

Use different wrapping for const char vs non-const char

David Gobbi requested to merge dgobbi/vtk:wrap-const-char into master

This change is needed in order for VTK to compile with Python 3.7, since in Python 3.7 the PyUnicode_AsUTF8() method was changed so that it returns "const char *" instead of returning "char *". Another possible (ugly) fix would be to simply add a const_cast.

Previously, the contents of a Python 'str' would be passed directly to C++ methods that took non-const 'char *' arguments. This was bad, since 'str' is immutable but there was no guarantee that the C++ method wouldn't try to modify the string. Now the C++ method receives a copy of the Python string for 'char *' args and only directly receives the contents for 'const char *' args. If a Python bytearray or other mutable sequence is passed as 'char *', then the wrappers will write any modifications back to Python.

Edited by David Gobbi

Merge request reports

Loading