@@ -722,44 +722,34 @@ pub struct Diagnostic {
722
722
level : DiagnosticLevel ,
723
723
}
724
724
725
- #[ repr( C ) ]
726
- #[ cfg( target_pointer_width = "64" ) ]
727
- pub struct ComponentCompilerOpaque ( [ usize ; 16 ] ) ;
728
-
729
- #[ repr( C ) ]
730
- #[ cfg( target_pointer_width = "32" ) ]
731
- #[ repr( align( 8 ) ) ]
732
- pub struct ComponentCompilerOpaque ( [ usize ; 19 ] ) ;
733
-
734
- /// Asserts that ComponentCompilerOpaque is as large as ComponentCompiler and has the same alignment, to make transmute safe.
735
- const _: [ ( ) ; std:: mem:: size_of :: < ComponentCompilerOpaque > ( ) ] =
736
- [ ( ) ; std:: mem:: size_of :: < ComponentCompiler > ( ) ] ;
737
- const _: [ ( ) ; std:: mem:: align_of :: < ComponentCompilerOpaque > ( ) ] =
738
- [ ( ) ; std:: mem:: align_of :: < ComponentCompiler > ( ) ] ;
725
+ #[ repr( transparent) ]
726
+ pub struct ComponentCompilerOpaque ( NonNull < ComponentCompiler > ) ;
739
727
740
728
impl ComponentCompilerOpaque {
741
729
fn as_component_compiler ( & self ) -> & ComponentCompiler {
742
730
// Safety: there should be no way to construct a ComponentCompilerOpaque without it holding an actual ComponentCompiler
743
- unsafe { std :: mem :: transmute :: < & ComponentCompilerOpaque , & ComponentCompiler > ( self ) }
731
+ unsafe { self . 0 . as_ref ( ) }
744
732
}
745
733
fn as_component_compiler_mut ( & mut self ) -> & mut ComponentCompiler {
746
734
// Safety: there should be no way to construct a ComponentCompilerOpaque without it holding an actual ComponentCompiler
747
- unsafe { std :: mem :: transmute :: < & mut ComponentCompilerOpaque , & mut ComponentCompiler > ( self ) }
735
+ unsafe { self . 0 . as_mut ( ) }
748
736
}
749
737
}
750
738
751
739
#[ no_mangle]
752
740
pub unsafe extern "C" fn slint_interpreter_component_compiler_new (
753
741
compiler : * mut ComponentCompilerOpaque ,
754
742
) {
755
- std:: ptr:: write ( compiler as * mut ComponentCompiler , ComponentCompiler :: default ( ) )
743
+ * compiler = ComponentCompilerOpaque ( NonNull :: new_unchecked ( Box :: into_raw ( Box :: new (
744
+ ComponentCompiler :: default ( ) ,
745
+ ) ) ) ) ;
756
746
}
757
747
758
748
#[ no_mangle]
759
749
pub unsafe extern "C" fn slint_interpreter_component_compiler_destructor (
760
750
compiler : * mut ComponentCompilerOpaque ,
761
751
) {
762
- drop ( std :: ptr :: read ( compiler as * mut ComponentCompiler ) )
752
+ drop ( Box :: from_raw ( ( * compiler ) . 0 . as_ptr ( ) ) )
763
753
}
764
754
765
755
#[ no_mangle]
0 commit comments