From c24da62cdd3f050f6b8fc7ffe5686dbcaab460eb Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 16 Nov 2018 18:41:27 +0100 Subject: [PATCH] - marked all places where an incomplete parameter list may be passed to the VM by a native call by redirecting VMCall to an intermediate VMCallWithDefaults. This function must later fill in the missing arguments from the default. --- src/info.cpp | 4 ++-- src/menu/menu.cpp | 4 ++-- src/menu/menudef.cpp | 4 ++-- src/p_acs.cpp | 8 ++++---- src/p_actionfunctions.cpp | 2 +- src/scripting/vm/vm.h | 5 +++++ 6 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/info.cpp b/src/info.cpp index 87332fd2b2..5e2593bb9f 100644 --- a/src/info.cpp +++ b/src/info.cpp @@ -175,13 +175,13 @@ bool FState::CallAction(AActor *self, AActor *stateowner, FStateParamInfo *info, if (stateret == nullptr) { - VMCall(ActionFunc, params, ActionFunc->ImplicitArgs, nullptr, 0); + VMCallWithDefaults(ActionFunc, params, ActionFunc->ImplicitArgs, nullptr, 0); } else { VMReturn ret; ret.PointerAt((void **)stateret); - VMCall(ActionFunc, params, ActionFunc->ImplicitArgs, &ret, 1); + VMCallWithDefaults(ActionFunc, params, ActionFunc->ImplicitArgs, &ret, 1); } } catch (CVMAbortException &err) diff --git a/src/menu/menu.cpp b/src/menu/menu.cpp index bcba959303..477ceda967 100644 --- a/src/menu/menu.cpp +++ b/src/menu/menu.cpp @@ -1211,7 +1211,7 @@ DMenuItemBase * CreateOptionMenuItemSubmenu(const char *label, FName cmd, int ce auto c = PClass::FindClass("OptionMenuItemSubmenu"); auto p = c->CreateNew(); FString namestr = label; - VMValue params[] = { p, &namestr, cmd.GetIndex(), center }; + VMValue params[] = { p, &namestr, cmd.GetIndex(), center, false }; auto f = dyn_cast(c->FindSymbol("Init", false)); VMCall(f->Variants[0].Implementation, params, countof(params), nullptr, 0); return (DMenuItemBase*)p; @@ -1233,7 +1233,7 @@ DMenuItemBase * CreateOptionMenuItemCommand(const char *label, FName cmd, bool c auto c = PClass::FindClass("OptionMenuItemCommand"); auto p = c->CreateNew(); FString namestr = label; - VMValue params[] = { p, &namestr, cmd.GetIndex(), centered }; + VMValue params[] = { p, &namestr, cmd.GetIndex(), centered, false }; auto f = dyn_cast(c->FindSymbol("Init", false)); VMCall(f->Variants[0].Implementation, params, countof(params), nullptr, 0); auto unsafe = dyn_cast(c->FindSymbol("mUnsafe", false)); diff --git a/src/menu/menudef.cpp b/src/menu/menudef.cpp index f7bf7e1086..333d463017 100644 --- a/src/menu/menudef.cpp +++ b/src/menu/menudef.cpp @@ -477,7 +477,7 @@ static void ParseListMenuBody(FScanner &sc, DListMenuDescriptor *desc) } DMenuItemBase *item = (DMenuItemBase*)cls->CreateNew(); params[0] = item; - VMCall(func->Variants[0].Implementation, ¶ms[0], params.Size(), nullptr, 0); + VMCallWithDefaults(func->Variants[0].Implementation, ¶ms[0], params.Size(), nullptr, 0); desc->mItems.Push((DMenuItemBase*)item); if (cls->IsDescendantOf("ListMenuItemSelectable")) @@ -917,7 +917,7 @@ static void ParseOptionMenuBody(FScanner &sc, DOptionMenuDescriptor *desc) DMenuItemBase *item = (DMenuItemBase*)cls->CreateNew(); params[0] = item; - VMCall(func->Variants[0].Implementation, ¶ms[0], params.Size(), nullptr, 0); + VMCallWithDefaults(func->Variants[0].Implementation, ¶ms[0], params.Size(), nullptr, 0); desc->mItems.Push((DMenuItemBase*)item); success = true; diff --git a/src/p_acs.cpp b/src/p_acs.cpp index 10038cb6d2..47a508995c 100644 --- a/src/p_acs.cpp +++ b/src/p_acs.cpp @@ -5448,7 +5448,7 @@ static int ScriptCall(AActor *activator, unsigned argc, int32_t *args) // The return value can be the same types as the parameter types, plus void if (func->Proto->ReturnTypes.Size() == 0) { - VMCall(func, ¶ms[0], params.Size(), nullptr, 0); + VMCallWithDefaults(func, ¶ms[0], params.Size(), nullptr, 0); } else { @@ -5470,20 +5470,20 @@ static int ScriptCall(AActor *activator, unsigned argc, int32_t *args) { double d; VMReturn ret(&d); - VMCall(func, ¶ms[0], params.Size(), &ret, 1); + VMCallWithDefaults(func, ¶ms[0], params.Size(), &ret, 1); retval = DoubleToACS(d); } else if (rettype == TypeString) { FString d; VMReturn ret(&d); - VMCall(func, ¶ms[0], params.Size(), &ret, 1); + VMCallWithDefaults(func, ¶ms[0], params.Size(), &ret, 1); retval = GlobalACSStrings.AddString(d); } else { // All other return values can not be handled so ignore them. - VMCall(func, ¶ms[0], params.Size(), nullptr, 0); + VMCallWithDefaults(func, ¶ms[0], params.Size(), nullptr, 0); } } } diff --git a/src/p_actionfunctions.cpp b/src/p_actionfunctions.cpp index 6e6e165008..d412bf2947 100644 --- a/src/p_actionfunctions.cpp +++ b/src/p_actionfunctions.cpp @@ -170,7 +170,7 @@ bool AStateProvider::CallStateChain (AActor *actor, FState *state) try { state->CheckCallerType(actor, this); - VMCall(state->ActionFunc, params, state->ActionFunc->ImplicitArgs, wantret, numret); + VMCallWithDefaults(state->ActionFunc, params, state->ActionFunc->ImplicitArgs, wantret, numret); } catch (CVMAbortException &err) { diff --git a/src/scripting/vm/vm.h b/src/scripting/vm/vm.h index 8289097790..11f5c60306 100644 --- a/src/scripting/vm/vm.h +++ b/src/scripting/vm/vm.h @@ -377,6 +377,11 @@ private: int VMCall(VMFunction *func, VMValue *params, int numparams, VMReturn *results, int numresults/*, VMException **trap = NULL*/); +inline int VMCallWithDefaults(VMFunction *func, VMValue *params, int numparams, VMReturn *results, int numresults/*, VMException **trap = NULL*/) +{ + VMCall(func, params, numparams, results, numresults); +} + // Use this in the prototype for a native function. #define VM_ARGS VMValue *param, TArray &defaultparam, int numparam, VMReturn *ret, int numret #define VM_ARGS_NAMES param, defaultparam, numparam, ret, numret