MCPcopy Create free account
hub / github.com/WasmEdge/WasmEdge / WasmEdge_TableInstanceCreateWithInit

Function WasmEdge_TableInstanceCreateWithInit

lib/api/wasmedge.cpp:2753–2784  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2751}
2752
2753WASMEDGE_CAPI_EXPORT extern WasmEdge_TableInstanceContext *
2754WasmEdge_TableInstanceCreateWithInit(const WasmEdge_TableTypeContext *TabType,
2755 const WasmEdge_Value Value) noexcept {
2756 try {
2757 if (TabType) {
2758 // Comparison of the value types needs the module instance to retrieve the
2759 // function type index after applying the typed function reference
2760 // proposal. It's impossible to do this without refactoring. Therefore
2761 // simply match the FuncRef and ExternRef here.
2762 const AST::TableType &TType = *fromTabTypeCxt(TabType);
2763 WasmEdge::ValType GotType = genValType(Value.Type);
2764 if (TType.getRefType().isFuncRefType() != GotType.isFuncRefType()) {
2765 spdlog::error(WasmEdge::ErrCode::Value::RefTypeMismatch);
2766 spdlog::error(
2767 WasmEdge::ErrInfo::InfoMismatch(TType.getRefType(), GotType));
2768 return nullptr;
2769 }
2770 auto Val = WasmEdge::ValVariant(
2771 to_WasmEdge_128_t<WasmEdge::uint128_t>(Value.Value))
2772 .get<WasmEdge::RefVariant>();
2773 if (!TType.getRefType().isNullableRefType() && Val.isNull()) {
2774 spdlog::error(WasmEdge::ErrCode::Value::NonNullRequired);
2775 return nullptr;
2776 }
2777 return toTabCxt(
2778 new WasmEdge::Runtime::Instance::TableInstance(TType, Val));
2779 }
2780 } catch (...) {
2781 handleCAPIError();
2782 }
2783 return nullptr;
2784}
2785
2786WASMEDGE_CAPI_EXPORT const WasmEdge_TableTypeContext *
2787WasmEdge_TableInstanceGetTableType(

Callers 1

TESTFunction · 0.85

Calls 8

fromTabTypeCxtFunction · 0.85
InfoMismatchClass · 0.85
handleCAPIErrorFunction · 0.85
isFuncRefTypeMethod · 0.80
isNullableRefTypeMethod · 0.80
isNullMethod · 0.80
genValTypeFunction · 0.70
errorFunction · 0.50

Tested by 1

TESTFunction · 0.68