caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Basile Starynkevitch [local]" <basile.starynkevitch@inria.fr>
To: caml-list@inria.fr
Subject: Re: [Caml-list] segfault in caml_copy_string
Date: Fri, 16 Jul 2004 16:22:23 +0200	[thread overview]
Message-ID: <20040716142223.GA17108@bourg.inria.fr> (raw)
In-Reply-To: <D981925B4F2CD611870300E0184CEE9B0157F214@kaiserslautern1.lms-gmbh.de>

On Fri, Jul 16, 2004 at 04:10:47PM +0200, Bauer, Christoph wrote:
> Hi,
> 
> here is a simple C-function:
> 
> CAMLprim value getparam(value request, value key)
> {
>   CAMLparam2(request, key);
>   const char * result;
>   CAMLreturn(key);  /* 1 */
>   CAMLreturn(caml_copy_string("test")); /* 2 */
>  }
> 
> Version 1 returns the key and everything works (except that
> key is not what I need.)
> 
> Version 2 calls caml_copy_string and this fails. Has anybody a idea why?

caml_copy_string actually allocates a *garbage-collected* string, so
you need to tell about its result to the GC. Try instead

 CAMLprim value getparam(value request, value key){
   CAMLparam2(request, key);
   CAMLlocal1(result);
   result = caml_copy_string("test");
   CAML_return(result);
}

(to understand why, read any material on precise moving garbage
collectors)

-- 
Basile STARYNKEVITCH -- basile dot starynkevitch at inria dot fr
Project cristal.inria.fr - phone +33 1 3963 5197 - mobile 6 8501 2359
http://cristal.inria.fr/~starynke --- all opinions are only mine 

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


      reply	other threads:[~2004-07-16 14:22 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-07-16 14:10 Bauer, Christoph
2004-07-16 14:22 ` Basile Starynkevitch [local] [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=20040716142223.GA17108@bourg.inria.fr \
    --to=basile.starynkevitch@inria.fr \
    --cc=caml-list@inria.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).