Skip to content

Commit

Permalink
[MSVC] Fix designated initializer style, keep designated initializer …
Browse files Browse the repository at this point in the history
…in C file.

Signed-off-by: Wang Jikai <[email protected]>
  • Loading branch information
am009 authored and hydai committed Sep 12, 2023
1 parent 50778b1 commit fc31890
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ GETTER(MemoryTypeContext)
JNIEXPORT void JNICALL Java_org_wasmedge_MemoryTypeContext_nativeInit(
JNIEnv *env, jobject thisObject, jboolean jHasMax, jlong jMin, jlong jMax) {

const WasmEdge_Limit limit = {/*.HasMax =*/ jHasMax, /*.Shared =*/ false, /*.Min =*/ jMin, /*.Max =*/ jMax};
const WasmEdge_Limit limit = {.HasMax = jHasMax, .Min = jMin, .Max = jMax};

WasmEdge_MemoryTypeContext *memCxt = WasmEdge_MemoryTypeCreate(limit);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ JNIEXPORT void JNICALL Java_org_wasmedge_TableTypeContext_nativeInit(
jmethodID minMid = (*env)->GetMethodID(env, cls, LIMIT_GET_MIN, VOID_LONG);
jlong min = (*env)->CallLongMethod(env, jLimit, minMid);

WasmEdge_Limit tableLimit = {/*.HasMax =*/ hasMax, /*.Shared =*/ false, /*.Min =*/ min, /*.Max =*/ max};
WasmEdge_Limit tableLimit = {.HasMax = hasMax, .Min = min, .Max = max};
WasmEdge_TableTypeContext *tableTypeContext =
WasmEdge_TableTypeCreate((enum WasmEdge_RefType)refType, tableLimit);
setPointer(env, thisObject, (long)tableTypeContext);
Expand Down
6 changes: 3 additions & 3 deletions include/api/wasmedge/wasmedge.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ typedef struct WasmEdge_Result {
uint32_t Code;
} WasmEdge_Result;
#ifdef __cplusplus
#define WasmEdge_Result_Success (WasmEdge_Result{/*.Code =*/0x00})
#define WasmEdge_Result_Terminate (WasmEdge_Result{/*.Code =*/0x01})
#define WasmEdge_Result_Fail (WasmEdge_Result{/*.Code =*/0x02})
#define WasmEdge_Result_Success (WasmEdge_Result{/* Code */ 0x00})
#define WasmEdge_Result_Terminate (WasmEdge_Result{/* Code */ 0x01})
#define WasmEdge_Result_Fail (WasmEdge_Result{/* Code */ 0x02})
#else
#define WasmEdge_Result_Success ((WasmEdge_Result){.Code = 0x00})
#define WasmEdge_Result_Terminate ((WasmEdge_Result){.Code = 0x01})
Expand Down
94 changes: 47 additions & 47 deletions lib/api/wasmedge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,11 @@ using namespace WasmEdge;
// Helper function for returning a WasmEdge_Result by error code.
inline constexpr WasmEdge_Result
genWasmEdge_Result(const ErrCode::Value &Code) noexcept {
return WasmEdge_Result{/*.Code =*/static_cast<uint32_t>(Code) & 0x00FFFFFFU};
return WasmEdge_Result{/* Code */ static_cast<uint32_t>(Code) & 0x00FFFFFFU};
}
inline constexpr WasmEdge_Result
genWasmEdge_Result(const ErrCode &Code) noexcept {
return WasmEdge_Result{/*.Code =*/Code.operator uint32_t()};
return WasmEdge_Result{/* Code */ Code.operator uint32_t()};
}

// Helper function for returning a struct uint128_t / int128_t
Expand All @@ -144,15 +144,15 @@ inline constexpr ::uint128_t to_uint128_t(C Val) noexcept {
(defined(__riscv) && __riscv_xlen == 64)
return Val;
#else
return {/*.Low =*/Val.low(), /*.High =*/static_cast<uint64_t>(Val.high())};
return {/* Low */ Val.low(), /* High */ static_cast<uint64_t>(Val.high())};
#endif
}
template <typename C> inline constexpr ::int128_t to_int128_t(C Val) noexcept {
#if defined(__x86_64__) || defined(__aarch64__) || \
(defined(__riscv) && __riscv_xlen == 64)
return Val;
#else
return {/*.Low =*/Val.low(), /*.High =*/Val.high()};
return {/* Low */ Val.low(), /* High */ Val.high()};
#endif
}

Expand All @@ -171,12 +171,12 @@ inline constexpr C to_WasmEdge_128_t(T Val) noexcept {
// Helper functions for returning a WasmEdge_Value by various values.
template <typename T> inline WasmEdge_Value genWasmEdge_Value(T Val) noexcept {
return WasmEdge_Value{
/*.Value =*/to_uint128_t(ValVariant(Val).unwrap()),
/*.Type =*/static_cast<WasmEdge_ValType>(WasmEdge::ValTypeFromType<T>())};
/* Value */ to_uint128_t(ValVariant(Val).unwrap()),
/* Type */ static_cast<WasmEdge_ValType>(WasmEdge::ValTypeFromType<T>())};
}
inline WasmEdge_Value genWasmEdge_Value(ValVariant Val,
WasmEdge_ValType T) noexcept {
return WasmEdge_Value{/*.Value =*/to_uint128_t(Val.unwrap()), /*.Type =*/T};
return WasmEdge_Value{/* Value */ to_uint128_t(Val.unwrap()), /* Type */ T};
}

// Helper function for converting a WasmEdge_Value array to a ValVariant
Expand Down Expand Up @@ -289,8 +289,8 @@ inline uint32_t fillMap(const std::map<std::string, T *, std::less<>> &Map,
}
if (Names) {
Names[I] = WasmEdge_String{
/*.Length =*/static_cast<uint32_t>(Pair.first.length()),
/*.Buf =*/Pair.first.data()};
/* Length */ static_cast<uint32_t>(Pair.first.length()),
/* Buf */ Pair.first.data()};
}
I++;
}
Expand Down Expand Up @@ -568,22 +568,22 @@ WasmEdge_StringCreateByCString(const char *Str) {
return WasmEdge_StringCreateByBuffer(
Str, static_cast<uint32_t>(std::strlen(Str)));
}
return WasmEdge_String{/*.Length =*/0, /*.Buf =*/nullptr};
return WasmEdge_String{/* Length */ 0, /* Buf */ nullptr};
}

WASMEDGE_CAPI_EXPORT WasmEdge_String
WasmEdge_StringCreateByBuffer(const char *Buf, const uint32_t Len) {
if (Buf && Len) {
char *Str = new char[Len];
std::copy_n(Buf, Len, Str);
return WasmEdge_String{/*.Length =*/Len, /*.Buf =*/Str};
return WasmEdge_String{/* Length */ Len, /* Buf */ Str};
}
return WasmEdge_String{/*.Length =*/0, /*.Buf =*/nullptr};
return WasmEdge_String{/* Length */ 0, /* Buf */ nullptr};
}

WASMEDGE_CAPI_EXPORT WasmEdge_String WasmEdge_StringWrap(const char *Buf,
const uint32_t Len) {
return WasmEdge_String{/*.Length =*/Len, /*.Buf =*/Buf};
return WasmEdge_String{/* Length */ Len, /* Buf */ Buf};
}

WASMEDGE_CAPI_EXPORT bool WasmEdge_StringIsEqual(const WasmEdge_String Str1,
Expand Down Expand Up @@ -631,7 +631,7 @@ WASMEDGE_CAPI_EXPORT bool WasmEdge_ResultOK(const WasmEdge_Result Res) {

WASMEDGE_CAPI_EXPORT WasmEdge_Result WasmEdge_ResultGen(
const enum WasmEdge_ErrCategory Category, const uint32_t Code) {
return WasmEdge_Result{/*.Code =*/(static_cast<uint32_t>(Category) << 24) +
return WasmEdge_Result{/* Code */ (static_cast<uint32_t>(Category) << 24) +
(Code & 0x00FFFFFFU)};
}

Expand Down Expand Up @@ -1130,13 +1130,13 @@ WASMEDGE_CAPI_EXPORT WasmEdge_Limit
WasmEdge_TableTypeGetLimit(const WasmEdge_TableTypeContext *Cxt) {
if (Cxt) {
const auto &Lim = fromTabTypeCxt(Cxt)->getLimit();
return WasmEdge_Limit{/*.HasMax =*/Lim.hasMax(),
/*.Shared =*/Lim.isShared(),
/*.Min =*/Lim.getMin(),
/*.Max =*/Lim.getMax()};
return WasmEdge_Limit{/* HasMax */ Lim.hasMax(),
/* Shared */ Lim.isShared(),
/* Min */ Lim.getMin(),
/* Max */ Lim.getMax()};
}
return WasmEdge_Limit{/*.HasMax =*/false, /*.Shared =*/false, /*.Min =*/0,
/*.Max =*/0};
return WasmEdge_Limit{/* HasMax */ false, /* Shared */ false, /* Min */ 0,
/* Max */ 0};
}

WASMEDGE_CAPI_EXPORT void
Expand Down Expand Up @@ -1164,13 +1164,13 @@ WASMEDGE_CAPI_EXPORT WasmEdge_Limit
WasmEdge_MemoryTypeGetLimit(const WasmEdge_MemoryTypeContext *Cxt) {
if (Cxt) {
const auto &Lim = fromMemTypeCxt(Cxt)->getLimit();
return WasmEdge_Limit{/*.HasMax =*/Lim.hasMax(),
/*.Shared =*/Lim.isShared(),
/*.Min =*/Lim.getMin(),
/*.Max =*/Lim.getMax()};
return WasmEdge_Limit{/* HasMax */ Lim.hasMax(),
/* Shared */ Lim.isShared(),
/* Min */ Lim.getMin(),
/* Max */ Lim.getMax()};
}
return WasmEdge_Limit{/*.HasMax =*/false, /*.Shared =*/false, /*.Min =*/0,
/*.Max =*/0};
return WasmEdge_Limit{/* HasMax */ false, /* Shared */ false, /* Min */ 0,
/* Max */ 0};
}

WASMEDGE_CAPI_EXPORT void
Expand Down Expand Up @@ -1228,20 +1228,20 @@ WASMEDGE_CAPI_EXPORT WasmEdge_String
WasmEdge_ImportTypeGetModuleName(const WasmEdge_ImportTypeContext *Cxt) {
if (Cxt) {
auto StrView = fromImpTypeCxt(Cxt)->getModuleName();
return WasmEdge_String{/*.Length =*/static_cast<uint32_t>(StrView.length()),
/*.Buf =*/StrView.data()};
return WasmEdge_String{/* Length */ static_cast<uint32_t>(StrView.length()),
/* Buf */ StrView.data()};
}
return WasmEdge_String{/*.Length =*/0, /*.Buf =*/nullptr};
return WasmEdge_String{/* Length */ 0, /* Buf */ nullptr};
}

WASMEDGE_CAPI_EXPORT WasmEdge_String
WasmEdge_ImportTypeGetExternalName(const WasmEdge_ImportTypeContext *Cxt) {
if (Cxt) {
auto StrView = fromImpTypeCxt(Cxt)->getExternalName();
return WasmEdge_String{/*.Length =*/static_cast<uint32_t>(StrView.length()),
/*.Buf =*/StrView.data()};
return WasmEdge_String{/* Length */ static_cast<uint32_t>(StrView.length()),
/* Buf */ StrView.data()};
}
return WasmEdge_String{/*.Length =*/0, /*.Buf =*/nullptr};
return WasmEdge_String{/* Length */ 0, /* Buf */ nullptr};
}

WASMEDGE_CAPI_EXPORT const WasmEdge_FunctionTypeContext *
Expand Down Expand Up @@ -1310,10 +1310,10 @@ WASMEDGE_CAPI_EXPORT WasmEdge_String
WasmEdge_ExportTypeGetExternalName(const WasmEdge_ExportTypeContext *Cxt) {
if (Cxt) {
auto StrView = fromExpTypeCxt(Cxt)->getExternalName();
return WasmEdge_String{/*.Length =*/static_cast<uint32_t>(StrView.length()),
/*.Buf =*/StrView.data()};
return WasmEdge_String{/* Length */ static_cast<uint32_t>(StrView.length()),
/* Buf */ StrView.data()};
}
return WasmEdge_String{/*.Length =*/0, /*.Buf =*/nullptr};
return WasmEdge_String{/* Length */ 0, /* Buf */ nullptr};
}

WASMEDGE_CAPI_EXPORT const WasmEdge_FunctionTypeContext *
Expand Down Expand Up @@ -1835,10 +1835,10 @@ WASMEDGE_CAPI_EXPORT WasmEdge_String WasmEdge_ModuleInstanceGetModuleName(
const WasmEdge_ModuleInstanceContext *Cxt) {
if (Cxt) {
auto StrView = fromModCxt(Cxt)->getModuleName();
return WasmEdge_String{/*.Length =*/static_cast<uint32_t>(StrView.length()),
/*.Buf =*/StrView.data()};
return WasmEdge_String{/* Length */ static_cast<uint32_t>(StrView.length()),
/* Buf */ StrView.data()};
}
return WasmEdge_String{/*.Length =*/0, /*.Buf =*/nullptr};
return WasmEdge_String{/* Length */ 0, /* Buf */ nullptr};
}

WASMEDGE_CAPI_EXPORT void *
Expand Down Expand Up @@ -2649,8 +2649,8 @@ WASMEDGE_CAPI_EXPORT uint32_t WasmEdge_VMGetFunctionList(
const auto &FuncType = FuncInst->getFuncType();
if (Names) {
Names[I] = WasmEdge_String{
/*.Length =*/static_cast<uint32_t>(It->first.length()),
/*.Buf =*/It->first.data()};
/* Length */ static_cast<uint32_t>(It->first.length()),
/* Buf */ It->first.data()};
}
if (FuncTypes) {
FuncTypes[I] = toFuncTypeCxt(&FuncType);
Expand Down Expand Up @@ -2850,8 +2850,8 @@ WASMEDGE_CAPI_EXPORT uint32_t WasmEdge_PluginListPlugins(WasmEdge_String *Names,
if (Names) {
for (uint32_t I = 0; I < Len && I < PList.size(); I++) {
Names[I] = WasmEdge_String{
/*.Length =*/static_cast<uint32_t>(std::strlen(PList[I].name())),
/*.Buf =*/PList[I].name()};
/* Length */ static_cast<uint32_t>(std::strlen(PList[I].name())),
/* Buf */ PList[I].name()};
}
}
return static_cast<uint32_t>(PList.size());
Expand All @@ -2867,10 +2867,10 @@ WasmEdge_PluginGetPluginName(const WasmEdge_PluginContext *Cxt) {
if (Cxt) {
const char *Name = fromPluginCxt(Cxt)->name();
return WasmEdge_String{
/*.Length =*/static_cast<uint32_t>(std::strlen(Name)),
/*.Buf =*/Name};
/* Length */ static_cast<uint32_t>(std::strlen(Name)),
/* Buf */ Name};
}
return WasmEdge_String{/*.Length =*/0, /*.Buf =*/nullptr};
return WasmEdge_String{/* Length */ 0, /* Buf */ nullptr};
}

WASMEDGE_CAPI_EXPORT uint32_t
Expand All @@ -2889,8 +2889,8 @@ WasmEdge_PluginListModule(const WasmEdge_PluginContext *Cxt,
if (Names) {
for (uint32_t I = 0; I < Len && I < MList.size(); I++) {
Names[I] = WasmEdge_String{
/*.Length =*/static_cast<uint32_t>(std::strlen(MList[I].name())),
/*.Buf =*/MList[I].name()};
/* Length */ static_cast<uint32_t>(std::strlen(MList[I].name())),
/* Buf */ MList[I].name()};
}
}
return static_cast<uint32_t>(MList.size());
Expand Down
2 changes: 1 addition & 1 deletion lib/host/wasi/inode-win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace {
#if WINAPI_PARTITION_DESKTOP
inline constexpr uint64_t combineHighLow(uint32_t HighPart,
uint32_t LowPart) noexcept {
const ULARGE_INTEGER_ Temp = {/*.LowPart =*/LowPart, /*.HighPart =*/HighPart};
const ULARGE_INTEGER_ Temp = {/* LowPart */ LowPart, /* HighPart */ HighPart};
return Temp.QuadPart;
}
#endif
Expand Down
8 changes: 4 additions & 4 deletions lib/host/wasi/win.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ static inline constexpr const FiletimeDuration NTToUnixEpoch =
static constexpr __wasi_timestamp_t fromFiletime(FILETIME_ FileTime) noexcept {
using std::chrono::duration_cast;
using std::chrono::nanoseconds;
ULARGE_INTEGER_ Temp = {/*.LowPart =*/FileTime.dwLowDateTime,
/*.HighPart =*/FileTime.dwHighDateTime};
ULARGE_INTEGER_ Temp = {/* LowPart */ FileTime.dwLowDateTime,
/* HighPart */ FileTime.dwHighDateTime};
auto Duration = duration_cast<nanoseconds>(FiletimeDuration{Temp.QuadPart} -
NTToUnixEpoch);
return static_cast<__wasi_timestamp_t>(Duration.count());
Expand All @@ -226,8 +226,8 @@ static constexpr FILETIME_ toFiletime(__wasi_timestamp_t TimeStamp) noexcept {
auto Duration =
duration_cast<FiletimeDuration>(nanoseconds{TimeStamp}) + NTToUnixEpoch;
ULARGE_INTEGER_ Temp = ULARGE_INTEGER_(Duration.count());
return FILETIME_{/*.dwLowDateTime =*/Temp.LowPart,
/*.dwHighDateTime =*/Temp.HighPart};
return FILETIME_{/* dwLowDateTime */ Temp.LowPart,
/* dwHighDateTime */ Temp.HighPart};
}

inline __wasi_errno_t fromWSALastError() noexcept {
Expand Down
Loading

0 comments on commit fc31890

Please sign in to comment.