[to #48891422] fix PL C interface allocator

This commit is contained in:
0xacc
2023-04-26 12:50:16 +00:00
committed by ob-robot
parent 18a5789477
commit 1ec41795d6
7 changed files with 135 additions and 88 deletions

View File

@ -24,23 +24,60 @@ using namespace common;
namespace pl
{
class ObPlExecCtx;
struct ObPLInterface {
const char* name;
void* entry;
PL_C_INTERFACE_t entry;
};
template <typename U, U func>
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.
// any other signature will yield a compile-time error.
using T3 = int (&)(ObExecContext &, ParamStore &, ObObj &);
using T4 = int (&)(ObExecContext &, ParamStore &, ObObj &, ObPLExecCtx &);
template <typename T, T v>
struct interface_checker_helper {}; // dummy type
template <T3 v>
struct interface_checker_helper<T3, v> {
static int value(ObExecContext &exec_ctx, ParamStore &param, ObObj &obj,
ObPLExecCtx &) {
return v(exec_ctx, param, obj);
}
};
template <T4 v>
struct interface_checker_helper<T4, v> {
static int value(ObExecContext &exec_ctx, ParamStore &param, ObObj &obj,
ObPLExecCtx &pl_exec_ctx) {
return v(exec_ctx, param, obj, pl_exec_ctx);
}
};
// for nullptr interface compatibility
template <nullptr_t v>
struct interface_checker_helper<nullptr_t, v> {
static constexpr PL_C_INTERFACE_t value = nullptr;
};
static constexpr PL_C_INTERFACE_t value = interface_checker_helper<U, func>::value;
};
static const ObPLInterface OB_PL_INTERFACE[INTERFACE_END +1] =
{
#define INTERFACE_DEF(type, name, entry) {name, entry},
#define INTERFACE_DEF(type, name, entry) {name, interface_checker<decltype(entry), entry>::value},
#include "pl/ob_pl_interface_pragma.h"
#undef INTERFACE_DEF
};
void *ObPLInterfaceService::get_entry(ObString &name) const
PL_C_INTERFACE_t ObPLInterfaceService::get_entry(ObString &name) const
{
int64_t idx = get_type(name);
void *entry_res = NULL;
PL_C_INTERFACE_t entry_res = nullptr;
if (idx >= 0 && idx < sizeof(OB_PL_INTERFACE)/sizeof(ObPLInterface)) {
entry_res = OB_PL_INTERFACE[idx].entry;
}