Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,3 @@
|
|||
void myfunc_a();
|
||||
float myfunc_b(int, float);
|
||||
char *myfunc_c(int *, int);
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
external myfunc_a: unit -> unit = "caml_myfunc_a"
|
||||
external myfunc_b: int -> float -> float = "caml_myfunc_b"
|
||||
external myfunc_c: int array -> string = "caml_myfunc_c"
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
#include <caml/mlvalues.h>
|
||||
#include <caml/alloc.h>
|
||||
#include <mylib.h>
|
||||
|
||||
CAMLprim value
|
||||
caml_myfunc_a(value unit) {
|
||||
myfunc_a();
|
||||
return Val_unit;
|
||||
}
|
||||
|
||||
CAMLprim value
|
||||
caml_myfunc_b(value a, value b) {
|
||||
float c = myfunc_b(Int_val(a), Double_val(b));
|
||||
return caml_copy_double(c);
|
||||
}
|
||||
|
||||
CAMLprim value
|
||||
caml_myfunc_c(value ml_array) {
|
||||
int i, len;
|
||||
int *arr;
|
||||
char *s;
|
||||
len = Wosize_val(ml_array);
|
||||
arr = malloc(len * sizeof(int));
|
||||
for (i=0; i < len; i++) {
|
||||
arr[i] = Int_val(Field(ml_array, i));
|
||||
}
|
||||
s = myfunc_c(arr, len);
|
||||
free(arr);
|
||||
return caml_copy_string(s);
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
wrap_mylib.o: wrap_mylib.c
|
||||
ocamlc -c -ccopt -I/usr/include/mylib $<
|
||||
|
||||
dllmylib_stubs.so: wrap_mylib.o
|
||||
ocamlmklib -o mylib_stubs $< -lmylib
|
||||
|
||||
mylib.mli: mylib.ml
|
||||
ocamlc -i $< > $@
|
||||
|
||||
mylib.cmi: mylib.mli
|
||||
ocamlc -c $<
|
||||
|
||||
mylib.cmo: mylib.ml mylib.cmi
|
||||
ocamlc -c $<
|
||||
|
||||
mylib.cma: mylib.cmo dllmylib_stubs.so
|
||||
ocamlc -a -o $@ $< -dllib -lmylib_stubs -cclib -lmylib
|
||||
|
||||
mylib.cmx: mylib.ml mylib.cmi
|
||||
ocamlopt -c $<
|
||||
|
||||
mylib.cmxa: mylib.cmx dllmylib_stubs.so
|
||||
ocamlopt -a -o $@ $< -cclib -lmylib_stubs -cclib -lmylib
|
||||
|
||||
clean:
|
||||
rm -f *.[oa] *.so *.cm[ixoa] *.cmxa
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
open Ctypes
|
||||
open Foreign
|
||||
|
||||
let myfunc_a = foreign "myfunc_a" (void @-> returning void)
|
||||
let myfunc_b = foreign "myfunc_b" (int @-> float @-> returning float)
|
||||
let myfunc_c = foreign "myfunc_c" (ptr void @-> int @-> returning string)
|
||||
|
||||
let myfunc_c lst =
|
||||
let arr = CArray.of_list int lst in
|
||||
myfunc_c (to_voidp (CArray.start arr)) (CArray.length arr)
|
||||
;;
|
||||
Loading…
Add table
Add a link
Reference in a new issue