From 28efa65e0c1b50c16554d0de4ada17c749de28d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Guilloux?= Date: Fri, 12 Jan 2024 17:04:43 +0100 Subject: [PATCH] Revert a2edf52: SQOpsLimiter does a more precise job (#11754) --- cmake/scripts/Regression.cmake | 4 ++++ regression/regression/main.nut | 7 +++++++ regression/regression/result.txt | 19 +++++++++++++++++++ src/script/api/script_list.cpp | 11 ----------- 4 files changed, 30 insertions(+), 11 deletions(-) diff --git a/cmake/scripts/Regression.cmake b/cmake/scripts/Regression.cmake index 19fece83f5..c719b90406 100644 --- a/cmake/scripts/Regression.cmake +++ b/cmake/scripts/Regression.cmake @@ -54,6 +54,9 @@ string(REPLACE "0x(nil)" "0x00000000" REGRESSION_RESULT "${REGRESSION_RESULT}") string(REPLACE "0x0000000000000000" "0x00000000" REGRESSION_RESULT "${REGRESSION_RESULT}") string(REPLACE "0x0x0" "0x00000000" REGRESSION_RESULT "${REGRESSION_RESULT}") +# Convert path separators +string(REPLACE "\\" "/" REGRESSION_RESULT "${REGRESSION_RESULT}") + # Remove timestamps if any string(REGEX REPLACE "\[[0-9-]+ [0-9:]+\] " "" REGRESSION_RESULT "${REGRESSION_RESULT}") @@ -62,6 +65,7 @@ string(REPLACE "\ndbg: [script]" "\n" REGRESSION_RESULT "${REGRESSION_RESULT}") string(REPLACE "\n " "\nERROR: " REGRESSION_RESULT "${REGRESSION_RESULT}") string(REPLACE "\nERROR: [1] " "\n" REGRESSION_RESULT "${REGRESSION_RESULT}") string(REPLACE "\n[P] " "\n" REGRESSION_RESULT "${REGRESSION_RESULT}") +string(REPLACE "\n[S] " "\n" REGRESSION_RESULT "${REGRESSION_RESULT}") string(REGEX REPLACE "dbg: ([^\n]*)\n?" "" REGRESSION_RESULT "${REGRESSION_RESULT}") # Read the expected result diff --git a/regression/regression/main.nut b/regression/regression/main.nut index 100a47f3c9..b2daa5b687 100644 --- a/regression/regression/main.nut +++ b/regression/regression/main.nut @@ -2026,5 +2026,12 @@ function Regression::Start() print(" IsEventWaiting: false"); this.Math(); + + /* Check Valuate() is actually limited, MUST BE THE LAST TEST. */ + print("--Valuate() with excessive CPU usage--") + local list = AIList(); + list.AddItem(0, 0); + local Infinite = function(id) { while(true); } + list.Valuate(Infinite); } diff --git a/regression/regression/result.txt b/regression/regression/result.txt index 578f15e623..f1d20754b0 100644 --- a/regression/regression/result.txt +++ b/regression/regression/result.txt @@ -9587,4 +9587,23 @@ ERROR: IsEnd() is invalid as Begin() is never called -1 > 2147483647: false -2147483648 > 2147483647: false 13725 > -2147483648: true +--Valuate() with excessive CPU usage-- +Your script made an error: excessive CPU usage in valuator function + +*FUNCTION [unknown()] regression/main.nut line [2034] +*FUNCTION [Valuate()] NATIVE line [-1] +*FUNCTION [Start()] regression/main.nut line [2035] + +[id] 0 +[this] TABLE +[Infinite] CLOSURE +[list] INSTANCE +[this] INSTANCE +Your script made an error: excessive CPU usage in valuator function + +*FUNCTION [Start()] regression/main.nut line [2035] + +[Infinite] CLOSURE +[list] INSTANCE +[this] INSTANCE ERROR: The script died unexpectedly. diff --git a/src/script/api/script_list.cpp b/src/script/api/script_list.cpp index fc727cc934..f774b2a004 100644 --- a/src/script/api/script_list.cpp +++ b/src/script/api/script_list.cpp @@ -9,7 +9,6 @@ #include "../../stdafx.h" #include "script_list.hpp" -#include "script_controller.hpp" #include "../../debug.h" #include "../../script/squirrel.hpp" @@ -914,16 +913,6 @@ SQInteger ScriptList::Valuate(HSQUIRRELVM vm) } } - /* Kill the script when the valuator call takes way too long. - * Triggered by nesting valuators, which then take billions of iterations. */ - if (ScriptController::GetOpsTillSuspend() < -1000000) { - /* See below for explanation. The extra pop is the return value. */ - sq_pop(vm, nparam + 4); - - ScriptObject::SetAllowDoCommand(backup_allow); - return sq_throwerror(vm, "excessive CPU usage in valuator function"); - } - /* Was something changed? */ if (previous_modification_count != this->modifications) { /* See below for explanation. The extra pop is the return value. */