Skip to content

Commit

Permalink
Fix merge errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jguhlin committed Nov 25, 2024
1 parent fffe869 commit fbdcb7d
Showing 1 changed file with 10 additions and 64 deletions.
74 changes: 10 additions & 64 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,6 @@ pub struct Aligner {

/// Index created by minimap2
pub idx: Option<Arc<*mut mm_idx_t>>,
pub idx: Option<Arc<*mut mm_idx_t>>,

/// Index reader created by minimap2
pub idx_reader: Option<Arc<mm_idx_reader_t>>,
Expand Down Expand Up @@ -894,7 +893,6 @@ impl Aligner {

mm_reg = MaybeUninit::new(unsafe {
mm_map(
&**self.idx.as_ref().unwrap().as_ref() as *const mm_idx_t,
&**self.idx.as_ref().unwrap().as_ref() as *const mm_idx_t,
seq.len() as i32,
seq.as_ptr() as *const ::std::os::raw::c_char,
Expand Down Expand Up @@ -1023,7 +1021,6 @@ impl Aligner {
&mut cs_string,
&mut m_cs_string,
&**self.idx.as_ref().unwrap().as_ref() as *const mm_idx_t,
&**self.idx.as_ref().unwrap().as_ref() as *const mm_idx_t,
const_ptr,
seq.as_ptr() as *const libc::c_char,
true.into(),
Expand All @@ -1043,7 +1040,6 @@ impl Aligner {
&mut cs_string,
&mut m_cs_string,
&**self.idx.as_ref().unwrap().as_ref() as *const mm_idx_t,
&**self.idx.as_ref().unwrap().as_ref() as *const mm_idx_t,
const_ptr,
seq.as_ptr() as *const libc::c_char,
);
Expand Down Expand Up @@ -1074,7 +1070,6 @@ impl Aligner {
};

let target_name_arc = Arc::new(
std::ffi::CStr::from_ptr(contig.as_ptr())
std::ffi::CStr::from_ptr(contig.as_ptr())
.to_str()
.unwrap()
Expand All @@ -1088,7 +1083,6 @@ impl Aligner {
mappings.push(Mapping {
target_name: Some(Arc::clone(&target_name_arc)),
target_len,
target_len,
target_start: reg.rs,
target_end: reg.re,
query_name: query_name_arc.clone(),
Expand Down Expand Up @@ -1852,22 +1846,19 @@ mod tests {
Err("File does not exist")
);

if let Err("Index File is empty") = Aligner::builder().with_index("test_data/empty.fa", None)
if let Err("Index File is empty") = Aligner::builder().with_index("test_data/empty.fa", None)
{
println!("File is empty - Success");
} else {
panic!("File is empty error not thrown");
}

if let Err("Invalid Path for Index") = Aligner::builder().with_index("\0invalid_\0path\0", None) {
if let Err("Invalid Path for Index") = Aligner::builder().with_index("\0invalid_\0path\0", None) {
println!("Invalid Path - Success");
} else {
panic!("Invalid Path error not thrown");
}

if let Err("Invalid Output for Index") =
if let Err("Invalid Output for Index") =
Aligner::builder().with_index("test_data/MT-human.fa", Some("test\0test"))
{
Expand Down Expand Up @@ -1965,22 +1956,16 @@ mod tests {
}

#[test]
fn double_free_index_test() {
fn double_free_index_test() {
// Create a new aligner
println!("Creating aligner");
println!("Creating aligner");
let aligner = Aligner::builder().map_ont().with_index("yeast_ref.mmi", None).unwrap();
println!("Aligner created");
println!("Aligner created");

// Perform a test mapping to ensure the index is loaded and all
let mappings = aligner.map("ACGGTAGAGAGGAAGAAGAAGGAATAGCGGACTTGTGTATTTTATCGTCATTCGTGGTTATCATATAGTTTATTGATTTGAAGACTACGTAAGTAATTTGAGGACTGATTAAAATTTTCTTTTTTAGCTTAGAGTCAATTAAAGAGGGCAAAATTTTCTCAAAAGACCATGGTGCATATGACGATAGCTTTAGTAGTATGGATTGGGCTCTTCTTTCATGGATGTTATTCAGAAGGAGTGATATATCGAGGTGTTTGAAACACCAGCGACACCAGAAGGCTGTGGATGTTAAATCGTAGAACCTATAGACGAGTTCTAAAATATACTTTGGGGTTTTCAGCGATGCAAAA".as_bytes(), false, false, None, None, Some("Sample Query")).unwrap();
assert!(mappings.len() > 0);

println!("Going into threads");
assert!(mappings.len() > 0);

println!("Going into threads");

// Spawn two threads using thread scoped aligners, clone aligner
Expand All @@ -1993,26 +1978,13 @@ mod tests {
// Confirm we have a strong count of 2
assert_eq!(Arc::strong_count(&aligner.idx.as_ref().unwrap()), 2);

let jh0 = s.spawn(move || {
let mappings = aligner_.map("ACGGTAGAGAGGAAGAAGAAGGAATAGCGGACTTGTGTATTTTATCGTCATTCGTGGTTATCATATAGTTTATTGATTTGAAGACTACGTAAGTAATTTGAGGACTGATTAAAATTTTCTTTTTTAGCTTAGAGTCAATTAAAGAGGGCAAAATTTTCTCAAAAGACCATGGTGCATATGACGATAGCTTTAGTAGTATGGATTGGGCTCTTCTTTCATGGATGTTATTCAGAAGGAGTGATATATCGAGGTGTTTGAAACACCAGCGACACCAGAAGGCTGTGGATGTTAAATCGTAGAACCTATAGACGAGTTCTAAAATATACTTTGGGGTTTTCAGCGATGCAAAA".as_bytes(), false, false, None, None, Some("Sample Query")).unwrap();
assert!(mappings.len() > 0);
let aligner_ = aligner.clone();

// Confirm that aligner_ idx points to the same memory as aligner idx arc
assert_eq!(Arc::as_ptr(aligner.idx.as_ref().unwrap()), Arc::as_ptr(aligner_.idx.as_ref().unwrap()));

// Confirm we have a strong count of 2
assert_eq!(Arc::strong_count(&aligner.idx.as_ref().unwrap()), 2);

let jh0 = s.spawn(move || {
let mappings = aligner_.map("ACGGTAGAGAGGAAGAAGAAGGAATAGCGGACTTGTGTATTTTATCGTCATTCGTGGTTATCATATAGTTTATTGATTTGAAGACTACGTAAGTAATTTGAGGACTGATTAAAATTTTCTTTTTTAGCTTAGAGTCAATTAAAGAGGGCAAAATTTTCTCAAAAGACCATGGTGCATATGACGATAGCTTTAGTAGTATGGATTGGGCTCTTCTTTCATGGATGTTATTCAGAAGGAGTGATATATCGAGGTGTTTGAAACACCAGCGACACCAGAAGGCTGTGGATGTTAAATCGTAGAACCTATAGACGAGTTCTAAAATATACTTTGGGGTTTTCAGCGATGCAAAA".as_bytes(), false, false, None, None, Some("Sample Query")).unwrap();
assert!(mappings.len() > 0);
// Sleep 100ms
std::thread::sleep(std::time::Duration::from_millis(100));
});

let aligner_ = aligner.clone();
let jh1 = s.spawn(move || {
let aligner_ = aligner.clone();
let jh1 = s.spawn(move || {
std::thread::sleep(std::time::Duration::from_millis(200));
Expand Down Expand Up @@ -2047,44 +2019,11 @@ mod tests {
println!("First thread");
let mappings = aligner0.map("ACGGTAGAGAGGAAGAAGAAGGAATAGCGGACTTGTGTATTTTATCGTCATTCGTGGTTATCATATAGTTTATTGATTTGAAGACTACGTAAGTAATTTGAGGACTGATTAAAATTTTCTTTTTTAGCTTAGAGTCAATTAAAGAGGGCAAAATTTTCTCAAAAGACCATGGTGCATATGACGATAGCTTTAGTAGTATGGATTGGGCTCTTCTTTCATGGATGTTATTCAGAAGGAGTGATATATCGAGGTGTTTGAAACACCAGCGACACCAGAAGGCTGTGGATGTTAAATCGTAGAACCTATAGACGAGTTCTAAAATATACTTTGGGGTTTTCAGCGATGCAAAA".as_bytes(), false, false, None, None, Some("Sample Query")).unwrap();
assert!(mappings.len() > 0);
let mappings = aligner_.map("ACGGTAGAGAGGAAGAAGAAGGAATAGCGGACTTGTGTATTTTATCGTCATTCGTGGTTATCATATAGTTTATTGATTTGAAGACTACGTAAGTAATTTGAGGACTGATTAAAATTTTCTTTTTTAGCTTAGAGTCAATTAAAGAGGGCAAAATTTTCTCAAAAGACCATGGTGCATATGACGATAGCTTTAGTAGTATGGATTGGGCTCTTCTTTCATGGATGTTATTCAGAAGGAGTGATATATCGAGGTGTTTGAAACACCAGCGACACCAGAAGGCTGTGGATGTTAAATCGTAGAACCTATAGACGAGTTCTAAAATATACTTTGGGGTTTTCAGCGATGCAAAA".as_bytes(), false, false, None, None, Some("Sample Query")).unwrap();
assert!(mappings.len() > 0);
// Sleep 100ms
std::thread::sleep(std::time::Duration::from_millis(100));
});

jh0.join().unwrap();
jh1.join().unwrap();
});

println!("Past the first one");

// Create a new aligner
let aligner = Aligner::builder().map_ont().with_index("yeast_ref.mmi", None).unwrap();

// Perform a test mapping to ensure the index is loaded and all
let mappings = aligner.map("ACGGTAGAGAGGAAGAAGAAGGAATAGCGGACTTGTGTATTTTATCGTCATTCGTGGTTATCATATAGTTTATTGATTTGAAGACTACGTAAGTAATTTGAGGACTGATTAAAATTTTCTTTTTTAGCTTAGAGTCAATTAAAGAGGGCAAAATTTTCTCAAAAGACCATGGTGCATATGACGATAGCTTTAGTAGTATGGATTGGGCTCTTCTTTCATGGATGTTATTCAGAAGGAGTGATATATCGAGGTGTTTGAAACACCAGCGACACCAGAAGGCTGTGGATGTTAAATCGTAGAACCTATAGACGAGTTCTAAAATATACTTTGGGGTTTTCAGCGATGCAAAA".as_bytes(), false, false, None, None, Some("Sample Query")).unwrap();
assert!(mappings.len() > 0);

// Spawn two threads using thread scoped aligners, clone aligner
std::thread::scope(|s| {
let aligner0 = aligner.clone();
let aligner1 = aligner.clone();

// Force drop logic
drop(aligner);

let jh0 = s.spawn(move || {
println!("First thread");
let mappings = aligner0.map("ACGGTAGAGAGGAAGAAGAAGGAATAGCGGACTTGTGTATTTTATCGTCATTCGTGGTTATCATATAGTTTATTGATTTGAAGACTACGTAAGTAATTTGAGGACTGATTAAAATTTTCTTTTTTAGCTTAGAGTCAATTAAAGAGGGCAAAATTTTCTCAAAAGACCATGGTGCATATGACGATAGCTTTAGTAGTATGGATTGGGCTCTTCTTTCATGGATGTTATTCAGAAGGAGTGATATATCGAGGTGTTTGAAACACCAGCGACACCAGAAGGCTGTGGATGTTAAATCGTAGAACCTATAGACGAGTTCTAAAATATACTTTGGGGTTTTCAGCGATGCAAAA".as_bytes(), false, false, None, None, Some("Sample Query")).unwrap();
assert!(mappings.len() > 0);
// Sleep 100ms
std::thread::sleep(std::time::Duration::from_millis(100));
println!("First thread done");
println!("First thread done");
});

// Join, to force drop logic from external thread
// Join, to force drop logic from external thread
jh0.join().unwrap();

Expand Down Expand Up @@ -2122,11 +2061,19 @@ mod tests {
assert!(mappings.len() > 0);
// Sleep 100ms
std::thread::sleep(std::time::Duration::from_millis(100));
assert!(Arc::strong_count(&aligner1.idx.as_ref().unwrap()) == 1);
println!("Second thread done");
});

// Join, to force drop logic from external thread
jh0.join().unwrap();

let jh1 = s.spawn(move || {
println!("Second thread - No mapping");
std::thread::sleep(std::time::Duration::from_millis(200));
let mappings = aligner1.map("ACGGTAGAGAGGAAGAAGAAGGAATAGCGGACTTGTGTATTTTATCGTCATTCGTGGTTATCATATAGTTTATTGATTTGAAGACTACGTAAGTAATTTGAGGACTGATTAAAATTTTCTTTTTTAGCTTAGAGTCAATTAAAGAGGGCAAAATTTTCTCAAAAGACCATGGTGCATATGACGATAGCTTTAGTAGTATGGATTGGGCTCTTCTTTCATGGATGTTATTCAGAAGGAGTGATATATCGAGGTGTTTGAAACACCAGCGACACCAGAAGGCTGTGGATGTTAAATCGTAGAACCTATAGACGAGTTCTAAAATATACTTTGGGGTTTTCAGCGATGCAAAA".as_bytes(), false, false, None, None, Some("Sample Query")).unwrap();
assert!(mappings.len() > 0);
// Sleep 100ms
std::thread::sleep(std::time::Duration::from_millis(100));
});

jh1.join().unwrap();
});
Expand All @@ -2144,5 +2091,4 @@ mod tests {
let aligner_clone = aligner.clone();
assert_eq!(aligner_clone.mapopt.flag & MM_F_CIGAR as i64, MM_F_CIGAR as i64);
}

}

0 comments on commit fbdcb7d

Please sign in to comment.