summaryrefslogtreecommitdiff
path: root/libjava
diff options
context:
space:
mode:
authorTom Tromey <tromey@cygnus.com>2000-11-27 04:05:23 +0000
committerTom Tromey <tromey@gcc.gnu.org>2000-11-27 04:05:23 +0000
commit2721806e9811dee451f847eba2e9655979ad4065 (patch)
treecb35dd525aae041b32949744d19afafd5d184626 /libjava
parent18205ca3b63fa0536ce6db35b4f1e264bdda5276 (diff)
downloadgcc-2721806e9811dee451f847eba2e9655979ad4065.tar.gz
prims.cc (_Jv_NewObjectArray): Use const_cast to initialize length field of array.
* 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. From-SVN: r37771
Diffstat (limited to 'libjava')
-rw-r--r--libjava/ChangeLog8
-rw-r--r--libjava/gcj/array.h9
-rw-r--r--libjava/prims.cc10
3 files changed, 23 insertions, 4 deletions
diff --git a/libjava/ChangeLog b/libjava/ChangeLog
index 00e95143bf6..5c645632735 100644
--- a/libjava/ChangeLog
+++ b/libjava/ChangeLog
@@ -1,3 +1,11 @@
+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.
+
2000-11-26 Anthony Green <green@redhat.com>
* javax/naming/spi/NamingManager.java,
diff --git a/libjava/gcj/array.h b/libjava/gcj/array.h
index b3ba9938228..8d280857ffe 100644
--- a/libjava/gcj/array.h
+++ b/libjava/gcj/array.h
@@ -17,8 +17,15 @@ extern "Java" {
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*);
};
diff --git a/libjava/prims.cc b/libjava/prims.cc
index b6ac7f87b81..c6b8d2030e1 100644
--- a/libjava/prims.cc
+++ b/libjava/prims.cc
@@ -411,8 +411,10 @@ _Jv_NewObjectArray (jsize count, jclass elementClass, jobject init)
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 @@ _Jv_NewPrimArray (jclass eltype, jint count)
__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;