diff --git a/src/pl/ob_pl_interface_pragma.cpp b/src/pl/ob_pl_interface_pragma.cpp index 3da5c96ca..ba4c92813 100644 --- a/src/pl/ob_pl_interface_pragma.cpp +++ b/src/pl/ob_pl_interface_pragma.cpp @@ -16,6 +16,7 @@ #include "share/ob_errno.h" #include "lib/utility/ob_macro_utils.h" #include "lib/oblog/ob_log_module.h" +#include "pl/ob_pl.h" namespace oceanbase { @@ -24,7 +25,6 @@ using namespace common; namespace pl { -class ObPlExecCtx; struct ObPLInterface { const char* name; PL_C_INTERFACE_t entry; @@ -33,28 +33,35 @@ struct ObPLInterface { template struct interface_checker { // only these types are allowed for PL C interfaces. - // T3 is for compatibility and deprecated. - // using T4 as interface signature is encouraged. + // T3, T4 is for compatibility and deprecated. + // using T_INTERFACE as interface signature is encouraged. // any other signature will yield a compile-time error. - using T3 = int (&)(ObExecContext &, ParamStore &, ObObj &); - using T4 = int (&)(ObExecContext &, ParamStore &, ObObj &, ObPLExecCtx &); + using T3 = int(&)(ObExecContext &, ParamStore &, ObObj &); + using T4 = int(&)(ObExecContext &, ParamStore &, ObObj &, ObPLExecCtx &); + using T_INTERFACE = int(&)(ObPLExecCtx &, ParamStore &, ObObj&); template struct interface_checker_helper {}; // dummy type template struct interface_checker_helper { - static int value(ObExecContext &exec_ctx, ParamStore ¶m, ObObj &obj, - ObPLExecCtx &) { - return v(exec_ctx, param, obj); + static int value(ObPLExecCtx &pl_exec_ctx, ParamStore ¶m, ObObj &obj) { + return v(*pl_exec_ctx.exec_ctx_, param, obj); } }; template struct interface_checker_helper { - static int value(ObExecContext &exec_ctx, ParamStore ¶m, ObObj &obj, - ObPLExecCtx &pl_exec_ctx) { - return v(exec_ctx, param, obj, pl_exec_ctx); + static int value(ObPLExecCtx &pl_exec_ctx, ParamStore ¶m, ObObj &obj) { + return v(*pl_exec_ctx.exec_ctx_, param, obj, pl_exec_ctx); + } + }; + + template + struct interface_checker_helper{ + static_assert(std::is_same::value, "T_INTERFACE and PL_C_INTERFACE_t do not match"); + static int value(ObPLExecCtx &pl_exec_ctx, ParamStore ¶m, ObObj &obj) { + return v(pl_exec_ctx, param, obj); } }; diff --git a/src/pl/ob_pl_interface_pragma.h b/src/pl/ob_pl_interface_pragma.h index 4e735c234..ba74e0067 100644 --- a/src/pl/ob_pl_interface_pragma.h +++ b/src/pl/ob_pl_interface_pragma.h @@ -137,7 +137,7 @@ namespace oceanbase namespace pl { -typedef int(*PL_C_INTERFACE_t)(ObExecContext&, ParamStore&, ObObj&, ObPLExecCtx&); +typedef int(*PL_C_INTERFACE_t)(ObPLExecCtx&, ParamStore&, ObObj&); enum ObPLInterfaceType { diff --git a/src/sql/ob_spi.cpp b/src/sql/ob_spi.cpp index 1d6bf883a..a3c1fa237 100644 --- a/src/sql/ob_spi.cpp +++ b/src/sql/ob_spi.cpp @@ -4846,7 +4846,7 @@ int ObSPIService::spi_interface_impl(pl::ObPLExecCtx *ctx, const char *interface ObString name(interface_name); PL_C_INTERFACE_t fp = GCTX.pl_engine_->get_interface_service().get_entry(name); if (nullptr != fp) { - ret = fp(*ctx->exec_ctx_, *ctx->params_, *ctx->result_, *ctx); + ret = fp(*ctx, *ctx->params_, *ctx->result_); } else { ret = OB_ERR_UNEXPECTED; LOG_WARN("Calling C interface which doesn't exist", K(interface_name), K(name));