@@ -82,13 +82,13 @@ impl Module {
82
82
/// Parse this bitcode file into a module, or return an error string.
83
83
pub fn parse_bitcode < ' a > ( context : & ' a Context , path : & str ) -> Result < CSemiBox < ' a , Module > , CBox < str > > {
84
84
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 ( ) ) )
90
90
} else {
91
- Ok ( CSemiBox :: new ( out) )
91
+ Ok ( CSemiBox :: new ( out. assume_init ( ) ) )
92
92
}
93
93
}
94
94
}
@@ -161,10 +161,10 @@ impl Module {
161
161
/// when an error occurs.
162
162
pub fn verify ( & self ) -> Result < ( ) , CBox < str > > {
163
163
unsafe {
164
- let mut error = mem:: uninitialized ( ) ;
164
+ let mut error = mem:: MaybeUninit :: uninit ( ) ;
165
165
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 ( ) ) )
168
168
} else {
169
169
Ok ( ( ) )
170
170
}
@@ -180,7 +180,7 @@ impl Module {
180
180
let path = path. to_str ( ) . unwrap ( ) ;
181
181
let mod_path = dir. join ( "module.bc" ) ;
182
182
let mod_path = mod_path. to_str ( ) . unwrap ( ) ;
183
- try! ( self . write_bitcode ( mod_path) ) ;
183
+ self . write_bitcode ( mod_path) ? ;
184
184
Command :: new ( "llc" )
185
185
. arg ( & format ! ( "-O={}" , opt_level) )
186
186
. arg ( "-filetype=obj" )
@@ -197,9 +197,9 @@ impl Module {
197
197
unsafe {
198
198
let dest = self . into ( ) ;
199
199
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 ( ) ) )
203
203
} else {
204
204
Ok ( ( ) )
205
205
}
@@ -213,9 +213,9 @@ impl Module {
213
213
unsafe {
214
214
let dest = self . into ( ) ;
215
215
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 ( ) ) )
219
219
} else {
220
220
Ok ( ( ) )
221
221
}
0 commit comments