Res: [mercury-users] Passing structures from and to C

Julien Fischer juliensf at csse.unimelb.edu.au
Thu Jul 12 10:00:58 AEST 2007


On Wed, 11 Jul 2007, Peter Wang wrote:

> On 2007-07-10, Alexsandro Soares <a_s_soares at yahoo.com.br> wrote:
>> Thanks by the answers.
>>
>> For others beginner Mercury programmers, such as myself, I put here my final code:
>>
>
>> :- func getName(person) = string.
>>
>> :- pragma foreign_proc("C",
>>      getName(P::in) = (Name::out),
>>      [will_not_call_mercury, thread_safe, promise_pure],"
>> {
>>     Name = (MR_String) strdup(P->name);
>> }").
>
> This memory won't be reclaimed.  You can use MR_make_aligned_string_copy*
> from mercury_string.h, although it's undocumented.

There's a case to be made for documenting the interface to part of the
runtime properly since non-trivial library bindings inevitably having
to use things defined in it.

Julien.
--------------------------------------------------------------------------
mercury-users mailing list
Post messages to:       mercury-users at csse.unimelb.edu.au
Administrative Queries: owner-mercury-users at csse.unimelb.edu.au
Subscriptions:          mercury-users-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the users mailing list