summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDarkvater <Darkvater@openttd.org>2006-02-23 20:53:30 +0000
committerDarkvater <Darkvater@openttd.org>2006-02-23 20:53:30 +0000
commitf3b50cdd35b3b276a0a0a6e7416c629f91995919 (patch)
tree17eeea5924c72a01259a6978e1fb10a8caa9e503
parent6e4bd06aa18d89bdd4cf2d5c45bf95136bf3c22f (diff)
downloadopenttd-f3b50cdd35b3b276a0a0a6e7416c629f91995919.tar.xz
(svn r3662) Fix regression FS#58 with union, endiannes and static decleration problems. Removed the union.
-rw-r--r--saveload.c6
-rw-r--r--saveload.h16
2 files changed, 9 insertions, 13 deletions
diff --git a/saveload.c b/saveload.c
index 0eb33e1fd..55d423391 100644
--- a/saveload.c
+++ b/saveload.c
@@ -580,7 +580,7 @@ size_t SlCalcObjMemberLength(const SaveLoad *sld)
case SL_VAR: return SlCalcConvFileLen(sld->conv);
case SL_REF: return SlCalcRefLen();
case SL_ARR: return SlCalcArrayLen(sld->length, sld->conv);
- case SL_STR: return SlCalcStringLen(sld->s.address, sld->length);
+ case SL_STR: return SlCalcStringLen(sld->address, sld->length);
default: NOT_REACHED();
}
break;
@@ -655,7 +655,7 @@ void SlObject(void *object, const SaveLoad *sld)
}
for (; sld->cmd != SL_END; sld++) {
- void *ptr = (byte*)object + sld->s.offset;
+ void *ptr = (byte*)object + (unsigned long)sld->address;
SlObjectMember(ptr, sld);
}
}
@@ -672,7 +672,7 @@ void SlGlobList(const SaveLoadGlobVarList *sldg)
}
for (; sldg->cmd != SL_END; sldg++) {
- SlObjectMember(sldg->s.address, (const SaveLoad*)sldg);
+ SlObjectMember(sldg->address, (const SaveLoad*)sldg);
}
}
diff --git a/saveload.h b/saveload.h
index 3c54eedd6..972953a1e 100644
--- a/saveload.h
+++ b/saveload.h
@@ -136,7 +136,6 @@ enum SaveLoadTypes {
};
typedef byte SaveLoadType;
-typedef uint32 OffSetType;
/** SaveLoad type struct. Do NOT use this directly but use the SLE_ macros defined just below! */
typedef struct SaveLoad {
@@ -149,17 +148,14 @@ typedef struct SaveLoad {
* variable, or the offset within a struct which is then bound to a variable
* during runtime. Decision on which one to use is controlled by the function
* that is called to save it. address: SlGlobList, offset: SlObject */
- union {
- void *address; /// address of variable
- OffSetType offset; /// offset of variable in the struct (max offset is 65536)
- } s;
+ void *address; /// address of variable OR offset of variable in the struct (max offset is 65536)
} SaveLoad;
/* Same as SaveLoad but global variables are used (for better readability); */
typedef SaveLoad SaveLoadGlobVarList;
/* Simple variables, references (pointers) and arrays */
-#define SLE_GENERAL(cmd, base, variable, type, length, from, to) {cmd, type, length, from, to, {(void*)offsetof(base, variable)}}
+#define SLE_GENERAL(cmd, base, variable, type, length, from, to) {cmd, type, length, from, to, (void*)offsetof(base, variable)}
#define SLE_CONDVAR(base, variable, type, from, to) SLE_GENERAL(SL_VAR, base, variable, type, 0, from, to)
#define SLE_CONDREF(base, variable, type, from, to) SLE_GENERAL(SL_REF, base, variable, type, 0, from, to)
#define SLE_CONDARR(base, variable, type, length, from, to) SLE_GENERAL(SL_ARR, base, variable, type, length, from, to)
@@ -176,7 +172,7 @@ typedef SaveLoad SaveLoadGlobVarList;
#define SLE_INCLUDE(base, variable, include_index) SLE_GENERAL(SL_INCLUDE, base, variable, 0, 0, include_index, 0)
/* The same as the ones at the top, only the offset is given directly; used for unions */
-#define SLE_GENERALX(cmd, offset, type, param1, param2) {cmd, type, 0, param1, param2, {(void*)(offset)}}
+#define SLE_GENERALX(cmd, offset, type, param1, param2) {cmd, type, 0, param1, param2, (void*)(offset)}
#define SLE_CONDVARX(offset, type, from, to) SLE_GENERALX(SL_VAR, offset, type, from, to)
#define SLE_CONDREFX(offset, type, from, to) SLE_GENERALX(SL_REF, offset, type, from, to)
@@ -187,10 +183,10 @@ typedef SaveLoad SaveLoadGlobVarList;
#define SLE_INCLUDEX(offset, type) SLE_GENERALX(SL_INCLUDE, offset, type, 0, SL_MAX_VERSION)
/* End marker */
-#define SLE_END() {SL_END, 0, 0, 0, 0, {(void*)0}}
+#define SLE_END() {SL_END, 0, 0, 0, 0, NULL}
/* Simple variables, references (pointers) and arrays, but for global variables */
-#define SLEG_GENERAL(cmd, variable, type, length, from, to) {cmd, type, length, from, to, {&variable}}
+#define SLEG_GENERAL(cmd, variable, type, length, from, to) {cmd, type, length, from, to, (void*)&variable}
#define SLEG_CONDVAR(variable, type, from, to) SLEG_GENERAL(SL_VAR, variable, type, 0, from, to)
#define SLEG_CONDREF(variable, type, from, to) SLEG_GENERAL(SL_REF, variable, type, 0, from, to)
@@ -202,7 +198,7 @@ typedef SaveLoad SaveLoadGlobVarList;
#define SLEG_ARR(variable, type) SLEG_CONDARR(variable, type, lengthof(variable), SL_MAX_VERSION)
#define SLEG_STR(variable, type) SLEG_CONDSTR(variable, type, lengthof(variable), SL_MAX_VERSION)
-#define SLEG_END() {SL_END, 0, 0, 0, 0, {NULL}}
+#define SLEG_END() {SL_END, 0, 0, 0, 0, NULL}
/** Checks if the savegame is below major.minor.
*/