[Scummvm-git-logs] scummvm master -> 19cc95468a4ff33eb57c172283de79a21e78b1c0

dreammaster dreammaster at scummvm.org
Thu Aug 5 03:57:41 UTC 2021


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
19cc95468a AGS: Fix 64-bit pointer plugin method result checks


Commit: 19cc95468a4ff33eb57c172283de79a21e78b1c0
    https://github.com/scummvm/scummvm/commit/19cc95468a4ff33eb57c172283de79a21e78b1c0
Author: Paul Gilbert (dreammaster at scummvm.org)
Date: 2021-08-04T20:55:37-07:00

Commit Message:
AGS: Fix 64-bit pointer plugin method result checks

In most cases, it looks like the GlobalReturnValue global is
set, resulting the return value being discarded

Changed paths:
    engines/ags/engine/script/cc_instance.cpp
    engines/ags/engine/script/script_runtime.cpp


diff --git a/engines/ags/engine/script/cc_instance.cpp b/engines/ags/engine/script/cc_instance.cpp
index 7c9ba407b8..ee60db873b 100644
--- a/engines/ags/engine/script/cc_instance.cpp
+++ b/engines/ags/engine/script/cc_instance.cpp
@@ -985,21 +985,28 @@ int ccInstance::Run(int32_t curpc) {
 
 			if (reg1.Type == kScValPluginFunction) {
 				_GP(GlobalReturnValue).Invalidate();
-				int32_t int_ret_val;
+				NumberPtr fnResult;
 				if (next_call_needs_object) {
 					RuntimeScriptValue obj_rval = registers[SREG_OP];
 					obj_rval.DirectPtrObj();
-					int_ret_val = call_function(reg1.pluginMethod(),
+					fnResult = call_function(reg1.pluginMethod(),
 						&obj_rval, num_args_to_func, func_callstack.GetHead() + 1);
 				} else {
-					int_ret_val = call_function(reg1.pluginMethod(),
+					fnResult = call_function(reg1.pluginMethod(),
 						nullptr, num_args_to_func, func_callstack.GetHead() + 1);
 				}
 
 				if (_GP(GlobalReturnValue).IsValid()) {
 					return_value = _GP(GlobalReturnValue);
 				} else {
-					return_value.SetPluginArgument(int_ret_val);
+					// TODO: Though some plugin methods return pointers, the SetPluginArgument
+					// call only supports a 32-bit value. This is fine in most cases, since
+					// methods mostly set the ptr on GlobalReturnValue, so it doesn't reach here.
+					// But just in case, throw a wobbly if it reaches here with a 64-bit pointer
+					if (fnResult._ptr > (void *)0xffffffff)
+						error("Uhandled 64-bit pointer result from plugin method call");
+
+					return_value.SetPluginArgument(fnResult);
 				}
 			} else if (next_call_needs_object) {
 				// member function call
diff --git a/engines/ags/engine/script/script_runtime.cpp b/engines/ags/engine/script/script_runtime.cpp
index 5eaaceb409..9e2fcdaf46 100644
--- a/engines/ags/engine/script/script_runtime.cpp
+++ b/engines/ags/engine/script/script_runtime.cpp
@@ -180,16 +180,7 @@ int call_function(const Plugins::PluginMethod &method,
 			params.push_back(parm_value[i]);
 
 		// Call the method
-		NumberPtr result = method(params);
-
-		// TODO: Though some script methods return pointers, the call_function only
-		// supports a 32-bit result. To avoid weird problems on 64-bit systems that
-		// produce pointers above 32-bits, detect and throw a wobbly
-		// until such time as it can properly be fixed
-		if (result._ptr > (void *)0xffffffff)
-			error("Uhandled 64-bit pointer result from plugin method call");
-
-		return result;
+		return method(params);
 	}
 }
 




More information about the Scummvm-git-logs mailing list