caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Olivier Andrieu <andrieu@ijm.jussieu.fr>
To: gava@univ-paris12.fr
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Pb "interface C <-> Ocaml" with array of string
Date: Tue, 22 Mar 2005 17:19:37 +0100 (CET)	[thread overview]
Message-ID: <20050322.171937.30179047.andrieu@ijm.jussieu.fr> (raw)
In-Reply-To: <002b01c52ef4$c6de9120$87cb0e50@mshome.net>

 Frédéric Gava [Tue, 22 Mar 2005]:
 > 
 > I have a problem with an initialization of a array of strings using a C
 > procedure. I give you the code
 > with some comments. My code works well without threads but when I add  some
 > threads to my code the array is initializing with some strange strings. If
 > someone could help me...

using String_val to pass a caml string to a C function can be unsafe
in several cases. 

Here I guess the C function copies the char* pointers and stores then
somewhere. When they are accessed later (by another function), they
have become invalid because the GC has moved the strings around.  Of
course you can't really know what the function does with the pointers
from the prototype alone, you'd need to see the library source code
(or a good documentation). The solution would be to copy the strings with
strdup() :

 for (i = 0; i < argc; i++) argv[i] = strdup (String_val(Field(arguments, i)));

-- 
   Olivier


      reply	other threads:[~2005-03-22 16:19 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-03-22 15:35 Frédéric Gava
2005-03-22 16:19 ` Olivier Andrieu [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20050322.171937.30179047.andrieu@ijm.jussieu.fr \
    --to=andrieu@ijm.jussieu.fr \
    --cc=caml-list@yquem.inria.fr \
    --cc=gava@univ-paris12.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).