From ee0f118156dceb7cc9b4272c443f27526c2cdbc7 Mon Sep 17 00:00:00 2001 From: Keyvan Kambakhsh Date: Tue, 29 Oct 2019 02:10:08 +0330 Subject: [PATCH] Platform::list() return OclResult instead of panicking --- ocl-interop/src/lib.rs | 2 +- ocl/examples/opencl_2_1/src/main.rs | 4 +--- ocl/src/standard/platform.rs | 7 +++---- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/ocl-interop/src/lib.rs b/ocl-interop/src/lib.rs index 73ef2116d..b0653bee1 100644 --- a/ocl-interop/src/lib.rs +++ b/ocl-interop/src/lib.rs @@ -52,7 +52,7 @@ pub fn get_properties_list() -> ocl::builders::ContextProperties { } pub fn get_context() -> std::option::Option { - ocl::Platform::list() + ocl::Platform::list().unwrap() .iter() .map(|plat| { //println!("Plat: {}",plat); diff --git a/ocl/examples/opencl_2_1/src/main.rs b/ocl/examples/opencl_2_1/src/main.rs index d439bfba8..2a13c6798 100644 --- a/ocl/examples/opencl_2_1/src/main.rs +++ b/ocl/examples/opencl_2_1/src/main.rs @@ -32,7 +32,7 @@ fn main() -> Result<(), ocl::Error> { println!("Choosing platorm..."); #[cfg(feature = "opencl_version_2_1")] - let platform = Platform::list().into_iter().find(|plat| plat.name().unwrap() == PLATFORM_NAME) + let platform = Platform::list().unwrap().into_iter().find(|plat| plat.name().unwrap() == PLATFORM_NAME) .unwrap_or(Platform::default()); #[cfg(not(feature = "opencl_version_2_1"))] @@ -97,5 +97,3 @@ fn main() -> Result<(), ocl::Error> { // println!("The value at index [{}] is now '{}'!", 200007, vec[200007]); Ok(()) } - - diff --git a/ocl/src/standard/platform.rs b/ocl/src/standard/platform.rs index cd8968005..8c6bb6e7c 100644 --- a/ocl/src/standard/platform.rs +++ b/ocl/src/standard/platform.rs @@ -45,11 +45,10 @@ pub struct Platform(PlatformIdCore); impl Platform { /// Returns a list of all platforms avaliable on the host machine. - pub fn list() -> Vec { - let list_core = core::get_platform_ids() - .expect("Platform::list: Error retrieving platform list"); + pub fn list() -> OclResult> { + let list_core = core::get_platform_ids()?; - list_core.into_iter().map(Platform::new).collect() + Ok(list_core.into_iter().map(Platform::new).collect()) } /// Returns the first available platform.