[Scummvm-git-logs] scummvm branch-2-7 -> ec14098a0c18a335b3cbd40fe2b1d7c9e603c8ab
lephilousophe
noreply at scummvm.org
Fri Jul 14 20:09:50 UTC 2023
This automated email contains information about 8 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
e003d012c5 COMMON: Make sure coroutine Process parameter is well aligned
9a09700d70 COMMON: Only apply alignment on supported platforms
346408a239 TONY: Fix various types discrepancies
288fe38657 TONY: Fix MemoryManager data alignment
f743cd55b2 TONY: Properly align Expressions
e0edbc0154 TONY: Only apply alignment on supported platforms
13475d111e TONY: Fix _num type discrepancy
ec14098a0c COMMON: Don't use a pointer to T in UnalignedPtr
Commit: e003d012c548237c9f4f17e0bea997ac9eb583be
https://github.com/scummvm/scummvm/commit/e003d012c548237c9f4f17e0bea997ac9eb583be
Author: Le Philousophe (lephilousophe at users.noreply.github.com)
Date: 2023-07-14T22:09:13+02:00
Commit Message:
COMMON: Make sure coroutine Process parameter is well aligned
Changed paths:
common/coroutines.h
diff --git a/common/coroutines.h b/common/coroutines.h
index 47c2e2635bd..1861ee53f88 100644
--- a/common/coroutines.h
+++ b/common/coroutines.h
@@ -307,7 +307,7 @@ struct PROCESS {
int sleepTime; ///< Number of scheduler cycles to sleep.
uint32 pid; ///< Process ID.
uint32 pidWaiting[CORO_MAX_PID_WAITING]; ///< Process ID(s) that the process is currently waiting on.
- char param[CORO_PARAM_SIZE]; ///< Process-specific information.
+ alignas(max_align_t) char param[CORO_PARAM_SIZE]; ///< Process-specific information.
};
typedef PROCESS *PPROCESS;
Commit: 9a09700d7045d2da323757907a77fb4e95103c6b
https://github.com/scummvm/scummvm/commit/9a09700d7045d2da323757907a77fb4e95103c6b
Author: Le Philousophe (lephilousophe at users.noreply.github.com)
Date: 2023-07-14T22:09:13+02:00
Commit Message:
COMMON: Only apply alignment on supported platforms
Changed paths:
common/coroutines.h
configure
diff --git a/common/coroutines.h b/common/coroutines.h
index 1861ee53f88..16d75e41df9 100644
--- a/common/coroutines.h
+++ b/common/coroutines.h
@@ -307,7 +307,10 @@ struct PROCESS {
int sleepTime; ///< Number of scheduler cycles to sleep.
uint32 pid; ///< Process ID.
uint32 pidWaiting[CORO_MAX_PID_WAITING]; ///< Process ID(s) that the process is currently waiting on.
- alignas(max_align_t) char param[CORO_PARAM_SIZE]; ///< Process-specific information.
+#ifndef NO_CXX11_ALIGNAS
+ alignas(max_align_t)
+#endif
+ char param[CORO_PARAM_SIZE]; ///< Process-specific information.
};
typedef PROCESS *PPROCESS;
diff --git a/configure b/configure
index 8d74abd13ac..5c28f7e3503 100755
--- a/configure
+++ b/configure
@@ -2306,6 +2306,25 @@ else
define_in_config_if_yes yes 'NO_CXX11_NULLPTR_T'
fi
+# Check if alignas and alignof are available
+echo_n "Checking if C++11 alignas and alignof keywords are available... "
+cat > $TMPC << EOF
+#include <stddef.h>
+struct test {
+ char c;
+ alignas(max_align_t) size_t _size;
+};
+static const size_t LENGTH = alignof(max_align_t);
+int main(int argc, char *argv[]) { return 0; }
+EOF
+cc_check
+if test "$TMPR" -eq 0; then
+ echo yes
+else
+ echo no
+ define_in_config_if_yes yes 'NO_CXX11_ALIGNAS'
+fi
+
#
# Determine extra build flags for debug and/or release builds
#
Commit: 346408a239e09d5ad9dfb212bf46f41aa30d75de
https://github.com/scummvm/scummvm/commit/346408a239e09d5ad9dfb212bf46f41aa30d75de
Author: Le Philousophe (lephilousophe at users.noreply.github.com)
Date: 2023-07-14T22:09:13+02:00
Commit Message:
TONY: Fix various types discrepancies
Avoid using byte * for opaque types and don't do unneeded casts.
Changed paths:
engines/tony/mpal/expr.cpp
engines/tony/mpal/expr.h
engines/tony/mpal/memory.cpp
engines/tony/mpal/memory.h
diff --git a/engines/tony/mpal/expr.cpp b/engines/tony/mpal/expr.cpp
index 6643dd9bf45..4940a15ed48 100644
--- a/engines/tony/mpal/expr.cpp
+++ b/engines/tony/mpal/expr.cpp
@@ -39,7 +39,7 @@ namespace MPAL {
* @param h Handle to the original expression
* @retruns Pointer to the cloned expression
*/
-static byte *duplicateExpression(MpalHandle h) {
+static void *duplicateExpression(MpalHandle h) {
byte *orig, *clone;
orig = (byte *)globalLock(h);
@@ -144,9 +144,9 @@ static void solve(LpExpression one, int num) {
* @param expr Pointer to an expression duplicated by DuplicateExpression
* @returns Value
*/
-static int evaluateAndFreeExpression(byte *expr) {
- int num = *expr;
- LpExpression one = (LpExpression)(expr + 1);
+static int evaluateAndFreeExpression(void *expr) {
+ int num = *(byte *)expr;
+ LpExpression one = (LpExpression)((byte *)expr + 1);
// 1) Substitutions of variables
LpExpression cur = one;
@@ -185,7 +185,7 @@ static int evaluateAndFreeExpression(byte *expr) {
const byte *parseExpression(const byte *lpBuf, const Common::UnalignedPtr<MpalHandle> &h) {
byte *start;
- uint32 num = *lpBuf;
+ byte num = *lpBuf;
lpBuf++;
if (num == 0)
@@ -196,7 +196,7 @@ const byte *parseExpression(const byte *lpBuf, const Common::UnalignedPtr<MpalHa
return NULL;
start = (byte *)globalLock(h.load());
- *start = (byte)num;
+ *start = num;
LpExpression cur = (LpExpression)(start + 1);
@@ -270,8 +270,8 @@ bool compareExpressions(MpalHandle h1, MpalHandle h2) {
e1 = (byte *)globalLock(h1);
e2 = (byte *)globalLock(h2);
- int num1 = *(byte *)e1;
- int num2 = *(byte *)e2;
+ int num1 = *e1;
+ int num2 = *e2;
if (num1 != num2) {
globalUnlock(h1);
diff --git a/engines/tony/mpal/expr.h b/engines/tony/mpal/expr.h
index a42c69e83cc..eec05885ae5 100644
--- a/engines/tony/mpal/expr.h
+++ b/engines/tony/mpal/expr.h
@@ -74,7 +74,7 @@ typedef struct {
int _num; // Identifier (if type == ELT_NUMBER)
char *_name; // Variable name (if type == ELT_VAR)
MpalHandle _son; // Handle expressions (if type == ELT_PARENTH)
- byte *_pson; // Handle lockato (if type == ELT_PARENTH2)
+ void *_pson; // Handle lockato (if type == ELT_PARENTH2)
} _val;
byte _symbol; // Mathematic symbols (see #define OP_*)
diff --git a/engines/tony/mpal/memory.cpp b/engines/tony/mpal/memory.cpp
index 1415c70aecc..2a1a1274052 100644
--- a/engines/tony/mpal/memory.cpp
+++ b/engines/tony/mpal/memory.cpp
@@ -102,7 +102,7 @@ void MemoryManager::destroyItem(MpalHandle handle) {
/**
* Locks an item for access
*/
-byte *MemoryManager::lockItem(MpalHandle handle) {
+void *MemoryManager::lockItem(MpalHandle handle) {
MemoryItem *item = (MemoryItem *)handle;
assert(item->_id == BLOCK_ID);
++item->_lockCount;
diff --git a/engines/tony/mpal/memory.h b/engines/tony/mpal/memory.h
index 4ada3b73dd5..e49e9275917 100644
--- a/engines/tony/mpal/memory.h
+++ b/engines/tony/mpal/memory.h
@@ -50,7 +50,7 @@ public:
static void freeBlock(MpalHandle handle);
static void destroyItem(MpalHandle handle);
static uint32 getSize(MpalHandle handle);
- static byte *lockItem(MpalHandle handle);
+ static void *lockItem(MpalHandle handle);
static void unlockItem(MpalHandle handle);
};
Commit: 288fe3865769fffa0f36fac7d6058b6d25937388
https://github.com/scummvm/scummvm/commit/288fe3865769fffa0f36fac7d6058b6d25937388
Author: Le Philousophe (lephilousophe at users.noreply.github.com)
Date: 2023-07-14T22:09:13+02:00
Commit Message:
TONY: Fix MemoryManager data alignment
Data being a byte type, it was never aligned.
Don't overallocate 1 byte which is here only because C++ doesn't support
VLA.
Changed paths:
engines/tony/mpal/memory.cpp
engines/tony/mpal/memory.h
diff --git a/engines/tony/mpal/memory.cpp b/engines/tony/mpal/memory.cpp
index 2a1a1274052..341e3de515c 100644
--- a/engines/tony/mpal/memory.cpp
+++ b/engines/tony/mpal/memory.cpp
@@ -36,7 +36,7 @@ namespace MPAL {
* @return Returns a MemoryItem instance for the new block
*/
MpalHandle MemoryManager::allocate(uint32 size, uint flags) {
- MemoryItem *newItem = (MemoryItem *)malloc(sizeof(MemoryItem) + size);
+ MemoryItem *newItem = (MemoryItem *)malloc(sizeof(MemoryItem) - sizeof(byte[1]) + size);
newItem->_id = BLOCK_ID;
newItem->_size = size;
newItem->_lockCount = 0;
diff --git a/engines/tony/mpal/memory.h b/engines/tony/mpal/memory.h
index e49e9275917..ca021637df2 100644
--- a/engines/tony/mpal/memory.h
+++ b/engines/tony/mpal/memory.h
@@ -35,7 +35,7 @@ struct MemoryItem {
uint32 _id;
uint32 _size;
int _lockCount;
- byte _data[1];
+ alignas(max_align_t) byte _data[1];
// Casting for access to data
operator void *() { return &_data[0]; }
Commit: f743cd55b22d02a0e1994e3ca9624708fc56a67d
https://github.com/scummvm/scummvm/commit/f743cd55b22d02a0e1994e3ca9624708fc56a67d
Author: Le Philousophe (lephilousophe at users.noreply.github.com)
Date: 2023-07-14T22:09:13+02:00
Commit Message:
TONY: Properly align Expressions
Make sure Expression array is properly aligned inside the buffer
provided by GlobalAlloc.
Changed paths:
engines/tony/mpal/expr.cpp
diff --git a/engines/tony/mpal/expr.cpp b/engines/tony/mpal/expr.cpp
index 4940a15ed48..c780e52db93 100644
--- a/engines/tony/mpal/expr.cpp
+++ b/engines/tony/mpal/expr.cpp
@@ -33,6 +33,8 @@ namespace Tony {
namespace MPAL {
+static const size_t EXPR_LENGTH_SIZE = alignof(max_align_t);
+
/**
* Duplicate a mathematical expression.
*
@@ -44,13 +46,13 @@ static void *duplicateExpression(MpalHandle h) {
orig = (byte *)globalLock(h);
- int num = *(byte *)orig;
- LpExpression one = (LpExpression)(orig+1);
+ int num = *orig;
+ LpExpression one = (LpExpression)(orig + EXPR_LENGTH_SIZE);
- clone = (byte *)globalAlloc(GMEM_FIXED, sizeof(Expression) * num + 1);
- LpExpression two = (LpExpression)(clone + 1);
+ clone = (byte *)globalAlloc(GMEM_FIXED, sizeof(Expression) * num + EXPR_LENGTH_SIZE);
+ LpExpression two = (LpExpression)(clone + EXPR_LENGTH_SIZE);
- memcpy(clone, orig, sizeof(Expression) * num + 1);
+ memcpy(clone, orig, sizeof(Expression) * num + EXPR_LENGTH_SIZE);
for (int i = 0; i < num; i++) {
if (one->_type == ELT_PARENTH) {
@@ -146,7 +148,7 @@ static void solve(LpExpression one, int num) {
*/
static int evaluateAndFreeExpression(void *expr) {
int num = *(byte *)expr;
- LpExpression one = (LpExpression)((byte *)expr + 1);
+ LpExpression one = (LpExpression)((byte *)expr + EXPR_LENGTH_SIZE);
// 1) Substitutions of variables
LpExpression cur = one;
@@ -191,14 +193,14 @@ const byte *parseExpression(const byte *lpBuf, const Common::UnalignedPtr<MpalHa
if (num == 0)
return NULL;
- h.store(globalAllocate(GMEM_MOVEABLE | GMEM_ZEROINIT, num * sizeof(Expression) + 1));
+ h.store(globalAllocate(GMEM_MOVEABLE | GMEM_ZEROINIT, num * sizeof(Expression) + EXPR_LENGTH_SIZE));
if (h.load() == NULL)
return NULL;
start = (byte *)globalLock(h.load());
*start = num;
- LpExpression cur = (LpExpression)(start + 1);
+ LpExpression cur = (LpExpression)(start + EXPR_LENGTH_SIZE);
for (uint32 i = 0;i < num; i++) {
cur->_type = *(lpBuf);
@@ -213,6 +215,7 @@ const byte *parseExpression(const byte *lpBuf, const Common::UnalignedPtr<MpalHa
break;
case ELT_VAR:
+ // As name is a byte, there is no alignment rule
cur->_val._name = (char *)globalAlloc(GMEM_FIXED | GMEM_ZEROINIT, (*lpBuf) + 1);
if (cur->_val._name == NULL)
return NULL;
@@ -279,8 +282,8 @@ bool compareExpressions(MpalHandle h1, MpalHandle h2) {
return false;
}
- LpExpression one = (LpExpression)(e1 + 1);
- LpExpression two = (LpExpression)(e2 + 1);
+ LpExpression one = (LpExpression)(e1 + EXPR_LENGTH_SIZE);
+ LpExpression two = (LpExpression)(e2 + EXPR_LENGTH_SIZE);
for (int i = 0; i < num1; i++) {
if (one->_type != two->_type || (i != num1 - 1 && one->_symbol != two->_symbol)) {
@@ -336,7 +339,7 @@ bool compareExpressions(MpalHandle h1, MpalHandle h2) {
void freeExpression(MpalHandle h) {
byte *data = (byte *)globalLock(h);
int num = *data;
- LpExpression cur = (LpExpression)(data + 1);
+ LpExpression cur = (LpExpression)(data + EXPR_LENGTH_SIZE);
for (int i = 0; i < num; ++i, ++cur) {
switch (cur->_type) {
Commit: e0edbc0154b4a81fe64b9ed4a1ca832c31498ff4
https://github.com/scummvm/scummvm/commit/e0edbc0154b4a81fe64b9ed4a1ca832c31498ff4
Author: Le Philousophe (lephilousophe at users.noreply.github.com)
Date: 2023-07-14T22:09:13+02:00
Commit Message:
TONY: Only apply alignment on supported platforms
Changed paths:
engines/tony/mpal/expr.cpp
engines/tony/mpal/memory.h
diff --git a/engines/tony/mpal/expr.cpp b/engines/tony/mpal/expr.cpp
index c780e52db93..fbb5194e4bc 100644
--- a/engines/tony/mpal/expr.cpp
+++ b/engines/tony/mpal/expr.cpp
@@ -33,7 +33,14 @@ namespace Tony {
namespace MPAL {
-static const size_t EXPR_LENGTH_SIZE = alignof(max_align_t);
+static const size_t EXPR_LENGTH_SIZE =
+#ifndef NO_CXX11_ALIGNAS
+ alignof(max_align_t)
+#else
+ sizeof(byte)
+#endif
+ ;
+
/**
* Duplicate a mathematical expression.
diff --git a/engines/tony/mpal/memory.h b/engines/tony/mpal/memory.h
index ca021637df2..3bdec7e6743 100644
--- a/engines/tony/mpal/memory.h
+++ b/engines/tony/mpal/memory.h
@@ -35,7 +35,10 @@ struct MemoryItem {
uint32 _id;
uint32 _size;
int _lockCount;
- alignas(max_align_t) byte _data[1];
+#ifndef NO_CXX11_ALIGNAS
+ alignas(max_align_t)
+#endif
+ byte _data[1];
// Casting for access to data
operator void *() { return &_data[0]; }
Commit: 13475d111e8698143c307da57ed83e652c4a1b8a
https://github.com/scummvm/scummvm/commit/13475d111e8698143c307da57ed83e652c4a1b8a
Author: Le Philousophe (lephilousophe at users.noreply.github.com)
Date: 2023-07-14T22:09:13+02:00
Commit Message:
TONY: Fix _num type discrepancy
It's int32 everywhere outside expr anyway.
Changed paths:
engines/tony/mpal/expr.cpp
engines/tony/mpal/expr.h
diff --git a/engines/tony/mpal/expr.cpp b/engines/tony/mpal/expr.cpp
index fbb5194e4bc..32c6316647c 100644
--- a/engines/tony/mpal/expr.cpp
+++ b/engines/tony/mpal/expr.cpp
@@ -75,7 +75,7 @@ static void *duplicateExpression(MpalHandle h) {
return clone;
}
-static int Compute(int a, int b, byte symbol) {
+static int32 Compute(int32 a, int32 b, byte symbol) {
switch (symbol) {
case OP_MUL:
return a * b;
@@ -153,7 +153,7 @@ static void solve(LpExpression one, int num) {
* @param expr Pointer to an expression duplicated by DuplicateExpression
* @returns Value
*/
-static int evaluateAndFreeExpression(void *expr) {
+static int32 evaluateAndFreeExpression(void *expr) {
int num = *(byte *)expr;
LpExpression one = (LpExpression)((byte *)expr + EXPR_LENGTH_SIZE);
@@ -177,7 +177,7 @@ static int evaluateAndFreeExpression(void *expr) {
// 3) algebraic resolution
solve(one, num);
- int val = one->_val._num;
+ int32 val = one->_val._num;
globalDestroy(expr);
return val;
@@ -260,9 +260,9 @@ const byte *parseExpression(const byte *lpBuf, const Common::UnalignedPtr<MpalHa
* @param h Handle to the expression
* @returns Numeric value
*/
-int evaluateExpression(MpalHandle h) {
+int32 evaluateExpression(MpalHandle h) {
lockVar();
- int ret = evaluateAndFreeExpression(duplicateExpression(h));
+ int32 ret = evaluateAndFreeExpression(duplicateExpression(h));
unlockVar();
return ret;
diff --git a/engines/tony/mpal/expr.h b/engines/tony/mpal/expr.h
index eec05885ae5..4a9195faccb 100644
--- a/engines/tony/mpal/expr.h
+++ b/engines/tony/mpal/expr.h
@@ -71,7 +71,7 @@ typedef struct {
byte _type; // Object Type (see enum ExprListTypes)
union {
- int _num; // Identifier (if type == ELT_NUMBER)
+ int32 _num; // Identifier (if type == ELT_NUMBER)
char *_name; // Variable name (if type == ELT_VAR)
MpalHandle _son; // Handle expressions (if type == ELT_PARENTH)
void *_pson; // Handle lockato (if type == ELT_PARENTH2)
@@ -114,7 +114,7 @@ const byte *parseExpression(const byte *lpBuf, const Common::UnalignedPtr<MpalHa
* @param h Handle to the expression
* @returns Numeric value
*/
-int evaluateExpression(MpalHandle h);
+int32 evaluateExpression(MpalHandle h);
/**
* Compare two mathematical expressions together
Commit: ec14098a0c18a335b3cbd40fe2b1d7c9e603c8ab
https://github.com/scummvm/scummvm/commit/ec14098a0c18a335b3cbd40fe2b1d7c9e603c8ab
Author: Le Philousophe (lephilousophe at users.noreply.github.com)
Date: 2023-07-14T22:09:13+02:00
Commit Message:
COMMON: Don't use a pointer to T in UnalignedPtr
This lets the compiler think the pointer value could be aligned.
Changed paths:
common/ptr.h
diff --git a/common/ptr.h b/common/ptr.h
index 472b41ca668..69155cf77a4 100644
--- a/common/ptr.h
+++ b/common/ptr.h
@@ -785,7 +785,7 @@ public:
void store(const T &value) const;
private:
- T *_ptr;
+ void *_ptr;
};
template<class T>
More information about the Scummvm-git-logs
mailing list