[llvm] r220611 - Allow the C API users to keep relying on the OutMessages parameter.
Rafael Espindola
rafael.espindola at gmail.com
Fri Oct 24 21:31:09 PDT 2014
Author: rafael
Date: Fri Oct 24 23:31:08 2014
New Revision: 220611
URL: http://llvm.org/viewvc/llvm-project?rev=220611&view=rev
Log:
Allow the C API users to keep relying on the OutMessages parameter.
Should fix the Ocaml tests.
Modified:
llvm/trunk/lib/Linker/LinkModules.cpp
Modified: llvm/trunk/lib/Linker/LinkModules.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Linker/LinkModules.cpp?rev=220611&r1=220610&r2=220611&view=diff
==============================================================================
--- llvm/trunk/lib/Linker/LinkModules.cpp (original)
+++ llvm/trunk/lib/Linker/LinkModules.cpp Fri Oct 24 23:31:08 2014
@@ -1766,8 +1766,33 @@ bool Linker::LinkModules(Module *Dest, M
// C API.
//===----------------------------------------------------------------------===//
+static void bindingDiagnosticHandler(const llvm::DiagnosticInfo &DI,
+ void *Context) {
+ if (DI.getSeverity() != DS_Error)
+ return;
+
+ std::string *Message = (std::string *)Context;
+ {
+ raw_string_ostream Stream(*Message);
+ DiagnosticPrinterRawOStream DP(Stream);
+ DI.print(DP);
+ }
+}
+
+
LLVMBool LLVMLinkModules(LLVMModuleRef Dest, LLVMModuleRef Src,
LLVMLinkerMode Mode, char **OutMessages) {
- LLVMBool Result = Linker::LinkModules(unwrap(Dest), unwrap(Src), Mode);
+ Module *D = unwrap(Dest);
+ LLVMContext &Ctx = D->getContext();
+
+ LLVMContext::DiagnosticHandlerTy OldHandler = Ctx.getDiagnosticHandler();
+ void *OldDiagnosticContext = Ctx.getDiagnosticContext();
+ std::string Message;
+ Ctx.setDiagnosticHandler(bindingDiagnosticHandler, &Message);
+ LLVMBool Result = Linker::LinkModules(D, unwrap(Src), Mode);
+ Ctx.setDiagnosticHandler(OldHandler, OldDiagnosticContext);
+
+ if (OutMessages && Result)
+ *OutMessages = strdup(Message.c_str());
return Result;
}
More information about the llvm-commits
mailing list