Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Does MLGetUTF8String() return a null-terminated string?

11 views
Skip to first unread message

Szabolcs Horvát

unread,
Feb 18, 2013, 6:00:13 AM2/18/13
to

Does the C MathLink function MLGetUTF8String() return a null-terminated
string? The documentation does not say that it does and it returns the
length of the string as well. But if it did, it would spare me some
copying, as my target requires a null-terminated UTF-8 string.


Patrick Scheibe

unread,
Feb 19, 2013, 1:09:14 AM2/19/13
to
Hi,

yes, I'm pretty sure it does. When you look at the LibraryLink examples,
you see that LibraryLink uses UTF8 strings as well.
In the example code you find

char *instring = MArgument_getUTF8String(Args[0]);
char *substring = MArgument_getUTF8String(Args[1]);
mint i, n = strlen(instring);
mint slen = strlen(substring);

which doesn't uses the length but calls strlen instead. If the string is
not null-terminated, strlen would fail, because
how should it know whether the string is over if not by the final \0.

When MathLink and LibraryLink share the same Wolfram type (what they
hopefully do), you should be on the safe side.

Cheers
Patrick
0 new messages