Skip to content

Commit

Permalink
[OCaml] Use LLVMCreateMessage with constant strings when calling llvm…
Browse files Browse the repository at this point in the history
…_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


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@265116 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
Jeroen Ketema committed Apr 1, 2016
1 parent 145384c commit f4430ca
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion bindings/ocaml/analysis/analysis_ocaml.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 3 additions & 2 deletions bindings/ocaml/bitreader/bitreader_ocaml.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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;
}
Expand All @@ -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;
}
3 changes: 2 additions & 1 deletion bindings/ocaml/linker/linker_ocaml.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
|* *|
\*===----------------------------------------------------------------------===*/

#include "llvm-c/Core.h"
#include "llvm-c/Linker.h"
#include "caml/alloc.h"
#include "caml/memory.h"
Expand All @@ -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;
}
1 change: 1 addition & 0 deletions bindings/ocaml/llvm/llvm_ocaml.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit f4430ca

Please sign in to comment.