Add runtime assertion to check that values passed to Obj_val()
authorKim Nguyễn <kn@lri.fr>
Sat, 13 Oct 2012 12:54:02 +0000 (14:54 +0200)
committerKim Nguyễn <kn@lri.fr>
Sat, 13 Oct 2012 12:54:02 +0000 (14:54 +0200)
are indeed custom blocks.

myocamlbuild.ml
src/common_stub.hpp

index 7a792d1..6f27e4e 100644 (file)
@@ -127,7 +127,7 @@ let () = dispatch begin
        compile_flags @= [A "-noassert"];
        pp_macro_options @= [ A "-unsafe" ];
        native_compile_flags @= [ A "-inline"; A ocaml_inline ];
-       cxx_flags @= [ A "-O3" ]
+       cxx_flags @= [ A "-O3"; A "-DNDEBUG" ]
       end;
 
       let dir_path = Pathname.pwd / src_path in
index 3e874b7..45aa0ca 100644 (file)
@@ -14,6 +14,7 @@ extern "C" {
 }
 #include <typeinfo>
 #include <cstdio>
+#include <cassert>
 
 #define NoAlloc
 
@@ -26,6 +27,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);
 }