* [Caml-list] segfault in caml_copy_string
@ 2004-07-16 14:10 Bauer, Christoph
2004-07-16 14:22 ` Basile Starynkevitch [local]
0 siblings, 1 reply; 2+ messages in thread
From: Bauer, Christoph @ 2004-07-16 14:10 UTC (permalink / raw)
To: caml-list
[-- Attachment #1: Type: text/plain, Size: 437 bytes --]
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?
OCaml Version is 3.08.0.
Thanks for help,
Christoph Bauer
[-- Attachment #2: Type: text/html, Size: 1149 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [Caml-list] segfault in caml_copy_string
2004-07-16 14:10 [Caml-list] segfault in caml_copy_string Bauer, Christoph
@ 2004-07-16 14:22 ` Basile Starynkevitch [local]
0 siblings, 0 replies; 2+ messages in thread
From: Basile Starynkevitch [local] @ 2004-07-16 14:22 UTC (permalink / raw)
To: caml-list
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2004-07-16 14:22 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-07-16 14:10 [Caml-list] segfault in caml_copy_string Bauer, Christoph
2004-07-16 14:22 ` Basile Starynkevitch [local]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox