From 85e881effa9e1eb75929f15c1a438ed2bc7961aa Mon Sep 17 00:00:00 2001 From: Sandu Liviu Catalin Date: Mon, 13 Jun 2016 00:27:06 +0300 Subject: [PATCH] Fix const correctness in utility functions. By not taking the object reference as const we are forced to make copies of objects that are const or use const_cast. Eitherway, this is the correct way because objects are not modified. --- shared/Base/Utility.cpp | 16 ++++++++-------- shared/Base/Utility.hpp | 8 ++++---- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/shared/Base/Utility.cpp b/shared/Base/Utility.cpp index 9132efe1..0acb5616 100644 --- a/shared/Base/Utility.cpp +++ b/shared/Base/Utility.cpp @@ -807,45 +807,45 @@ Object MakeULongObj(HSQUIRRELVM vm, Uint64 val) } // ------------------------------------------------------------------------------------------------ -Int64 FetchSLongObjVal(Object & val) +Int64 FetchSLongObjVal(const Object & val) { // Obtain the initial stack size const StackGuard sg(DefaultVM::Get()); // Push the specified object onto the stack - Var< Object & >::push(DefaultVM::Get(), val); + Var< const Object & >::push(DefaultVM::Get(), val); // Retrieve and return the object value from the stack return PopStackSLong(DefaultVM::Get(), -1); } // ------------------------------------------------------------------------------------------------ -Uint64 FetchULongObjVal(Object & val) +Uint64 FetchULongObjVal(const Object & val) { // Obtain the initial stack size const StackGuard sg(DefaultVM::Get()); // Push the specified object onto the stack - Var< Object & >::push(DefaultVM::Get(), val); + Var< const Object & >::push(DefaultVM::Get(), val); // Retrieve and return the object value from the stack return PopStackSLong(DefaultVM::Get(), -1); } // ------------------------------------------------------------------------------------------------ -Int64 FetchSLongObjVal(HSQUIRRELVM vm, Object & val) +Int64 FetchSLongObjVal(HSQUIRRELVM vm, const Object & val) { // Obtain the initial stack size const StackGuard sg(vm); // Push the specified object onto the stack - Var< Object & >::push(vm, val); + Var< const Object & >::push(vm, val); // Retrieve and return the object value from the stack return PopStackSLong(vm, -1); } // ------------------------------------------------------------------------------------------------ -Uint64 FetchULongObjVal(HSQUIRRELVM vm, Object & val) +Uint64 FetchULongObjVal(HSQUIRRELVM vm, const Object & val) { // Obtain the initial stack size const StackGuard sg(vm); // Push the specified object onto the stack - Var< Object & >::push(vm, val); + Var< const Object & >::push(vm, val); // Retrieve and return the object value from the stack return PopStackSLong(vm, -1); } diff --git a/shared/Base/Utility.hpp b/shared/Base/Utility.hpp index cad273a3..4ea71c4a 100644 --- a/shared/Base/Utility.hpp +++ b/shared/Base/Utility.hpp @@ -1468,22 +1468,22 @@ Object MakeULongObj(HSQUIRRELVM vm, Uint64 val); /* ------------------------------------------------------------------------------------------------ * Retrieve a signed 64 bit integer from an signed long integer object. */ -Int64 FetchSLongObjVal(Object & val); +Int64 FetchSLongObjVal(const Object & val); /* ------------------------------------------------------------------------------------------------ * Retrieve a unsigned 64 bit integer from an unsigned long integer object. */ -Uint64 FetchULongObjVal(Object & val); +Uint64 FetchULongObjVal(const Object & val); /* ------------------------------------------------------------------------------------------------ * Retrieve a signed 64 bit integer from an signed long integer object. */ -Int64 FetchSLongObjVal(HSQUIRRELVM vm, Object & val); +Int64 FetchSLongObjVal(HSQUIRRELVM vm, const Object & val); /* ------------------------------------------------------------------------------------------------ * Retrieve a unsigned 64 bit integer from an unsigned long integer object. */ -Uint64 FetchULongObjVal(HSQUIRRELVM vm, Object & val); +Uint64 FetchULongObjVal(HSQUIRRELVM vm, const Object & val); /* ------------------------------------------------------------------------------------------------ * Attempt to pop the value at the specified index on the stack as a native integer.