@@ -229,7 +229,7 @@ pub struct Linker {
229
229
context : LLVMContextRef ,
230
230
module : LLVMModuleRef ,
231
231
target_machine : LLVMTargetMachineRef ,
232
- has_errors : bool ,
232
+ diagnostic_handler : DiagnosticHandler ,
233
233
}
234
234
235
235
impl Linker {
@@ -240,7 +240,7 @@ impl Linker {
240
240
context : ptr:: null_mut ( ) ,
241
241
module : ptr:: null_mut ( ) ,
242
242
target_machine : ptr:: null_mut ( ) ,
243
- has_errors : false ,
243
+ diagnostic_handler : DiagnosticHandler :: new ( ) ,
244
244
}
245
245
}
246
246
@@ -270,7 +270,7 @@ impl Linker {
270
270
}
271
271
272
272
pub fn has_errors ( & self ) -> bool {
273
- self . has_errors
273
+ self . diagnostic_handler . has_errors
274
274
}
275
275
276
276
fn link_modules ( & mut self ) -> Result < ( ) , LinkerError > {
@@ -537,8 +537,8 @@ impl Linker {
537
537
self . context = LLVMContextCreate ( ) ;
538
538
LLVMContextSetDiagnosticHandler (
539
539
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 _ ,
542
542
) ;
543
543
LLVMInstallFatalErrorHandler ( Some ( llvm:: fatal_error) ) ;
544
544
LLVMEnablePrettyStackTrace ( ) ;
@@ -551,7 +551,39 @@ impl Linker {
551
551
}
552
552
}
553
553
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 Default for DiagnosticHandler {
575
+ fn default ( ) -> Self {
576
+ Self :: new ( )
577
+ }
578
+ }
579
+
580
+ impl DiagnosticHandler {
581
+ pub fn new ( ) -> Self {
582
+ Self { has_errors : false }
583
+ }
584
+ }
585
+
586
+ impl llvm:: LLVMDiagnosticHandler for DiagnosticHandler {
555
587
fn handle_diagnostic ( & mut self , severity : llvm_sys:: LLVMDiagnosticSeverity , message : & str ) {
556
588
// TODO(https://reviews.llvm.org/D155894): Remove this when LLVM no longer emits these
557
589
// errors.
@@ -582,22 +614,6 @@ impl llvm::LLVMDiagnosticHandler for Linker {
582
614
}
583
615
}
584
616
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
-
601
617
fn detect_input_type ( data : & [ u8 ] ) -> Option < InputType > {
602
618
if data. len ( ) < 8 {
603
619
return None ;
0 commit comments