[PATCH] D18675: [OCaml] Use LLVMCreateMessage with constant strings when calling llvm_raise

Jeroen Ketema via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 31 13:54:58 PDT 2016


jketema created this revision.
jketema added a reviewer: whitequark.
jketema added a subscriber: llvm-commits.

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.

http://reviews.llvm.org/D18675

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

Index: bindings/ocaml/llvm/llvm_ocaml.c
===================================================================
--- bindings/ocaml/llvm/llvm_ocaml.c
+++ bindings/ocaml/llvm/llvm_ocaml.c
@@ -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"
Index: bindings/ocaml/linker/linker_ocaml.c
===================================================================
--- bindings/ocaml/linker/linker_ocaml.c
+++ bindings/ocaml/linker/linker_ocaml.c
@@ -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 @@
 /* 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: bindings/ocaml/bitreader/bitreader_ocaml.c
===================================================================
--- bindings/ocaml/bitreader/bitreader_ocaml.c
+++ bindings/ocaml/bitreader/bitreader_ocaml.c
@@ -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 @@
   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 @@
   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: bindings/ocaml/analysis/analysis_ocaml.c
===================================================================
--- bindings/ocaml/analysis/analysis_ocaml.c
+++ bindings/ocaml/analysis/analysis_ocaml.c
@@ -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"


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D18675.52281.patch
Type: text/x-patch
Size: 2725 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160331/0af96cc2/attachment.bin>


More information about the llvm-commits mailing list