From b7f633b8d3c2c107f364c83243b2c5290f9e5769 Mon Sep 17 00:00:00 2001 From: Jeroen Ketema Date: Fri, 1 Apr 2016 07:56:17 +0000 Subject: [PATCH] [OCaml] Use LLVMCreateMessage with constant strings when calling llvm_raise 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 | 2 +- llvm/bindings/ocaml/bitreader/bitreader_ocaml.c | 5 +++-- llvm/bindings/ocaml/linker/linker_ocaml.c | 3 ++- llvm/bindings/ocaml/llvm/llvm_ocaml.c | 1 + 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/llvm/bindings/ocaml/analysis/analysis_ocaml.c b/llvm/bindings/ocaml/analysis/analysis_ocaml.c index 9b746d6..8b8263d9 100644 --- a/llvm/bindings/ocaml/analysis/analysis_ocaml.c +++ b/llvm/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" diff --git a/llvm/bindings/ocaml/bitreader/bitreader_ocaml.c b/llvm/bindings/ocaml/bitreader/bitreader_ocaml.c index f91b092..6d95776 100644 --- a/llvm/bindings/ocaml/bitreader/bitreader_ocaml.c +++ b/llvm/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 @@ 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; } diff --git a/llvm/bindings/ocaml/linker/linker_ocaml.c b/llvm/bindings/ocaml/linker/linker_ocaml.c index 498a5f0..08737bd 100644 --- a/llvm/bindings/ocaml/linker/linker_ocaml.c +++ b/llvm/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 @@ 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; } diff --git a/llvm/bindings/ocaml/llvm/llvm_ocaml.c b/llvm/bindings/ocaml/llvm/llvm_ocaml.c index b4c47e7..925f3bd 100644 --- a/llvm/bindings/ocaml/llvm/llvm_ocaml.c +++ b/llvm/bindings/ocaml/llvm/llvm_ocaml.c @@ -19,6 +19,7 @@ #include #include #include "llvm-c/Core.h" +#include "llvm-c/Support.h" #include "caml/alloc.h" #include "caml/custom.h" #include "caml/memory.h" -- 2.7.4