Skip to content

Commit

Permalink
Enhance interceptor code in rayaop.c
Browse files Browse the repository at this point in the history
This update significantly expands the interceptor code within the src/rayaop.c file. The changes provide functionality for handling NULL objects and setting parameters for the intercept handler. If the intercept handler's function call is successful, the return value is copied. If it's unsuccessful, an error message is generated. Some code cleanup steps have been also added after completing these operations.
  • Loading branch information
koriym committed Jun 27, 2024
1 parent ab8180d commit 6b44e8f
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion src/rayaop.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,49 @@ static void rayaop_zend_execute_ex(zend_execute_data *execute_data)

// インターセプト処理のコード
if (Z_TYPE(info->handler) == IS_OBJECT) {
// ... (インターセプト処理のコード)
zval retval, params[3];

// オブジェクトが NULL の場合は元の関数を実行
if (execute_data->This.value.obj == NULL) {
original_zend_execute_ex(execute_data);
return;
}

// インターセプトハンドラーへのパラメータ設定
ZVAL_OBJ(&params[0], execute_data->This.value.obj);
ZVAL_STR(&params[1], method_name);

array_init(&params[2]);
uint32_t arg_count = ZEND_CALL_NUM_ARGS(execute_data);
zval *args = ZEND_CALL_ARG(execute_data, 1);
for (uint32_t i = 0; i < arg_count; i++) {
zval *arg = &args[i];
Z_TRY_ADDREF_P(arg);
add_next_index_zval(&params[2], arg);
}

is_intercepting = 1;
zval func_name;
ZVAL_STRING(&func_name, "intercept");

// インターセプトハンドラーの呼び出し
ZVAL_UNDEF(&retval);
if (call_user_function(NULL, &info->handler, &func_name, &retval, 3, params) == SUCCESS) {
if (!Z_ISUNDEF(retval)) {
ZVAL_COPY(execute_data->return_value, &retval);
}
zval_ptr_dtor(&retval);
} else {
php_error_docref(NULL, E_WARNING, "Interception failed for %s::%s", ZSTR_VAL(class_name), ZSTR_VAL(method_name));
}

// クリーンアップ
zval_ptr_dtor(&func_name);
zval_ptr_dtor(&params[1]);
zval_ptr_dtor(&params[2]);

is_intercepting = 0;
return;
}
} else {
RAYAOP_DEBUG_PRINT("No intercept info found for key: %s", key);
Expand Down

0 comments on commit 6b44e8f

Please sign in to comment.