Skip to content

Commit

Permalink
Clean C Code further
Browse files Browse the repository at this point in the history
  • Loading branch information
PROFeNoM committed Dec 20, 2024
1 parent 3da77fa commit 12bff4c
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 42 deletions.
10 changes: 10 additions & 0 deletions ext/compatibility.h
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,16 @@ static zend_always_inline zend_result zend_call_function_with_return_value(zend_

#define Z_PARAM_ZVAL_OR_NULL(dest) Z_PARAM_ZVAL_EX(dest, 1, 0)

#ifndef Z_PARAM_STRING_OR_NULL
#define Z_PARAM_STRING_OR_NULL(dest, dest_len) \
Z_PARAM_STRING_EX(dest, dest_len, 1, 0)
#endif

#ifndef Z_PARAM_STR_OR_NULL
#define Z_PARAM_STR_OR_NULL(dest) \
Z_PARAM_STR_EX(dest, 1, 0)
#endif

#define ZEND_GUARD_PROPERTY_MASK 0xf

// strip const
Expand Down
74 changes: 32 additions & 42 deletions ext/handlers_kafka.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,6 @@

ZEND_EXTERN_MODULE_GLOBALS(ddtrace);

#ifndef Z_PARAM_STRING_OR_NULL
#define Z_PARAM_STRING_OR_NULL(dest, dest_len) \
Z_PARAM_STRING_EX(dest, dest_len, 1, 0)
#endif

#ifndef Z_PARAM_STR_OR_NULL
#define Z_PARAM_STR_OR_NULL(dest) \
Z_PARAM_STR_EX(dest, 1, 0)
#endif

#define MAX_PRODUCEV_ARGS 7

// True global - only modify during MINIT/MSHUTDOWN
Expand Down Expand Up @@ -49,38 +39,38 @@ static void dd_initialize_producev_args(zval* args, zend_long partition, zend_lo
}

ZEND_FUNCTION(ddtrace_kafka_produce) {
if (!dd_load_kafka_integration()) {
// Call the original handler
dd_kafka_produce_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU);
return;
}

zend_long partition, msgflags;
char* payload = NULL;
size_t payload_len = 0;
char* key = NULL;
size_t key_len = 0;
zend_string* opaque = NULL;

ZEND_PARSE_PARAMETERS_START(2, 4 + opaque_param)
Z_PARAM_LONG(partition)
Z_PARAM_LONG(msgflags)
Z_PARAM_OPTIONAL
Z_PARAM_STRING_OR_NULL(payload, payload_len)
Z_PARAM_STRING_OR_NULL(key, key_len)
Z_PARAM_STR_OR_NULL(opaque)
ZEND_PARSE_PARAMETERS_END();

zval args[MAX_PRODUCEV_ARGS];
dd_initialize_producev_args(args, partition, msgflags, payload, payload_len, key, key_len, opaque);

zval function_name;
ZVAL_STRING(&function_name, "producev");
call_user_function(NULL, getThis(), &function_name, return_value, 6 + opaque_param, args);
zval_dtor(&function_name);

zend_string_release(Z_STR(args[2]));
zend_string_release(Z_STR(args[3]));
if (!dd_load_kafka_integration()) {
// Call the original handler
dd_kafka_produce_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU);
return;
}

zend_long partition, msgflags;
char* payload = NULL;
size_t payload_len = 0;
char* key = NULL;
size_t key_len = 0;
zend_string* opaque = NULL;

ZEND_PARSE_PARAMETERS_START(2, 4 + opaque_param)
Z_PARAM_LONG(partition)
Z_PARAM_LONG(msgflags)
Z_PARAM_OPTIONAL
Z_PARAM_STRING_OR_NULL(payload, payload_len)
Z_PARAM_STRING_OR_NULL(key, key_len)
Z_PARAM_STR_OR_NULL(opaque)
ZEND_PARSE_PARAMETERS_END();

zval args[MAX_PRODUCEV_ARGS];
dd_initialize_producev_args(args, partition, msgflags, payload, payload_len, key, key_len, opaque);

zval function_name;
ZVAL_STRING(&function_name, "producev");
call_user_function(NULL, getThis(), &function_name, return_value, 6 + opaque_param, args);
zval_dtor(&function_name);

zend_string_release(Z_STR(args[2]));
zend_string_release(Z_STR(args[3]));
}

/**
Expand Down

0 comments on commit 12bff4c

Please sign in to comment.