X-Git-Url: http://git.nguyen.vg/gitweb/?a=blobdiff_plain;f=src%2Fcommon_stub.hpp;h=b771f338f16c684c33d705afaa23e6e8cedde7da;hb=29fa227d5418c6346167f3ec46a68bff9f104392;hp=5655a309cef9402872b4acac19d67d7399e33360;hpb=813b239795aac1844eb233dab7f8f98d8dba845e;p=SXSI%2Fxpathcomp.git diff --git a/src/common_stub.hpp b/src/common_stub.hpp index 5655a30..b771f33 100644 --- a/src/common_stub.hpp +++ b/src/common_stub.hpp @@ -1,5 +1,5 @@ -#ifndef COMMON_STUB_H_ -#define COMMON_STUB_H_ +#ifndef COMMON_STUB_HPP_ +#define COMMON_STUB_HPP_ extern "C" { #define CAML_NAME_SPACE @@ -11,9 +11,16 @@ extern "C" { #include #include #include - } #include +#include +#include + +#define NoAlloc + +//Must be used in front of every function that is called from OCaml. + +#define ML_BINDING extern "C" __attribute__ ((force_align_arg_pointer)) void register_custom_(char* name, @@ -24,6 +31,7 @@ value alloc_custom_(char* name); template X& Obj_val(value v) { + assert(Tag_val(v) == Custom_tag); return * (X*) Data_custom_val(v); } @@ -39,22 +47,22 @@ template void sxsi_finalize_custom(value v) sxsi_finalize_obj(Obj_val(v)); } -template value sxsi_alloc_custom() +template value +sxsi_alloc_custom(void (*finalize)(value) = sxsi_finalize_custom) { char * name = const_cast(typeid(X).name()); value v = alloc_custom_(name); if (v == Val_unit) { - register_custom_(name, sizeof(X), sxsi_finalize_custom); + register_custom_(name, sizeof(X), finalize); v = alloc_custom_(name); }; return v; } -void sxsi_raise_msg(char * msg); - -extern "C" value sxsi_cpp_init(value unit); +void sxsi_raise_msg(const char * msg); +ML_BINDING value sxsi_cpp_init(value unit); #endif