[to #48891422] update PL C interface signature

This commit is contained in:
0xacc
2023-04-26 15:02:30 +00:00
committed by ob-robot
parent aa50359fed
commit ffb125d10e
3 changed files with 20 additions and 13 deletions

View File

@ -16,6 +16,7 @@
#include "share/ob_errno.h" #include "share/ob_errno.h"
#include "lib/utility/ob_macro_utils.h" #include "lib/utility/ob_macro_utils.h"
#include "lib/oblog/ob_log_module.h" #include "lib/oblog/ob_log_module.h"
#include "pl/ob_pl.h"
namespace oceanbase namespace oceanbase
{ {
@ -24,7 +25,6 @@ using namespace common;
namespace pl namespace pl
{ {
class ObPlExecCtx;
struct ObPLInterface { struct ObPLInterface {
const char* name; const char* name;
PL_C_INTERFACE_t entry; PL_C_INTERFACE_t entry;
@ -33,28 +33,35 @@ struct ObPLInterface {
template <typename U, U func> template <typename U, U func>
struct interface_checker { struct interface_checker {
// only these types are allowed for PL C interfaces. // only these types are allowed for PL C interfaces.
// T3 is for compatibility and deprecated. // T3, T4 is for compatibility and deprecated.
// using T4 as interface signature is encouraged. // using T_INTERFACE as interface signature is encouraged.
// any other signature will yield a compile-time error. // any other signature will yield a compile-time error.
using T3 = int (&)(ObExecContext &, ParamStore &, ObObj &); using T3 = int(&)(ObExecContext &, ParamStore &, ObObj &);
using T4 = int (&)(ObExecContext &, ParamStore &, ObObj &, ObPLExecCtx &); using T4 = int(&)(ObExecContext &, ParamStore &, ObObj &, ObPLExecCtx &);
using T_INTERFACE = int(&)(ObPLExecCtx &, ParamStore &, ObObj&);
template <typename T, T v> template <typename T, T v>
struct interface_checker_helper {}; // dummy type struct interface_checker_helper {}; // dummy type
template <T3 v> template <T3 v>
struct interface_checker_helper<T3, v> { struct interface_checker_helper<T3, v> {
static int value(ObExecContext &exec_ctx, ParamStore &param, ObObj &obj, static int value(ObPLExecCtx &pl_exec_ctx, ParamStore &param, ObObj &obj) {
ObPLExecCtx &) { return v(*pl_exec_ctx.exec_ctx_, param, obj);
return v(exec_ctx, param, obj);
} }
}; };
template <T4 v> template <T4 v>
struct interface_checker_helper<T4, v> { struct interface_checker_helper<T4, v> {
static int value(ObExecContext &exec_ctx, ParamStore &param, ObObj &obj, static int value(ObPLExecCtx &pl_exec_ctx, ParamStore &param, ObObj &obj) {
ObPLExecCtx &pl_exec_ctx) { return v(*pl_exec_ctx.exec_ctx_, param, obj, pl_exec_ctx);
return v(exec_ctx, param, obj, pl_exec_ctx); }
};
template <T_INTERFACE v>
struct interface_checker_helper<T_INTERFACE, v>{
static_assert(std::is_same<decltype(&v),PL_C_INTERFACE_t>::value, "T_INTERFACE and PL_C_INTERFACE_t do not match");
static int value(ObPLExecCtx &pl_exec_ctx, ParamStore &param, ObObj &obj) {
return v(pl_exec_ctx, param, obj);
} }
}; };

View File

@ -137,7 +137,7 @@ namespace oceanbase
namespace pl namespace pl
{ {
typedef int(*PL_C_INTERFACE_t)(ObExecContext&, ParamStore&, ObObj&, ObPLExecCtx&); typedef int(*PL_C_INTERFACE_t)(ObPLExecCtx&, ParamStore&, ObObj&);
enum ObPLInterfaceType enum ObPLInterfaceType
{ {

View File

@ -4846,7 +4846,7 @@ int ObSPIService::spi_interface_impl(pl::ObPLExecCtx *ctx, const char *interface
ObString name(interface_name); ObString name(interface_name);
PL_C_INTERFACE_t fp = GCTX.pl_engine_->get_interface_service().get_entry(name); PL_C_INTERFACE_t fp = GCTX.pl_engine_->get_interface_service().get_entry(name);
if (nullptr != fp) { if (nullptr != fp) {
ret = fp(*ctx->exec_ctx_, *ctx->params_, *ctx->result_, *ctx); ret = fp(*ctx, *ctx->params_, *ctx->result_);
} else { } else {
ret = OB_ERR_UNEXPECTED; ret = OB_ERR_UNEXPECTED;
LOG_WARN("Calling C interface which doesn't exist", K(interface_name), K(name)); LOG_WARN("Calling C interface which doesn't exist", K(interface_name), K(name));