@@ -229,7 +229,7 @@ pub struct Linker {
229229 context : LLVMContextRef ,
230230 module : LLVMModuleRef ,
231231 target_machine : LLVMTargetMachineRef ,
232- has_errors : bool ,
232+ diagnostic_handler : DiagnosticHandler ,
233233}
234234
235235impl Linker {
@@ -240,7 +240,7 @@ impl Linker {
240240 context : ptr:: null_mut ( ) ,
241241 module : ptr:: null_mut ( ) ,
242242 target_machine : ptr:: null_mut ( ) ,
243- has_errors : false ,
243+ diagnostic_handler : DiagnosticHandler :: new ( ) ,
244244 }
245245 }
246246
@@ -270,7 +270,7 @@ impl Linker {
270270 }
271271
272272 pub fn has_errors ( & self ) -> bool {
273- self . has_errors
273+ self . diagnostic_handler . has_errors
274274 }
275275
276276 fn link_modules ( & mut self ) -> Result < ( ) , LinkerError > {
@@ -537,8 +537,8 @@ impl Linker {
537537 self . context = LLVMContextCreate ( ) ;
538538 LLVMContextSetDiagnosticHandler (
539539 self . context ,
540- Some ( llvm:: diagnostic_handler :: < Self > ) ,
541- self as * mut _ as _ ,
540+ Some ( llvm:: diagnostic_handler :: < DiagnosticHandler > ) ,
541+ & mut self . diagnostic_handler as * mut _ as _ ,
542542 ) ;
543543 LLVMInstallFatalErrorHandler ( Some ( llvm:: fatal_error) ) ;
544544 LLVMEnablePrettyStackTrace ( ) ;
@@ -551,7 +551,33 @@ impl Linker {
551551 }
552552}
553553
554- impl llvm:: LLVMDiagnosticHandler for Linker {
554+ impl Drop for Linker {
555+ fn drop ( & mut self ) {
556+ unsafe {
557+ if !self . target_machine . is_null ( ) {
558+ LLVMDisposeTargetMachine ( self . target_machine ) ;
559+ }
560+ if !self . module . is_null ( ) {
561+ LLVMDisposeModule ( self . module ) ;
562+ }
563+ if !self . context . is_null ( ) {
564+ LLVMContextDispose ( self . context ) ;
565+ }
566+ }
567+ }
568+ }
569+
570+ pub struct DiagnosticHandler {
571+ pub ( crate ) has_errors : bool ,
572+ }
573+
574+ impl DiagnosticHandler {
575+ pub fn new ( ) -> Self {
576+ Self { has_errors : false }
577+ }
578+ }
579+
580+ impl llvm:: LLVMDiagnosticHandler for DiagnosticHandler {
555581 fn handle_diagnostic ( & mut self , severity : llvm_sys:: LLVMDiagnosticSeverity , message : & str ) {
556582 // TODO(https://reviews.llvm.org/D155894): Remove this when LLVM no longer emits these
557583 // errors.
@@ -582,22 +608,6 @@ impl llvm::LLVMDiagnosticHandler for Linker {
582608 }
583609}
584610
585- impl Drop for Linker {
586- fn drop ( & mut self ) {
587- unsafe {
588- if !self . target_machine . is_null ( ) {
589- LLVMDisposeTargetMachine ( self . target_machine ) ;
590- }
591- if !self . module . is_null ( ) {
592- LLVMDisposeModule ( self . module ) ;
593- }
594- if !self . context . is_null ( ) {
595- LLVMContextDispose ( self . context ) ;
596- }
597- }
598- }
599- }
600-
601611fn detect_input_type ( data : & [ u8 ] ) -> Option < InputType > {
602612 if data. len ( ) < 8 {
603613 return None ;
0 commit comments