Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2013

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Does MLGetUTF8String() return a null-terminated string?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg129856] Re: Does MLGetUTF8String() return a null-terminated string?
  • From: Patrick Scheibe <pscheibe at trm.uni-leipzig.de>
  • Date: Tue, 19 Feb 2013 00:58:26 -0500 (EST)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • Delivered-to: l-mathgroup@wolfram.com
  • Delivered-to: mathgroup-newout@smc.vnet.net
  • Delivered-to: mathgroup-newsend@smc.vnet.net
  • References: <20130218110203.548426960@smc.vnet.net>

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




  • Prev by Date: Re: Stephen Wolfram's recent blog
  • Next by Date: Re: Stephen Wolfram's recent blog
  • Previous by thread: Does MLGetUTF8String() return a null-terminated string?
  • Next by thread: Ingolf Dahl's "SetFaceAndFont" palette broken in Mathematica 9