[kaffe] CVS kaffe (robilad): small cleanup of newArrayChecked
Kaffe CVS
cvs-commits at kaffe.org
Wed Apr 5 18:48:19 PDT 2006
PatchSet 7215
Date: 2006/04/06 01:39:06
Author: robilad
Branch: HEAD
Tag: (none)
Log:
small cleanup of newArrayChecked
2006-04-06 Dalibor Topic <robilad at kaffe.org>
* kaffe/kaffevm/object.c (newArrayChecked): Added assert to check
that count is >= 0. Simplified a bit, and added casts to fix
compiler warnings.
* include/Arrays.h: Explicitely name structs in typedefs.
* kaffe/kaffevm/jit3/machine.h,
kaffe/kaffevm/jit/machine.h,
kaffe/kaffevm/intrp/machine.h: Include Arrays.h.
* kaffe/kaffevm/object.h (OBJECT_DTABLE_OFFSET)
(ARRAY_SIZE_OFFSET, ARRAY_DATA_OFFSET): Use offsetof instead of
wild casts.
Members:
ChangeLog:1.4721->1.4722
include/Arrays.h:1.6->1.7
kaffe/kaffevm/object.c:1.37->1.38
kaffe/kaffevm/object.h:1.8->1.9
kaffe/kaffevm/intrp/machine.h:1.13->1.14
kaffe/kaffevm/jit/machine.h:1.26->1.27
kaffe/kaffevm/jit3/machine.h:1.29->1.30
Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.4721 kaffe/ChangeLog:1.4722
--- kaffe/ChangeLog:1.4721 Wed Apr 5 23:00:14 2006
+++ kaffe/ChangeLog Thu Apr 6 01:39:06 2006
@@ -1,3 +1,19 @@
+2006-04-06 Dalibor Topic <robilad at kaffe.org>
+
+ * kaffe/kaffevm/object.c (newArrayChecked): Added assert to check
+ that count is >= 0. Simplified a bit, and added casts to fix
+ compiler warnings.
+
+ * include/Arrays.h: Explicitely name structs in typedefs.
+
+ * kaffe/kaffevm/jit3/machine.h,
+ kaffe/kaffevm/jit/machine.h,
+ kaffe/kaffevm/intrp/machine.h: Include Arrays.h.
+
+ * kaffe/kaffevm/object.h (OBJECT_DTABLE_OFFSET)
+ (ARRAY_SIZE_OFFSET, ARRAY_DATA_OFFSET): Use offsetof instead of
+ wild casts.
+
2006-04-05 Dalibor Topic <robilad at kaffe.org>
* libraries/clib/zip/CRC32.c: Use zlib implementation. Added
Index: kaffe/include/Arrays.h
diff -u kaffe/include/Arrays.h:1.6 kaffe/include/Arrays.h:1.7
--- kaffe/include/Arrays.h:1.6 Sun Sep 25 02:46:52 2005
+++ kaffe/include/Arrays.h Thu Apr 6 01:39:09 2006
@@ -15,16 +15,16 @@
/*
* Define various array types
*/
-typedef struct { Hjava_lang_Object base; jsize length; union { double align; jboolean body[1]; } data[1]; } HArrayOfBoolean;
-typedef struct { Hjava_lang_Object base; jsize length; union { double align; jbyte body[1]; } data[1]; } HArrayOfByte;
-typedef struct { Hjava_lang_Object base; jsize length; union { double align; jchar body[1]; } data[1]; } HArrayOfChar;
-typedef struct { Hjava_lang_Object base; jsize length; union { double align; jdouble body[1]; } data[1]; } HArrayOfDouble;
-typedef struct { Hjava_lang_Object base; jsize length; union { double align; jfloat body[1]; } data[1]; } HArrayOfFloat;
-typedef struct { Hjava_lang_Object base; jsize length; union { double align; jint body[1]; } data[1]; } HArrayOfInt;
-typedef struct { Hjava_lang_Object base; jsize length; union { double align; jshort body[1]; } data[1]; } HArrayOfShort;
-typedef struct { Hjava_lang_Object base; jsize length; union { double align; jlong body[1]; } data[1]; } HArrayOfLong;
-typedef struct { Hjava_lang_Object base; jsize length; union { double align; Hjava_lang_Object* body[1]; } data[1]; } HArrayOfArray;
-typedef struct { Hjava_lang_Object base; jsize length; union { double align; Hjava_lang_Object* body[1]; } data[1]; } HArrayOfObject;
+typedef struct HArrayOfBoolean { Hjava_lang_Object base; jsize length; union { double align; jboolean body[1]; } data[1]; } HArrayOfBoolean;
+typedef struct HArrayOfByte { Hjava_lang_Object base; jsize length; union { double align; jbyte body[1]; } data[1]; } HArrayOfByte;
+typedef struct HArrayOfChar { Hjava_lang_Object base; jsize length; union { double align; jchar body[1]; } data[1]; } HArrayOfChar;
+typedef struct HArrayOfDouble { Hjava_lang_Object base; jsize length; union { double align; jdouble body[1]; } data[1]; } HArrayOfDouble;
+typedef struct HArrayOfFloat { Hjava_lang_Object base; jsize length; union { double align; jfloat body[1]; } data[1]; } HArrayOfFloat;
+typedef struct HArrayOfInt { Hjava_lang_Object base; jsize length; union { double align; jint body[1]; } data[1]; } HArrayOfInt;
+typedef struct HArrayOfShort { Hjava_lang_Object base; jsize length; union { double align; jshort body[1]; } data[1]; } HArrayOfShort;
+typedef struct HArrayOfLong { Hjava_lang_Object base; jsize length; union { double align; jlong body[1]; } data[1]; } HArrayOfLong;
+typedef struct HArrayOfArray { Hjava_lang_Object base; jsize length; union { double align; Hjava_lang_Object* body[1]; } data[1]; } HArrayOfArray;
+typedef struct HArrayOfObject { Hjava_lang_Object base; jsize length; union { double align; Hjava_lang_Object* body[1]; } data[1]; } HArrayOfObject;
/* Get length of arrays */
#define obj_length(_obj) ((_obj)->length)
Index: kaffe/kaffe/kaffevm/object.c
diff -u kaffe/kaffe/kaffevm/object.c:1.37 kaffe/kaffe/kaffevm/object.c:1.38
--- kaffe/kaffe/kaffevm/object.c:1.37 Sun Oct 2 14:20:08 2005
+++ kaffe/kaffe/kaffevm/object.c Thu Apr 6 01:39:10 2006
@@ -15,6 +15,9 @@
#define ADBG(s)
#include "config.h"
+
+#include <assert.h>
+
#include "debug.h"
#include "config-std.h"
#include "config-mem.h"
@@ -137,12 +140,15 @@
Hjava_lang_Class* class = NULL;
Hjava_lang_Object* obj = NULL;
+ assert(count >= 0);
+
if ((class = lookupArray(elclass, info)) != NULL) {
size_t total_count;
+ const size_t MAX_MEM = KGC_MAX_MALLOC_TYPE - ARRAY_DATA_OFFSET;
if (CLASS_IS_PRIMITIVE(elclass) || elclass == PtrClass) {
- if (((KGC_MAX_MALLOC_TYPE - ARRAY_DATA_OFFSET) / TYPE_SIZE(elclass)) < count)
+ if ((MAX_MEM / TYPE_SIZE(elclass)) < (size_t) count)
{
postOutOfMemory(info);
}
@@ -155,7 +161,7 @@
}
}
else {
- if (((KGC_MAX_MALLOC_TYPE - ARRAY_DATA_OFFSET) / PTR_TYPE_SIZE) < count)
+ if ((MAX_MEM / PTR_TYPE_SIZE) < (size_t) count)
{
postOutOfMemory(info);
}
Index: kaffe/kaffe/kaffevm/object.h
diff -u kaffe/kaffe/kaffevm/object.h:1.8 kaffe/kaffe/kaffevm/object.h:1.9
--- kaffe/kaffe/kaffevm/object.h:1.8 Sat May 7 16:20:10 2005
+++ kaffe/kaffe/kaffevm/object.h Thu Apr 6 01:39:10 2006
@@ -30,11 +30,11 @@
#define OBJARRAY_DATA(ARRAY) ((Hjava_lang_Object**)&(((HArrayOfObject*)(ARRAY))->data))
/*
- * These bizzare casts provide various offset into the object structure.
+ * Offsets into the object structure.
*/
-#define OBJECT_DTABLE_OFFSET ((int)&(*(Hjava_lang_Object*)0).vtable)
-#define ARRAY_SIZE_OFFSET ((int)&ARRAY_SIZE(0))
-#define ARRAY_DATA_OFFSET ((int)ARRAY_DATA(0))
+#define OBJECT_DTABLE_OFFSET (offsetof(struct Hjava_lang_Object, vtable))
+#define ARRAY_SIZE_OFFSET (offsetof(struct HArrayOfObject, length))
+#define ARRAY_DATA_OFFSET (offsetof(struct HArrayOfObject, data))
struct Hjava_lang_Class;
struct _errorInfo;
Index: kaffe/kaffe/kaffevm/intrp/machine.h
diff -u kaffe/kaffe/kaffevm/intrp/machine.h:1.13 kaffe/kaffe/kaffevm/intrp/machine.h:1.14
--- kaffe/kaffe/kaffevm/intrp/machine.h:1.13 Thu Mar 30 17:39:17 2006
+++ kaffe/kaffe/kaffevm/intrp/machine.h Thu Apr 6 01:39:10 2006
@@ -11,6 +11,7 @@
#ifndef __machine_h
#define __machine_h
+#include "object.h"
#include "threadData.h"
#define current_class() (meth->class)
Index: kaffe/kaffe/kaffevm/jit/machine.h
diff -u kaffe/kaffe/kaffevm/jit/machine.h:1.26 kaffe/kaffe/kaffevm/jit/machine.h:1.27
--- kaffe/kaffe/kaffevm/jit/machine.h:1.26 Thu Mar 30 17:39:17 2006
+++ kaffe/kaffe/kaffevm/jit/machine.h Thu Apr 6 01:39:10 2006
@@ -12,6 +12,7 @@
#include "errors.h"
#include "gtypes.h"
+#include "object.h"
/* -------------------------------------------------------------------- */
Index: kaffe/kaffe/kaffevm/jit3/machine.h
diff -u kaffe/kaffe/kaffevm/jit3/machine.h:1.29 kaffe/kaffe/kaffevm/jit3/machine.h:1.30
--- kaffe/kaffe/kaffevm/jit3/machine.h:1.29 Thu Mar 30 17:39:17 2006
+++ kaffe/kaffe/kaffevm/jit3/machine.h Thu Apr 6 01:39:11 2006
@@ -14,6 +14,7 @@
#define __machine_h
#include "gtypes.h"
+#include "object.h"
/* -------------------------------------------------------------------- */
More information about the kaffe
mailing list