Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.math.mathematica

Topic: Does MLGetUTF8String() return a null-terminated string?
Replies: 1   Last Post: Feb 19, 2013 1:09 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View  
Patrick Scheibe

Posts: 327
Registered: 5/22/07
Re: Does MLGetUTF8String() return a null-terminated string?
Posted: Feb 19, 2013 1:09 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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


On Feb 18, 2013, at 12:02 PM, Szabolcs Horv=E1t <szhorvat@gmail.com> wrote:

>
> 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.
>
>






Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.