[OCaml] Initialize local roots prior to raising.
[oota-llvm.git] / bindings / ocaml / llvm / llvm_ocaml.c
index 4b146332c943170f165b3429b027e4973a3ec740..d8682880033b1880b8b4e1de6e7a8f4cea351716 100644 (file)
 #include "caml/fail.h"
 #include "caml/callback.h"
 
 #include "caml/fail.h"
 #include "caml/callback.h"
 
-static void llvm_raise(value Prototype, char *Message) {
-  CAMLparam1(Prototype);
-  CAMLlocal1(CamlMessage);
-
-  CamlMessage = copy_string(Message);
+value llvm_string_of_message(char* Message) {
+  value String = caml_copy_string(Message);
   LLVMDisposeMessage(Message);
 
   LLVMDisposeMessage(Message);
 
-  raise_with_arg(Prototype, CamlMessage);
+  return String;
+}
+
+void llvm_raise(value Prototype, char *Message) {
+  CAMLparam1(Prototype);
+  raise_with_arg(Prototype, llvm_string_of_message(Message));
   CAMLnoreturn;
 }
 
   CAMLnoreturn;
 }
 
@@ -955,6 +957,17 @@ CAMLprim value llvm_set_visibility(value Viz, LLVMValueRef Global) {
   return Val_unit;
 }
 
   return Val_unit;
 }
 
+/* llvalue -> DLLStorageClass.t */
+CAMLprim value llvm_dll_storage_class(LLVMValueRef Global) {
+  return Val_int(LLVMGetDLLStorageClass(Global));
+}
+
+/* DLLStorageClass.t -> llvalue -> unit */
+CAMLprim value llvm_set_dll_storage_class(value Viz, LLVMValueRef Global) {
+  LLVMSetDLLStorageClass(Global, Int_val(Viz));
+  return Val_unit;
+}
+
 /* llvalue -> int */
 CAMLprim value llvm_alignment(LLVMValueRef Global) {
   return Val_int(LLVMGetAlignment(Global));
 /* llvalue -> int */
 CAMLprim value llvm_alignment(LLVMValueRef Global) {
   return Val_int(LLVMGetAlignment(Global));
@@ -1577,11 +1590,12 @@ CAMLprim value llvm_position_builder(value Pos, value B) {
 }
 
 /* llbuilder -> llbasicblock */
 }
 
 /* llbuilder -> llbasicblock */
-CAMLprim LLVMBasicBlockRef llvm_insertion_block(value B) {
+CAMLprim value llvm_insertion_block(value B) {
+  CAMLparam0();
   LLVMBasicBlockRef InsertBlock = LLVMGetInsertBlock(Builder_val(B));
   if (!InsertBlock)
   LLVMBasicBlockRef InsertBlock = LLVMGetInsertBlock(Builder_val(B));
   if (!InsertBlock)
-    raise_not_found();
-  return InsertBlock;
+    caml_raise_not_found();
+  CAMLreturn((value) InsertBlock);
 }
 
 /* llvalue -> string -> llbuilder -> unit */
 }
 
 /* llvalue -> string -> llbuilder -> unit */