Commit fd1bb3d2 authored by Jason Swails's avatar Jason Swails
Browse files

In the generated C wrappers, instantiate std::string arguments from

'const char*' by passing it straight to the std::string constructor rather than
through a reinterpret_cast.  This solves segfaults when trying to use the OpenMM
C-API (which is auto-generated from the generate*Wrappers.py scripts) when used
with gcc/g++.  clang and clang++ seem to accept this (perhaps why it was not
caught before).

After these changes, the OpenMM-Tinker binding works again with the current git
version of OpenMM.
parent a6524f94
......@@ -550,6 +550,8 @@ class CSourceGenerator(WrapperGenerator):
unwrappedType = type[:-1].strip()
if unwrappedType in self.classesByShortName:
unwrappedType = self.classesByShortName[unwrappedType]
if unwrappedType == 'const std::string':
return 'std::string(%s)' % value
return '*'+self.unwrapValue(unwrappedType+'*', value)
if type in self.classesByShortName:
return 'static_cast<%s>(%s)' % (self.classesByShortName[type], value)
......
......@@ -624,6 +624,8 @@ class CSourceGenerator(WrapperGenerator):
unwrappedType = type[:-1].strip()
if unwrappedType in self.classesByShortName:
unwrappedType = self.classesByShortName[unwrappedType]
if unwrappedType == 'const std::string':
return 'std::string(%s)' % value
return '*'+self.unwrapValue(unwrappedType+'*', value)
if type in self.classesByShortName:
return 'static_cast<%s>(%s)' % (self.classesByShortName[type], value)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment