@@ -82,13 +82,13 @@ impl Module {
8282 /// Parse this bitcode file into a module, or return an error string.
8383 pub fn parse_bitcode < ' a > ( context : & ' a Context , path : & str ) -> Result < CSemiBox < ' a , Module > , CBox < str > > {
8484 unsafe {
85- let mut out = mem:: uninitialized ( ) ;
86- let mut err = mem:: uninitialized ( ) ;
87- let buf = try! ( MemoryBuffer :: new_from_file ( path) ) ;
88- if reader:: LLVMParseBitcodeInContext ( context. into ( ) , buf. as_ptr ( ) , & mut out, & mut err) == 1 {
89- Err ( CBox :: new ( err) )
85+ let mut out = mem:: MaybeUninit :: uninit ( ) ;
86+ let mut err = mem:: MaybeUninit :: uninit ( ) ;
87+ let buf = MemoryBuffer :: new_from_file ( path) ? ;
88+ if reader:: LLVMParseBitcodeInContext ( context. into ( ) , buf. as_ptr ( ) , out. as_mut_ptr ( ) , err. as_mut_ptr ( ) ) == 1 {
89+ Err ( CBox :: new ( err. assume_init ( ) ) )
9090 } else {
91- Ok ( CSemiBox :: new ( out) )
91+ Ok ( CSemiBox :: new ( out. assume_init ( ) ) )
9292 }
9393 }
9494 }
@@ -161,10 +161,10 @@ impl Module {
161161 /// when an error occurs.
162162 pub fn verify ( & self ) -> Result < ( ) , CBox < str > > {
163163 unsafe {
164- let mut error = mem:: uninitialized ( ) ;
164+ let mut error = mem:: MaybeUninit :: uninit ( ) ;
165165 let action = LLVMVerifierFailureAction :: LLVMReturnStatusAction ;
166- if analysis:: LLVMVerifyModule ( self . into ( ) , action, & mut error) == 1 {
167- Err ( CBox :: new ( error) )
166+ if analysis:: LLVMVerifyModule ( self . into ( ) , action, error. as_mut_ptr ( ) ) == 1 {
167+ Err ( CBox :: new ( error. assume_init ( ) ) )
168168 } else {
169169 Ok ( ( ) )
170170 }
@@ -180,7 +180,7 @@ impl Module {
180180 let path = path. to_str ( ) . unwrap ( ) ;
181181 let mod_path = dir. join ( "module.bc" ) ;
182182 let mod_path = mod_path. to_str ( ) . unwrap ( ) ;
183- try! ( self . write_bitcode ( mod_path) ) ;
183+ self . write_bitcode ( mod_path) ? ;
184184 Command :: new ( "llc" )
185185 . arg ( & format ! ( "-O={}" , opt_level) )
186186 . arg ( "-filetype=obj" )
@@ -197,9 +197,9 @@ impl Module {
197197 unsafe {
198198 let dest = self . into ( ) ;
199199 let src = src. into ( ) ;
200- let mut message = mem:: uninitialized ( ) ;
201- if linker:: LLVMLinkModules ( dest, src, linker:: LLVMLinkerMode :: LLVMLinkerPreserveSource , & mut message) == 1 {
202- Err ( CBox :: new ( message) )
200+ let mut message = mem:: MaybeUninit :: uninit ( ) ;
201+ if linker:: LLVMLinkModules ( dest, src, linker:: LLVMLinkerMode :: LLVMLinkerPreserveSource , message. as_mut_ptr ( ) ) == 1 {
202+ Err ( CBox :: new ( message. assume_init ( ) ) )
203203 } else {
204204 Ok ( ( ) )
205205 }
@@ -213,9 +213,9 @@ impl Module {
213213 unsafe {
214214 let dest = self . into ( ) ;
215215 let src = src. as_ptr ( ) ;
216- let mut message = mem:: uninitialized ( ) ;
217- if linker:: LLVMLinkModules ( dest, src, linker:: LLVMLinkerMode :: LLVMLinkerDestroySource , & mut message) == 1 {
218- Err ( CBox :: new ( message) )
216+ let mut message = mem:: MaybeUninit :: uninit ( ) ;
217+ if linker:: LLVMLinkModules ( dest, src, linker:: LLVMLinkerMode :: LLVMLinkerDestroySource , message. as_mut_ptr ( ) ) == 1 {
218+ Err ( CBox :: new ( message. assume_init ( ) ) )
219219 } else {
220220 Ok ( ( ) )
221221 }
0 commit comments