diff --git a/profiling/build.rs b/profiling/build.rs index 471a0b52c95..e174c8add42 100644 --- a/profiling/build.rs +++ b/profiling/build.rs @@ -313,6 +313,9 @@ fn cfg_trigger_time_sample() -> bool { fn cfg_zend_error_observer(vernum: u64) -> bool { if vernum >= 80000 { println!("cargo:rustc-cfg=zend_error_observer"); + if vernum < 80100 { + println!("cargo:rustc-cfg=zend_error_observer_80"); + } true } else { false diff --git a/profiling/src/timeline.rs b/profiling/src/timeline.rs index 93ee1d7eca3..33c03b89dd2 100644 --- a/profiling/src/timeline.rs +++ b/profiling/src/timeline.rs @@ -152,7 +152,8 @@ unsafe extern "C" fn ddog_php_prof_frankenphp_handle_request( #[cfg(zend_error_observer)] unsafe extern "C" fn ddog_php_prof_zend_error_observer( _type: i32, - file: *mut zend::ZendString, + #[cfg(zend_error_observer_80)] file: *const i8, + #[cfg(not(zend_error_observer_80))] file: *mut zend::ZendString, line: u32, message: *mut zend::ZendString, ) { @@ -161,15 +162,24 @@ unsafe extern "C" fn ddog_php_prof_zend_error_observer( return; } + #[cfg(zend_error_observer_80)] + let file = unsafe { + let mut len = 0; + let file = file as *const u8; + while *file.add(len) != 0 { + len += 1; + } + std::str::from_utf8_unchecked(std::slice::from_raw_parts(file, len)).to_string() + }; + #[cfg(not(zend_error_observer_80))] + let file = unsafe { zend::zai_str_from_zstr(file.as_mut()).into_string() }; + let now = SystemTime::now().duration_since(UNIX_EPOCH).unwrap(); if let Some(profiler) = Profiler::get() { let now = now.as_nanos() as i64; - profiler.collect_fatal( - now, - unsafe { zend::zai_str_from_zstr(file.as_mut()).into_string() }, - line, - unsafe { zend::zai_str_from_zstr(message.as_mut()).into_string() }, - ); + profiler.collect_fatal(now, file, line, unsafe { + zend::zai_str_from_zstr(message.as_mut()).into_string() + }); } }