Skip to content

Commit

Permalink
Made broken file writing method private. GH issue rust-lang#6
Browse files Browse the repository at this point in the history
  • Loading branch information
TheDan64 committed Jul 13, 2017
1 parent 93bc8d2 commit e89a583
Showing 1 changed file with 26 additions and 24 deletions.
50 changes: 26 additions & 24 deletions src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,10 @@ impl Module {
}
}

pub fn write_bitcode_to_file(&self, file: &File, should_close: bool, unbuffered: bool) -> bool {
// See GH issue #6
fn write_bitcode_to_file(&self, file: &File, should_close: bool, unbuffered: bool) -> bool {
// REVIEW: as_raw_fd docs suggest it only works in *nix
// Also, should_close should maybe be hardcoded to true?
unsafe {
LLVMWriteBitcodeToFD(self.module, file.as_raw_fd(), should_close as i32, unbuffered as i32) == 0
}
Expand Down Expand Up @@ -286,35 +288,35 @@ fn test_write_bitcode_to_path() {
remove_file(&path).unwrap();
}

#[test]
fn test_write_bitcode_to_file() {
use context::Context;
use std::env::temp_dir;
use std::fs::{File, remove_file};
use std::io::{Read, Seek, SeekFrom};
// REVIEW: This test infrequently fails. Seems to happen more often on travis.
// Possibly a LLVM bug? Wrapper is really straightforward. See issue #6 on GH
// #[test]
// fn test_write_bitcode_to_file() {
// use context::Context;
// use std::env::temp_dir;
// use std::fs::{File, remove_file};
// use std::io::{Read, Seek, SeekFrom};

let mut path = temp_dir();
// let mut path = temp_dir();

path.push("temp2.bc");
// path.push("temp2.bc");

let mut file = File::create(&path).unwrap();
// let mut file = File::create(&path).unwrap();

let context = Context::create();
let module = context.create_module("my_module");
let void_type = context.void_type();
let fn_type = void_type.fn_type(&[], false);
// let context = Context::create();
// let module = context.create_module("my_module");
// let void_type = context.void_type();
// let fn_type = void_type.fn_type(&[], false);

module.add_function("my_fn", &fn_type);
module.write_bitcode_to_file(&file, true, false);

let mut contents = Vec::new();
let mut file2 = File::open(&path).expect("Could not open temp file");
// module.add_function("my_fn", &fn_type);
// module.write_bitcode_to_file(&file, true, false);

file.read_to_end(&mut contents).expect("Unable to verify written file");
// let mut contents = Vec::new();
// let mut file2 = File::open(&path).expect("Could not open temp file");

assert!(contents.len() > 0);
// file.read_to_end(&mut contents).expect("Unable to verify written file");

remove_file(&path).unwrap();
// assert!(contents.len() > 0);

// REVIEW: This test infrequently fails. LLVM bug?
}
// remove_file(&path).unwrap();
// }

0 comments on commit e89a583

Please sign in to comment.