Skip to content

Retrieving a program build log might be impossible #8

@vmx

Description

@vmx

The build log of a program might contain nul characters. Currently if it does, there is no way to retrieve the log as Program::get_build_log() only returns Err(-9999) ( CSTRING_UTF8_CONVERSION_ERROR) when it encounters a nul.

A potential fix could be something along the lines of the following code, which strips away all nul characters.

diff --git a/src/program.rs b/src/program.rs
index 7cd8541..3b8271c 100644
--- a/src/program.rs
+++ b/src/program.rs
@@ -304,7 +304,14 @@ impl Program {
     pub fn get_build_log(&self, device: cl_device_id) -> Result<CString, cl_int> {
         get_program_build_info(self.program, device, ProgramBuildInfo::CL_PROGRAM_BUILD_LOG)?
             .to_str()
-            .map_err(|_| error_codes::CSTRING_UTF8_CONVERSION_ERROR)
+            .or_else(|nul_error| {
+                Ok(CString::new(
+                    std::str::from_utf8(&nul_error.into_vec())
+                        .unwrap()
+                        .replace('\0', ""),
+                )
+                .unwrap())
+            })
     }
 
     pub fn get_build_binary_type(&self, device: cl_device_id) -> Result<cl_uint, cl_int> {

When reading the spec it also seems that usually strings don't contain any nul characters within the string (and if they could (like CL_PROGRAM_SOURCE they are stripped away. So it won't make sense to change the general approach of returning Cstrings.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions