diff options
-rwxr-xr-x | src/clang.rs | 22 | ||||
-rw-r--r-- | src/ir/function.rs | 3 | ||||
-rw-r--r-- | src/ir/ty.rs | 4 | ||||
-rw-r--r-- | tests/tests.rs | 28 |
4 files changed, 38 insertions, 19 deletions
diff --git a/src/clang.rs b/src/clang.rs index ae4a3f44..c48b45d5 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 } } @@ -714,9 +717,12 @@ impl Type { /// Given that this type is a function type, get the type of its return /// value. - pub fn ret_type(&self) -> Type { - unsafe { - Type { x: clang_getResultType(self.x) } + pub fn ret_type(&self) -> Option<Type> { + let rt = Type { x: unsafe { clang_getResultType(self.x) } }; + if rt.kind() == CXType_Invalid { + None + } else { + Some(rt) } } @@ -1044,9 +1050,11 @@ impl Diagnostic { clang_getDiagnosticSeverity(self.x) } } +} +impl Drop for Diagnostic { /// Destroy this diagnostic message. - pub fn dispose(&self) { + fn drop(&mut self) { unsafe { clang_disposeDiagnostic(self.x); } diff --git a/src/ir/function.rs b/src/ir/function.rs index 2693eddf..0cf23f43 100644 --- a/src/ir/function.rs +++ b/src/ir/function.rs @@ -186,7 +186,8 @@ impl FunctionSig { } } - let ret = try!(Item::from_ty(&ty.ret_type(), None, None, ctx)); + let ty_ret_type = try!(ty.ret_type().ok_or(ParseError::Continue)); + let ret = try!(Item::from_ty(&ty_ret_type, None, None, ctx)); let abi = get_abi(ty.call_conv()); Ok(Self::new(ret, args, ty.is_variadic(), abi)) diff --git a/src/ir/ty.rs b/src/ir/ty.rs index 09059528..71512c31 100644 --- a/src/ir/ty.rs +++ b/src/ir/ty.rs @@ -500,7 +500,7 @@ impl Type { // tests/headers/func_ptr_in_struct.h), so we do a // guess here trying to see if it has a valid return // type. - if ty.ret_type().kind() != CXType_Invalid { + if ty.ret_type().is_some() { let signature = try!(FunctionSig::from_ty(ty, &location.unwrap_or(cursor), ctx)); TypeKind::Function(signature) @@ -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(); |