This is the mail archive of the java-patches@sources.redhat.com mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Patch: const again


I'm checking this in.  It is a simpler approach to making the array
length field `const'.

2000-11-26  Tom Tromey  <tromey@cygnus.com>

	* prims.cc (_Jv_NewObjectArray): Use const_cast to initialize
	length field of array.
	(_Jv_NewPrimArray): Likewise.
	* gcj/array.h (__JArray): `length' field now const.  Added
	constructor.

Tom

Index: prims.cc
===================================================================
RCS file: /cvs/java/libgcj/libjava/prims.cc,v
retrieving revision 1.41
diff -u -r1.41 prims.cc
--- prims.cc	2000/11/26 03:58:55	1.41
+++ prims.cc	2000/11/27 04:03:54
@@ -411,8 +411,10 @@
   obj = (jobjectArray) _Jv_AllocArray (size, klass);
   if (__builtin_expect (! obj, false))
     JvThrow (no_memory);
-  obj->length = count;
-  jobject *ptr = elements (obj);
+  // Cast away const.
+  jsize *lp = const_cast<jsize *> (&obj->length);
+  *lp = count;
+  jobject *ptr = elements(obj);
   // We know the allocator returns zeroed memory.  So don't bother
   // zeroing it again.
   if (init)
@@ -446,7 +448,9 @@
   __JArray *arr = (__JArray*) _Jv_AllocObj (size + elsize * count, klass);
   if (__builtin_expect (! arr, false))
     JvThrow (no_memory);
-  arr->length = count;
+  // Cast away const.
+  jsize *lp = const_cast<jsize *> (&arr->length);
+  *lp = count;
   // Note that we assume we are given zeroed memory by the allocator.
 
   return arr;
Index: gcj/array.h
===================================================================
RCS file: /cvs/java/libgcj/libjava/gcj/array.h,v
retrieving revision 1.10
diff -u -r1.10 array.h
--- array.h	2000/11/26 03:58:55	1.10
+++ array.h	2000/11/27 04:03:55
@@ -17,8 +17,15 @@
 
 class __JArray : public java::lang::Object
 {
+protected:
+  // This is just a hack to work around a warning emitted by the C++
+  // compiler.  We initialize `length' evilly, but it doesn't know
+  // that.
+  __JArray () : length (0)
+  {
+  }
 public:
-  jsize length;
+  const jsize length;
   friend jsize JvGetArrayLength (__JArray*);
 };
 

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]