diff options
-rwxr-xr-x | src/clang.rs | 17 | ||||
-rw-r--r-- | src/ir/annotations.rs | 2 | ||||
-rw-r--r-- | src/ir/ty.rs | 2 | ||||
-rw-r--r-- | tests/tests.rs | 28 |
4 files changed, 32 insertions, 17 deletions
diff --git a/src/clang.rs b/src/clang.rs index 8e1ec258..3d87dccd 100755 --- a/src/clang.rs +++ b/src/clang.rs @@ -678,9 +678,12 @@ impl Type { /// Given that this type is an array or vector type, return its number of /// elements. - pub fn num_elements(&self) -> usize { - unsafe { - clang_getNumElements(self.x) as usize + pub fn num_elements(&self) -> Option<usize> { + let num_elements_returned = unsafe { clang_getNumElements(self.x) }; + if num_elements_returned != -1 { + Some(num_elements_returned as usize) + } else { + None } } @@ -793,9 +796,11 @@ impl Comment { } /// Get this comment's `idx`th child comment - pub fn get_child(&self, idx: c_uint) -> Comment { - unsafe { - Comment { x: clang_Comment_getChild(self.x, idx) } + pub fn get_child(&self, idx: c_uint) -> Option<Comment> { + if idx >= self.num_children() { + None + } else { + Some(Comment { x: unsafe { clang_Comment_getChild(self.x, idx) } }) } } diff --git a/src/ir/annotations.rs b/src/ir/annotations.rs index f0d9715e..d276608f 100644 --- a/src/ir/annotations.rs +++ b/src/ir/annotations.rs @@ -153,7 +153,7 @@ impl Annotations { } for i in 0..comment.num_children() { - self.parse(&comment.get_child(i), matched); + self.parse(&comment.get_child(i).unwrap(), matched); } } } diff --git a/src/ir/ty.rs b/src/ir/ty.rs index 09059528..c55d7622 100644 --- a/src/ir/ty.rs +++ b/src/ir/ty.rs @@ -681,7 +681,7 @@ impl Type { CXType_ConstantArray => { let inner = Item::from_ty(&ty.elem_type(), location, parent_id, ctx) .expect("Not able to resolve array element?"); - TypeKind::Array(inner, ty.num_elements()) + TypeKind::Array(inner, ty.num_elements().unwrap()) } // A complex number is always a real and an imaginary part, so // represent that as a two-item array. diff --git a/tests/tests.rs b/tests/tests.rs index 1f8864e0..003c0f1a 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -10,6 +10,8 @@ use std::io::Read; use std::path::{Path, PathBuf}; use std::process; +const TEST_BATCH_DEFAULT_SIZE: usize = 16; + fn spawn_run_bindgen<P, Q, R>(run_bindgen: P, bindgen: Q, header: R) -> process::Child where P: AsRef<Path>, Q: AsRef<Path>, @@ -83,25 +85,33 @@ fn run_bindgen_tests() { Some(Some("hpp")) => true, _ => false, } - }); + }).collect::<Vec<_>>(); + + let batch_size = env::var("BINDGEN_TEST_BATCH_SIZE") + .ok() + .and_then(|x| x.parse::<usize>().ok()) + .unwrap_or(TEST_BATCH_DEFAULT_SIZE); - // Spawn one child at a time and wait on it as number of process - // is the number of test files. + // Spawn batch_size child to run in parallel + // and wait on all of them before processing the next batch - let children = tests.map(|entry| { - let child = spawn_run_bindgen(run_bindgen.clone(), bindgen.clone(), entry.path()); - (entry.path(), child) + let children = tests.chunks(batch_size).map(|x| { + x.iter().map(|entry| { + let child = spawn_run_bindgen(run_bindgen.clone(), bindgen.clone(), entry.path()); + (entry.path(), child) + }).collect::<Vec<_>>() }); - let failures: Vec<_> = children - .filter_map(|(path, mut child)| { + let failures: Vec<_> = children.flat_map(|x| { + x.into_iter().filter_map(|(path, mut child)| { let passed = child.wait() .expect("Should wait on child process") .success(); if passed { None } else { Some((path, child)) } }) - .collect(); + }) + .collect(); let num_failures = failures.len(); |