[Scummvm-cvs-logs] SF.net SVN: scummvm:[33566] residual/trunk/engine/lua

aquadran at users.sourceforge.net aquadran at users.sourceforge.net
Sun Aug 3 11:43:35 CEST 2008


Revision: 33566
          http://scummvm.svn.sourceforge.net/scummvm/?rev=33566&view=rev
Author:   aquadran
Date:     2008-08-03 09:43:34 +0000 (Sun, 03 Aug 2008)

Log Message:
-----------
a bit more portability

Modified Paths:
--------------
    residual/trunk/engine/lua/lmem.cpp
    residual/trunk/engine/lua/lobject.h
    residual/trunk/engine/lua/lstring.cpp
    residual/trunk/engine/lua/ltable.cpp

Modified: residual/trunk/engine/lua/lmem.cpp
===================================================================
--- residual/trunk/engine/lua/lmem.cpp	2008-08-03 09:41:10 UTC (rev 33565)
+++ residual/trunk/engine/lua/lmem.cpp	2008-08-03 09:43:34 UTC (rev 33566)
@@ -50,7 +50,7 @@
 int32 totalmem = 0;
 
 static void *checkblock(void *block) {
-	int32 *b = (uint32 *)((char *)block - HEADER);
+	int32 *b = (int32 *)((char *)block - HEADER);
 	int32 size = *b;
 	LUA_ASSERT(*(((char *)b) + size + HEADER) == MARK, "corrupted block");
 	numblocks--;

Modified: residual/trunk/engine/lua/lobject.h
===================================================================
--- residual/trunk/engine/lua/lobject.h	2008-08-03 09:41:10 UTC (rev 33565)
+++ residual/trunk/engine/lua/lobject.h	2008-08-03 09:43:34 UTC (rev 33566)
@@ -90,7 +90,7 @@
 
 typedef struct TaggedString {
 	GCnode head;
-	unsigned long hash;
+	uint32 hash;
 	int32 constindex;  // hint to reuse constants (= -1 if this is a userdata)
 	union {
 		struct {

Modified: residual/trunk/engine/lua/lstring.cpp
===================================================================
--- residual/trunk/engine/lua/lstring.cpp	2008-08-03 09:41:10 UTC (rev 33565)
+++ residual/trunk/engine/lua/lstring.cpp	2008-08-03 09:43:34 UTC (rev 33566)
@@ -4,6 +4,7 @@
 ** See Copyright Notice in lua.h
 */
 
+#include "common/util.h"
 
 #include "engine/lua/lmem.h"
 #include "engine/lua/lobject.h"
@@ -29,7 +30,7 @@
 static uint32 hash_s(const char *s, int32 l) {
 	uint32 h = 0;
 	while (l--)
-		h = ((h << 5) - h) ^ (byte) * (s++);
+		h = ((h << 5) - h) ^ (byte)*(s++);
 	return h;
 }
 
@@ -103,14 +104,14 @@
 	int32 size = tb->size;
 	int32 i;
 	int32 j = -1;
-	if ((int32)tb->nuse * 3 >= size * 2) {
+	if (tb->nuse * 3 >= size * 2) {
 		grow(tb);
 		size = tb->size;
 	}
 	for (i = h % size; (ts = tb->hash[i]); ) {
 		if (ts == &EMPTY)
 			j = i;
-		else if (ts->constindex >= 0 && ts->u.s.len == l && (memcmp(str, ts->str, l) == 0))
+		else if (ts->constindex >= 0 && ts->u.s.len == l && (memcmp(str, ts->str, MAX(l, ts->u.s.len)) == 0))
 			return ts;
 		if (++i == size)
 			i = 0;
@@ -126,7 +127,11 @@
 
 static TaggedString *insert_u(void *buff, int32 tag, stringtable *tb) {
 	TaggedString *ts;
-	unsigned long h = (unsigned long)buff;
+#ifdef TARGET_64BITS
+	uint32 h = (uint64)buff;
+#else
+	uint32 h = (uint32)buff;
+#endif
 	int32 size = tb->size;
 	int32 i;
 	int32 j = -1;
@@ -147,12 +152,16 @@
 		i = j;
 	else
 		tb->nuse++;
-	ts = tb->hash[i] = newone_u((char*)buff, tag, h);
+	ts = tb->hash[i] = newone_u((char *)buff, tag, h);
 	return ts;
 }
 
 TaggedString *luaS_createudata(void *udata, int32 tag) {
-	return insert_u(udata, tag, &L->string_root[(unsigned long)udata % NUM_HASHS]);
+#ifdef TARGET_64BITS
+	return insert_u(udata, tag, &L->string_root[(uint64)udata % NUM_HASHS]);
+#else
+	return insert_u(udata, tag, &L->string_root[(uint32)udata % NUM_HASHS]);
+#endif
 }
 
 TaggedString *luaS_newlstr(const char *str, int32 l) {

Modified: residual/trunk/engine/lua/ltable.cpp
===================================================================
--- residual/trunk/engine/lua/ltable.cpp	2008-08-03 09:41:10 UTC (rev 33565)
+++ residual/trunk/engine/lua/ltable.cpp	2008-08-03 09:43:34 UTC (rev 33566)
@@ -17,30 +17,32 @@
 #define REHASH_LIMIT	0.70    // avoid more than this % full
 #define TagDefault		LUA_T_ARRAY;
 
-static long int hashindex(TObject *ref) {
-	long int h;
+#ifdef TARGET_64BITS
+static int64 int hashindex(TObject *ref) {
+	int64 h;
+
 	switch (ttype(ref)) {
 	case LUA_T_NUMBER:
-		h = (long int)nvalue(ref);
+		h = (int64)nvalue(ref);
 		break;
 	case LUA_T_STRING:
 	case LUA_T_USERDATA:
-		h = (long int)tsvalue(ref);
+		h = (int64)tsvalue(ref);
 		break;
 	case LUA_T_ARRAY:
-		h = (long int)avalue(ref);
+		h = (int64)avalue(ref);
 		break;
 	case LUA_T_PROTO:
-		h = (long int)tfvalue(ref);
+		h = (int64)tfvalue(ref);
 		break;
 	case LUA_T_CPROTO:
-		h = (long int)fvalue(ref);
+		h = (int64)fvalue(ref);
 		break;
 	case LUA_T_CLOSURE:
-		h = (long int)clvalue(ref);
+		h = (int64)clvalue(ref);
 		break;
 	case LUA_T_TASK:
-		h = (long int)nvalue(ref);
+		h = (int64)nvalue(ref);
 		break;
 	default:
 		lua_error("unexpected type to index table");
@@ -49,9 +51,46 @@
 	return (h >= 0 ? h : -(h + 1));
 }
 
+#else
+
+static int32 hashindex(TObject *ref) {
+	int32 h;
+
+	switch (ttype(ref)) {
+	case LUA_T_NUMBER:
+		h = (int32)nvalue(ref);
+		break;
+	case LUA_T_STRING:
+	case LUA_T_USERDATA:
+		h = (int32)tsvalue(ref);
+		break;
+	case LUA_T_ARRAY:
+		h = (int32)avalue(ref);
+		break;
+	case LUA_T_PROTO:
+		h = (int32)tfvalue(ref);
+		break;
+	case LUA_T_CPROTO:
+		h = (int32)fvalue(ref);
+		break;
+	case LUA_T_CLOSURE:
+		h = (int32)clvalue(ref);
+		break;
+	case LUA_T_TASK:
+		h = (int32)nvalue(ref);
+		break;
+	default:
+		lua_error("unexpected type to index table");
+		h = 0;  // to avoid warnings
+	}
+	return (h >= 0 ? h : -(h + 1));
+}
+
+#endif
+
 int32 present(Hash *t, TObject *key) {
 	int32 tsize = nhash(t);
-	long int h = hashindex(key);
+	int32 h = (int32)hashindex(key);
 	int32 h1 = h % tsize;
 	TObject *rf = ref(node(t, h1));
 	if (ttype(rf) != LUA_T_NIL && !luaO_equalObj(key, rf)) {


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list