Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] Binding problem.
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2003-04-30 (06:13)
From: David Brown <caml-list@d...>
Subject: Re: [Caml-list] Binding problem.
On Wed, Apr 30, 2003 at 09:41:19AM +0400, Nickolay Kolchin-Semyonov wrote:

> Always use CAMLparam with true arguments number!

There's no real point, since some of the arguments are C heap pointers,
so they're never going to move.  It also isn't needed if the arguments
are only used before the first allocation.

> You have a bug in 
> caml_sqlite_compile (value db, value query)
> strcpy (String_val (tmp), tail);
> Don't do that. Instead work with char pointers and convert to Ocaml types only 
> at function end. I.e. (I just fixed code that don't like, without 
> understanding your algorithms)

Actually, that part works just fine, at least the string manipulation.
The example you give needs to change the
        Field (pair, 1) = copy_string (tmp);
into a
        Store_field (pair, 1, copy_string (tmp));

since the copy_string can call the GC, and could move the pair into the
shared heap.  I learned this because I just figured out what was wrong
with the binding :-)

The code I have there is kind of gross, but will always work, since
sqlite always will return a tail value that points later on.  I kind of
wanted to avoid a malloc and free to copy a value that in normal cases
will never be used.

Thanks for looking at it,

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: