Skip to content

Commit

Permalink
Update otel_observer.c fix for windows build
Browse files Browse the repository at this point in the history
  • Loading branch information
wantedxnn authored Sep 20, 2023
1 parent eb0812b commit 5fd1821
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions ext/otel_observer.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,25 @@ static void log_invalid_message(char *msg, zval *scope, zval *function) {
s = Z_STRVAL_P(scope);
}
char *f = Z_STRVAL_P(function);
char formatted[strlen(msg) + strlen(s) + strlen(f) + 1];
snprintf(formatted, sizeof(formatted), msg, s, f);

// Calculate the size of the formatted message.
int formatted_size = strlen(msg) + strlen(s) + strlen(f) + 1;

// Allocate a buffer for the formatted message.
char *formatted = malloc(formatted_size);
if (formatted == NULL) {
php_log_err("OpenTelemetry: Failed to allocate memory for formatted message.");
return;
}

// Format the message.
snprintf(formatted, formatted_size, msg, s, f);

// Log the message.
php_log_err(formatted);

// Free the allocated memory.
free(formatted);
}

static void observer_begin(zend_execute_data *execute_data, zend_llist *hooks) {
Expand All @@ -218,8 +233,8 @@ static void observer_begin(zend_execute_data *execute_data, zend_llist *hooks) {

for (zend_llist_element *element = hooks->head; element;
element = element->next) {
zend_fcall_info fci = {};
zend_fcall_info_cache fcc = {};
zend_fcall_info fci = empty_fcall_info;
zend_fcall_info_cache fcc = empty_fcall_info_cache;
zend_function *func = execute_data->func; // the observed function
if (UNEXPECTED(zend_fcall_info_init((zval *)element->data, 0, &fci,
&fcc, NULL, NULL) != SUCCESS)) {
Expand Down Expand Up @@ -337,8 +352,8 @@ static void observer_end(zend_execute_data *execute_data, zval *retval,

for (zend_llist_element *element = hooks->tail; element;
element = element->prev) {
zend_fcall_info fci = {};
zend_fcall_info_cache fcc = {};
zend_fcall_info fci = empty_fcall_info;
zend_fcall_info_cache fcc = empty_fcall_info_cache;
if (UNEXPECTED(zend_fcall_info_init((zval *)element->data, 0, &fci,
&fcc, NULL, NULL) != SUCCESS)) {
continue;
Expand Down

0 comments on commit 5fd1821

Please sign in to comment.