[OCaml] Use LLVMCreateMessage with constant strings when calling llvm_raise
authorJeroen Ketema <j.ketema@imperial.ac.uk>
Fri, 1 Apr 2016 07:56:17 +0000 (07:56 +0000)
committerJeroen Ketema <j.ketema@imperial.ac.uk>
Fri, 1 Apr 2016 07:56:17 +0000 (07:56 +0000)
The llvm_string_of_message function, called by llvm_raise, calls
LLVMDisposeMessage, which expects the message to be dynamically
allocated; it fails freeing the message otherwise. So always
dynamically allocate with LLVMCreateMessage.

Differential Revision: http://reviews.llvm.org/D18675

llvm-svn: 265116

llvm/bindings/ocaml/analysis/analysis_ocaml.c
llvm/bindings/ocaml/bitreader/bitreader_ocaml.c
llvm/bindings/ocaml/linker/linker_ocaml.c
llvm/bindings/ocaml/llvm/llvm_ocaml.c

index 9b746d6..8b8263d 100644 (file)
@@ -15,8 +15,8 @@
 |*                                                                            *|
 \*===----------------------------------------------------------------------===*/
 
-#include "llvm-c/Core.h"
 #include "llvm-c/Analysis.h"
+#include "llvm-c/Core.h"
 #include "caml/alloc.h"
 #include "caml/mlvalues.h"
 #include "caml/memory.h"
index f91b092..6d95776 100644 (file)
@@ -13,6 +13,7 @@
 \*===----------------------------------------------------------------------===*/
 
 #include "llvm-c/BitReader.h"
+#include "llvm-c/Core.h"
 #include "caml/alloc.h"
 #include "caml/fail.h"
 #include "caml/memory.h"
@@ -25,7 +26,7 @@ CAMLprim LLVMModuleRef llvm_get_module(LLVMContextRef C, LLVMMemoryBufferRef Mem
   LLVMModuleRef M;
 
   if (LLVMGetBitcodeModuleInContext2(C, MemBuf, &M))
-    llvm_raise(*caml_named_value("Llvm_bitreader.Error"), "");
+    llvm_raise(*caml_named_value("Llvm_bitreader.Error"), LLVMCreateMessage(""));
 
   return M;
 }
@@ -35,7 +36,7 @@ CAMLprim LLVMModuleRef llvm_parse_bitcode(LLVMContextRef C, LLVMMemoryBufferRef
   LLVMModuleRef M;
 
   if (LLVMParseBitcodeInContext2(C, MemBuf, &M))
-    llvm_raise(*caml_named_value("Llvm_bitreader.Error"), "");
+    llvm_raise(*caml_named_value("Llvm_bitreader.Error"), LLVMCreateMessage(""));
 
   return M;
 }
index 498a5f0..08737bd 100644 (file)
@@ -15,6 +15,7 @@
 |*                                                                            *|
 \*===----------------------------------------------------------------------===*/
 
+#include "llvm-c/Core.h"
 #include "llvm-c/Linker.h"
 #include "caml/alloc.h"
 #include "caml/memory.h"
@@ -26,7 +27,7 @@ void llvm_raise(value Prototype, char *Message);
 /* llmodule -> llmodule -> unit */
 CAMLprim value llvm_link_modules(LLVMModuleRef Dst, LLVMModuleRef Src) {
   if (LLVMLinkModules2(Dst, Src))
-    llvm_raise(*caml_named_value("Llvm_linker.Error"), "Linking failed");
+    llvm_raise(*caml_named_value("Llvm_linker.Error"), LLVMCreateMessage("Linking failed"));
 
   return Val_unit;
 }
index b4c47e7..925f3bd 100644 (file)
@@ -19,6 +19,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include "llvm-c/Core.h"
+#include "llvm-c/Support.h"
 #include "caml/alloc.h"
 #include "caml/custom.h"
 #include "caml/memory.h"