Merge branch 'master' of ssh://git.nguyen.vg/SXSI/xpathcomp
[SXSI/xpathcomp.git] / src / common_stub.hpp
index ad15256..b771f33 100644 (file)
@@ -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
@@ -13,9 +13,15 @@ extern "C" {
 #include <caml/bigarray.h>
 }
 #include <typeinfo>
+#include <cstdio>
+#include <cassert>
 
 #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,
                      size_t size,
@@ -25,6 +31,7 @@ value alloc_custom_(char* name);
 
 template <class X> X& Obj_val(value v)
 {
+  assert(Tag_val(v) == Custom_tag);
   return * (X*) Data_custom_val(v);
 }
 
@@ -55,8 +62,7 @@ sxsi_alloc_custom(void (*finalize)(value) = sxsi_finalize_custom<X>)
 
 void sxsi_raise_msg(const char * msg);
 
-extern "C" value sxsi_cpp_init(value unit);
-
+ML_BINDING value sxsi_cpp_init(value unit);
 
 
 #endif