Streamline and improve std::string typemaps

Avoid unnecessary heap allocations, just use temporary variables.

Actually update the string parameters passed by pointer/non-const
reference. This requires the pointers passed to actually be non-const,
so update the C-specific unit test runme to use a char buffer instead of
a literal string.

Also simplify the code copying the string contents to just use strdup()
(if there are ever any platforms where this POSIX functions is not
available, we could just define it ourselves once instead of using
strlen() + malloc() + memcpy() manually twice).
This commit is contained in:
Vadim Zeitlin 2021-12-05 03:05:30 +01:00
commit aacc930023
2 changed files with 49 additions and 38 deletions

View file

@ -6,7 +6,8 @@
int main()
{
char *myComposedString = c_backend_cpp_natural_std_string_myStringAppend("World, ", "Hello!");
char buf[] = "World, ";
char *myComposedString = c_backend_cpp_natural_std_string_myStringAppend(buf, "Hello!");
assert(myComposedString);
assert(strcmp(myComposedString, "World, Hello!") == 0);