Version française
Home     About     Download     Resources     Contact us    
Browse thread
problem calling C-function from Ocaml
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Matthieu Dubuget <matthieu.dubuget@l...>
Subject: Re: [Caml-list] problem calling C-function from Ocaml
Dan Koppel a écrit :

> Here is the C "stub function" that I use:
>  
> value stub_myCTime(
>         value _v_dummy)
> {
>   int dummy; /*in*/
>   float _res;
>   value _vres;
>   dummy = Int_val(_v_dummy);
>   _res = myCTime(dummy);
>   _vres = copy_double(_res);
>   return _vres;
> }
> value stub_myCTime_bytecode(value * argv, int argn)
> {
>   return stub_myCTime(argv[0]);
> }
>  
> and here is the .ml/.mli file that I use:
>  
> external myCamlTime : int -> float
>         = "stub_myCTime_bytecode" "stub_myCTime"
>  

I did not try. Here is the stub function I would have written (no need
for a distinct bytecode/native stub function, since there are less than
5 parameters.

CAMLprim value stub_myCTime(value _v_dummy){
CAMLparam1(_v_dummy);
int dummy;
dummy = Int_val(_v_dummy);
CAMLreturn( copy_double(myCTime(dummy)) );
}

The only point I think of  that you should check is: are the CAMLparam1
and CAMLreturn macros mandatory in your case?
I think that you are using a code that was generated by camlidl, am I
right? If this is the case, did you modify it?

Salutations

Matthieu