From 2ec3adfad531b7e1f698c338545fb9817f99e5b1 Mon Sep 17 00:00:00 2001 From: Adrian Astley Date: Fri, 12 Sep 2014 16:04:38 -0500 Subject: SWORD25: Make save files x32/x64 agnostic --- engines/sword25/util/pluto/pluto.cpp | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) (limited to 'engines/sword25/util') diff --git a/engines/sword25/util/pluto/pluto.cpp b/engines/sword25/util/pluto/pluto.cpp index fb477c1687..78b0a815e8 100644 --- a/engines/sword25/util/pluto/pluto.cpp +++ b/engines/sword25/util/pluto/pluto.cpp @@ -835,7 +835,15 @@ static void persistthread(PersistInfo *pi) #endif write_size(pi, &stackbase); write_size(pi, &stacktop); + + // ptrdiff_t changes sizes based on 32/64 bit + // Hard cast to 64 bit size if SIZE64 is defined +#ifdef SIZES64 + uint64 ptrIndex = static_cast(L2->errfunc); + pi_write(pi, &ptrIndex, sizeof(uint64), pi->ud); +#else pi_write(pi, &L2->errfunc, sizeof(ptrdiff_t), pi->ud); +#endif //write_size(pi, (size_t *)&L2->errfunc); } @@ -944,12 +952,6 @@ static void persist(PersistInfo *pi) if(!lua_isnil(pi->L, -1)) { /* perms reftbl ... obj ref */ int zero = 0; - // FIXME: Casting a pointer to an integer data type is a bad idea we - // should really get rid of this by fixing the design of this code. - // For now casting to size_t should silence most (all?) compilers, - // since size_t is supposedly the same size as a pointer on most - // (modern) architectures. - int ref = (int)(size_t)lua_touserdata(pi->L, -1); pi_write(pi, &zero, sizeof(int), pi->ud); if (humanReadable) { snprintf(hrBuf, hrBufSize, "persist_seenobject\n"); @@ -958,7 +960,8 @@ static void persist(PersistInfo *pi) #ifdef TOTEXT printf("persist_seenobject\n"); #endif - pi_write(pi, &ref, sizeof(int), pi->ud); + int *ref = (int *)lua_touserdata(pi->L, -1); + pi_write(pi, ref, sizeof(int), pi->ud); if (humanReadable) { snprintf(hrBuf, hrBufSize, "persist_touserdata_ref %d\n", ref); hrOut(pi); @@ -1011,7 +1014,8 @@ static void persist(PersistInfo *pi) } lua_pushvalue(pi->L, -1); /* perms reftbl ... obj obj */ - lua_pushlightuserdata(pi->L, (void *)(++(pi->counter))); + int *ref = (int *)lua_newuserdata(pi->L, sizeof(int)); + *ref = ++(pi->counter); /* perms reftbl ... obj obj ref */ lua_rawset(pi->L, 2); /* perms reftbl ... obj */ @@ -1737,7 +1741,16 @@ static void unpersistthread(int ref, UnpersistInfo *upi) verify(LIF(Z,read)(&upi->zio, &L2->status, sizeof(lu_byte)) == 0); read_size(&upi->zio, &stackbase); read_size(&upi->zio, &stacktop); + +#ifdef SIZES64 + uint64 value; + verify(LIF(Z,read)(&upi->zio, &value, sizeof(uint64)) == 0); + + L2->errfunc = static_cast(value); +#else verify(LIF(Z,read)(&upi->zio, &L2->errfunc, sizeof(ptrdiff_t)) == 0); +#endif + //read_size(&upi->zio, (size_t *)&L2->errfunc); L2->base = L2->stack + stackbase; L2->top = L2->stack + stacktop; -- cgit v1.2.3