diff --git a/Cargo.lock b/Cargo.lock index c323514d..43d0461f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,3 +1,5 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. [[package]] name = "bitflags" version = "0.5.0" @@ -27,13 +29,13 @@ version = "0.5.0" dependencies = [ "cbox 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)", - "llvm-sys 0.3.0 (git+https://github.com/TomBebbington/llvm-sys.rs)", + "llvm-sys 0.3.0 (git+https://github.com/Others/llvm-sys.rs)", ] [[package]] name = "llvm-sys" version = "0.3.0" -source = "git+https://github.com/TomBebbington/llvm-sys.rs#88a4f2da362f5162d28d8fd60503733476040db6" +source = "git+https://github.com/Others/llvm-sys.rs#f4d6b7523e9c3e71a45aa8155f0ef0911689033a" dependencies = [ "bitflags 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "gcc 0.3.31 (registry+https://github.com/rust-lang/crates.io-index)", @@ -51,5 +53,5 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum cbox 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e4198143b96d30e1758ebe0abab558e0845f09b36d83872d88db34911349321f" "checksum gcc 0.3.31 (registry+https://github.com/rust-lang/crates.io-index)" = "cfe877476e53690ebb0ce7325d0bf43e198d9500291b54b3c65e518de5039b07" "checksum libc 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "39dfaaa0f4da0f1a06876c5d94329d739ad0150868069cc235f1ddf80a0480e7" -"checksum llvm-sys 0.3.0 (git+https://github.com/TomBebbington/llvm-sys.rs)" = "" +"checksum llvm-sys 0.3.0 (git+https://github.com/Others/llvm-sys.rs)" = "" "checksum semver 0.1.20 (registry+https://github.com/rust-lang/crates.io-index)" = "d4f410fedcf71af0345d7607d246e7ad15faaadd49d240ee3b24e5dc21a820ac" diff --git a/src/buffer.rs b/src/buffer.rs index 52c5939e..da6b13d4 100644 --- a/src/buffer.rs +++ b/src/buffer.rs @@ -13,12 +13,12 @@ native_ref!(&MemoryBuffer = LLVMMemoryBufferRef); impl MemoryBuffer { pub fn new_from_file(path: &str) -> Result, CBox> { util::with_cstr(path, |path| unsafe { - let mut output = mem::uninitialized(); - let mut error = mem::uninitialized(); - if core::LLVMCreateMemoryBufferWithContentsOfFile(path, &mut output, &mut error) == 1 { - Err(CBox::new(error)) + let mut output = mem::MaybeUninit::uninit(); + let mut error = mem::MaybeUninit::uninit(); + if core::LLVMCreateMemoryBufferWithContentsOfFile(path, output.as_mut_ptr(), error.as_mut_ptr()) == 1 { + Err(CBox::new(error.assume_init())) } else { - Ok(CBox::new(output)) + Ok(CBox::new(output.assume_init())) } }) } diff --git a/src/engine.rs b/src/engine.rs index 0e5f3630..c4f71839 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -30,9 +30,9 @@ pub trait ExecutionEngine<'a>:'a + Sized + DisposeRef where LLVMExecutionEngineR /// Remove a module from the list of modules to interpret or compile. fn remove_module(&'a self, module: &'a Module) -> &'a Module { unsafe { - let mut out = mem::uninitialized(); - engine::LLVMRemoveModule(self.into(), module.into(), &mut out, ptr::null_mut()); - out.into() + let mut out = mem::MaybeUninit::uninit(); + engine::LLVMRemoveModule(self.into(), module.into(), out.as_mut_ptr(), ptr::null_mut()); + out.assume_init().into() } } /// Execute all of the static constructors for this program. @@ -134,7 +134,7 @@ impl<'a> ExecutionEngine<'a> for JitEngine { type Options = JitOptions; fn new(module: &'a Module, options: JitOptions) -> Result, CBox> { unsafe { - let mut ee = mem::uninitialized(); + let mut ee = mem::MaybeUninit::uninit(); let mut out = mem::zeroed(); engine::LLVMLinkInMCJIT(); if target::LLVM_InitializeNativeTarget() == 1 { @@ -151,9 +151,9 @@ impl<'a> ExecutionEngine<'a> for JitEngine { MCJMM: ptr::null_mut() }; let size = mem::size_of::(); - let result = engine::LLVMCreateMCJITCompilerForModule(&mut ee, (&*module).into(), &mut options, size, &mut out); + let result = engine::LLVMCreateMCJITCompilerForModule(ee.as_mut_ptr(), (&*module).into(), &mut options, size, &mut out); if result == 0 { - Ok(ee.into()) + Ok(ee.assume_init().into()) } else { Err(CBox::new(out)) } @@ -168,12 +168,12 @@ impl<'a> ExecutionEngine<'a> for Interpreter { type Options = (); fn new(module: &'a Module, _: ()) -> Result, CBox> { unsafe { - let mut ee = mem::uninitialized(); + let mut ee = mem::MaybeUninit::uninit(); let mut out = mem::zeroed(); engine::LLVMLinkInInterpreter(); - let result = engine::LLVMCreateInterpreterForModule(&mut ee, (&*module).into(), &mut out); + let result = engine::LLVMCreateInterpreterForModule(ee.as_mut_ptr(), (&*module).into(), &mut out); if result == 0 { - Ok(ee.into()) + Ok(ee.assume_init().into()) } else { Err(CBox::new(out)) } diff --git a/src/module.rs b/src/module.rs index 8420e3d1..30922433 100644 --- a/src/module.rs +++ b/src/module.rs @@ -82,13 +82,13 @@ impl Module { /// Parse this bitcode file into a module, or return an error string. pub fn parse_bitcode<'a>(context: &'a Context, path: &str) -> Result, CBox> { unsafe { - let mut out = mem::uninitialized(); - let mut err = mem::uninitialized(); - let buf = try!(MemoryBuffer::new_from_file(path)); - if reader::LLVMParseBitcodeInContext(context.into(), buf.as_ptr(), &mut out, &mut err) == 1 { - Err(CBox::new(err)) + let mut out = mem::MaybeUninit::uninit(); + let mut err = mem::MaybeUninit::uninit(); + let buf = MemoryBuffer::new_from_file(path)?; + if reader::LLVMParseBitcodeInContext(context.into(), buf.as_ptr(), out.as_mut_ptr(), err.as_mut_ptr()) == 1 { + Err(CBox::new(err.assume_init())) } else { - Ok(CSemiBox::new(out)) + Ok(CSemiBox::new(out.assume_init())) } } } @@ -161,10 +161,10 @@ impl Module { /// when an error occurs. pub fn verify(&self) -> Result<(), CBox> { unsafe { - let mut error = mem::uninitialized(); + let mut error = mem::MaybeUninit::uninit(); let action = LLVMVerifierFailureAction::LLVMReturnStatusAction; - if analysis::LLVMVerifyModule(self.into(), action, &mut error) == 1 { - Err(CBox::new(error)) + if analysis::LLVMVerifyModule(self.into(), action, error.as_mut_ptr()) == 1 { + Err(CBox::new(error.assume_init())) } else { Ok(()) } @@ -180,7 +180,7 @@ impl Module { let path = path.to_str().unwrap(); let mod_path = dir.join("module.bc"); let mod_path = mod_path.to_str().unwrap(); - try!(self.write_bitcode(mod_path)); + self.write_bitcode(mod_path)?; Command::new("llc") .arg(&format!("-O={}", opt_level)) .arg("-filetype=obj") @@ -197,9 +197,9 @@ impl Module { unsafe { let dest = self.into(); let src = src.into(); - let mut message = mem::uninitialized(); - if linker::LLVMLinkModules(dest, src, linker::LLVMLinkerMode::LLVMLinkerPreserveSource, &mut message) == 1 { - Err(CBox::new(message)) + let mut message = mem::MaybeUninit::uninit(); + if linker::LLVMLinkModules(dest, src, linker::LLVMLinkerMode::LLVMLinkerPreserveSource, message.as_mut_ptr()) == 1 { + Err(CBox::new(message.assume_init())) } else { Ok(()) } @@ -213,9 +213,9 @@ impl Module { unsafe { let dest = self.into(); let src = src.as_ptr(); - let mut message = mem::uninitialized(); - if linker::LLVMLinkModules(dest, src, linker::LLVMLinkerMode::LLVMLinkerDestroySource, &mut message) == 1 { - Err(CBox::new(message)) + let mut message = mem::MaybeUninit::uninit(); + if linker::LLVMLinkModules(dest, src, linker::LLVMLinkerMode::LLVMLinkerDestroySource, message.as_mut_ptr()) == 1 { + Err(CBox::new(message.assume_init())) } else { Ok(()) } diff --git a/src/object.rs b/src/object.rs index 6af40879..cabf1f4f 100644 --- a/src/object.rs +++ b/src/object.rs @@ -16,7 +16,7 @@ native_ref!(ObjectFile, obj: LLVMObjectFileRef); impl ObjectFile { /// Parse the object file at the path given, or return an error string if an error occurs. pub fn read(path: &str) -> Result> { - let buf = try!(MemoryBuffer::new_from_file(path)); + let buf = MemoryBuffer::new_from_file(path)?; unsafe { let ptr = object::LLVMCreateObjectFile(buf.as_ptr()); if ptr.is_null() { diff --git a/src/types.rs b/src/types.rs index 7a6a40f1..6ecaaa2d 100644 --- a/src/types.rs +++ b/src/types.rs @@ -108,9 +108,9 @@ impl StructType { pub fn get_elements(&self) -> Vec<&Type> { unsafe { let size = core::LLVMCountStructElementTypes(self.into()); - let mut els:Vec<_> = (0..size).map(|_| mem::uninitialized()).collect(); + let mut els:Vec<_> = (0..size).map(|_| mem::MaybeUninit::<&Type>::uninit()).collect(); core::LLVMGetStructElementTypes(self.into(), els.as_mut_ptr() as *mut LLVMTypeRef); - els + els.into_iter().map(|el| el.assume_init()).collect() } } } @@ -145,9 +145,9 @@ impl FunctionType { pub fn get_params(&self) -> Vec<&Type> { unsafe { let count = core::LLVMCountParamTypes(self.into()); - let mut types:Vec<_> = (0..count).map(|_| mem::uninitialized()).collect(); + let mut types:Vec<_> = (0..count).map(|_| mem::MaybeUninit::<&Type>::uninit()).collect(); core::LLVMGetParamTypes(self.into(), types.as_mut_ptr() as *mut LLVMTypeRef); - types + types.into_iter().map(|type_| type_.assume_init()).collect() } } /// Returns the type that this function returns. @@ -229,4 +229,4 @@ impl ArrayType { pub fn get_length(&self) -> usize { unsafe { core::LLVMGetArrayLength(self.into()) as usize } } -} \ No newline at end of file +}