Skip to content

Commit d988b36

Browse files
fix
1 parent b0da77f commit d988b36

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

profiling/src/bindings/mod.rs

+5
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

+1-8
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

zend_abstract_interface/zai_string/string.c

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
char *ZAI_STRING_EMPTY_PTR = "";
44

5+
extern inline zai_str zai_str_from_cstr(const char *cstr);
6+
57
extern inline zai_str zai_str_from_zstr(zend_string *zstr);
68

79
extern inline zai_string zai_string_concat3(zai_str first, zai_str second, zai_str third);

zend_abstract_interface/zai_string/string.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ static inline zai_str zai_str_new(const char *ptr, size_t len) {
7575
*
7676
* If the pointer is known to be non-null, use ZAI_STR_FROM_CSTR directly.
7777
*/
78-
static inline zai_str zai_str_from_cstr(const char *cstr) {
78+
inline zai_str zai_str_from_cstr(const char *cstr) {
7979
if (cstr) {
8080
return (zai_str)ZAI_STR_FROM_CSTR(cstr);
8181
}

0 commit comments

Comments
 (0)