Skip to content

Commit fdc11a7

Browse files
fix
1 parent b0da77f commit fdc11a7

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

profiling/src/bindings/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,11 @@ extern "C" {
317317
#[cfg(php7)]
318318
pub fn zend_register_extension(extension: &ZendExtension, handle: *mut c_void) -> ZendResult;
319319

320+
/// Converts the `const char *` into a `zai_str`. A None as well as empty
321+
/// strings will be converted into a string view to a static empty string
322+
/// (single byte of null, len of 0).
323+
pub fn zai_str_from_cstr(cstr: *const c_char) -> zai_str<'static>;
324+
320325
/// Converts the `zstr` into a `zai_str`. A None as well as empty
321326
/// strings will be converted into a string view to a static empty string
322327
/// (single byte of null, len of 0).

profiling/src/timeline.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -204,14 +204,7 @@ unsafe extern "C" fn ddog_php_prof_zend_error_observer(
204204
}
205205

206206
#[cfg(zend_error_observer_80)]
207-
let file = unsafe {
208-
let mut len = 0;
209-
let file = file as *const u8;
210-
while *file.add(len) != 0 {
211-
len += 1;
212-
}
213-
std::str::from_utf8_unchecked(std::slice::from_raw_parts(file, len)).to_string()
214-
};
207+
let file = unsafe { zend::zai_str_from_cstr(file).into_string() };
215208
#[cfg(not(zend_error_observer_80))]
216209
let file = unsafe { zend::zai_str_from_zstr(file.as_mut()).into_string() };
217210

0 commit comments

Comments
 (0)