From 206d512c10dbf97446b740903869c3810d3e5005 Mon Sep 17 00:00:00 2001 From: Siu Kwan Lam Date: Thu, 17 Jan 2013 18:59:20 -0600 Subject: [PATCH] Fix LLVMLinkModules for LLVM-3.1 --- llvm/_core.cpp | 4 ++-- llvm/extra.cpp | 24 +++++++++--------------- llvm/extra.h | 7 +++---- 3 files changed, 14 insertions(+), 21 deletions(-) diff --git a/llvm/_core.cpp b/llvm/_core.cpp index 18b39f3..db5287e 100644 --- a/llvm/_core.cpp +++ b/llvm/_core.cpp @@ -278,8 +278,8 @@ _wLLVMLinkModules(PyObject *self, PyObject *args) const LLVMModuleRef dest = pycap_get(dest_obj ) ; const LLVMModuleRef src = pycap_get(src_obj) ; - PyObject *ret; - char *errmsg; + PyObject *ret = NULL; + char *errmsg = NULL; if (LLVMLinkModules(dest, src, (LLVMLinkerMode)mode, &errmsg)) { if (errmsg) { ret = PyUnicode_FromString(errmsg); diff --git a/llvm/extra.cpp b/llvm/extra.cpp index 726ebab..7b6c064 100644 --- a/llvm/extra.cpp +++ b/llvm/extra.cpp @@ -1191,21 +1191,15 @@ LLVMModuleRef LLVMGetModuleFromBitcode(const char *bitcode, unsigned bclen, } #if LLVM_VERSION_MAJOR <= 3 && LLVM_VERSION_MINOR < 2 -unsigned LLVMLinkModules(LLVMModuleRef dest, LLVMModuleRef src, unsigned int mode, - char **out) -{ - llvm::Module *sourcep = llvm::unwrap(src); - assert(sourcep); - llvm::Module *destinationp = llvm::unwrap(dest); - assert(destinationp); - - std::string msg; - if (llvm::Linker::LinkModules(destinationp, sourcep, mode, &msg)) { - *out = strdup(msg.c_str()); - return 0; - } - - return 1; +// Shamelessly copy from LLVM-3.2 +unsigned LLVMLinkModules(LLVMModuleRef Dest, LLVMModuleRef Src, + int Mode, char **OutMessages) { + std::string Messages; + unsigned Result = Linker::LinkModules(unwrap(Dest), unwrap(Src), Mode, + OutMessages? &Messages : 0); + if (OutMessages) + *OutMessages = strdup(Messages.c_str()); + return Result; } #endif diff --git a/llvm/extra.h b/llvm/extra.h index 829de23..b734f1b 100644 --- a/llvm/extra.h +++ b/llvm/extra.h @@ -46,10 +46,9 @@ #endif #include "llvm-c/Transforms/PassManagerBuilder.h" - - #include "llvm_c_extra.h" + #ifdef __cplusplus extern "C" { #endif @@ -578,8 +577,8 @@ LLVMModuleRef LLVMGetModuleFromBitcode(const char *bc, unsigned bclen, /* Wraps llvm::Linker::LinkModules(). Returns 0 on failure (with errmsg * filled in) and 1 on success. Dispose error message after use with * LLVMDisposeMessage(). */ -unsigned LLVMLinkModules(LLVMModuleRef dest, LLVMModuleRef src, - unsigned int, char **errmsg); +unsigned LLVMLinkModules(LLVMModuleRef dest, LLVMModuleRef src, int mode, + char **errmsg); #endif /* Returns pointer to a heap-allocated block of `*len' bytes containing bit code * for the given module. NULL on error. */