aboutsummaryrefslogtreecommitdiff
path: root/libjava
diff options
context:
space:
mode:
authorTom Tromey <tromey@cygnus.com>2000-11-24 21:02:36 +0000
committerTom Tromey <tromey@gcc.gnu.org>2000-11-24 21:02:36 +0000
commitad86a903a28cb259d55d9abc95c5e091acc92143 (patch)
treed4054b9ccee889a0365a1284dd577cf7e13c7d0c /libjava
parent81d87b4e64fe9c7a72791a70e680df452cfc9e37 (diff)
downloadgcc-ad86a903a28cb259d55d9abc95c5e091acc92143.zip
gcc-ad86a903a28cb259d55d9abc95c5e091acc92143.tar.gz
gcc-ad86a903a28cb259d55d9abc95c5e091acc92143.tar.bz2
prims.cc (_Jv_NewObjectArray): Use palcement new to create array.
* prims.cc (_Jv_NewObjectArray): Use palcement new to create array. (_Jv_NewPrimArray): Likewise. Include <new>. * gcj/array.h (__JArray): `length' field now const. Added constructor. (class JArray): Added constructor. From-SVN: r37718
Diffstat (limited to 'libjava')
-rw-r--r--libjava/ChangeLog10
-rw-r--r--libjava/gcj/array.h18
-rw-r--r--libjava/prims.cc11
3 files changed, 32 insertions, 7 deletions
diff --git a/libjava/ChangeLog b/libjava/ChangeLog
index d9ea6b5..1d7f179 100644
--- a/libjava/ChangeLog
+++ b/libjava/ChangeLog
@@ -1,3 +1,13 @@
+2000-11-24 Tom Tromey <tromey@cygnus.com>
+
+ * prims.cc (_Jv_NewObjectArray): Use palcement new to create
+ array.
+ (_Jv_NewPrimArray): Likewise.
+ Include <new>.
+ * gcj/array.h (__JArray): `length' field now const. Added
+ constructor.
+ (class JArray): Added constructor.
+
2000-11-23 Mark Wielaard <mark@klomp.org>
* name-finder.cc (lookup): Check for a NULL _Jv_argv before attempting
diff --git a/libjava/gcj/array.h b/libjava/gcj/array.h
index 8b0a416..7c65924 100644
--- a/libjava/gcj/array.h
+++ b/libjava/gcj/array.h
@@ -1,6 +1,6 @@
// array.h - Header file for CNI arrays. -*- c++ -*-
-/* Copyright (C) 1998, 1999 Free Software Foundation
+/* Copyright (C) 1998, 1999, 2000 Free Software Foundation
This file is part of libgcj.
@@ -17,11 +17,21 @@ extern "Java" {
class __JArray : public java::lang::Object
{
+protected:
+ // FIXME: this is a hack to work around a bug in the g++ Java
+ // support. If we add a constructor with a jsize argument to
+ // JArray<T>, then g++ complains.
+ __JArray () : length (0)
+ {
+ }
public:
- // FIXME: we'd like this to be `const' but that causes problems with
- // the C++ compiler.
- jsize length;
+ const jsize length;
friend jsize JvGetArrayLength (__JArray*);
+
+ // This probably shouldn't be public.
+ __JArray (jsize l) : length (l)
+ {
+ }
};
template<class T>
diff --git a/libjava/prims.cc b/libjava/prims.cc
index 8ca05da..22fa4b6 100644
--- a/libjava/prims.cc
+++ b/libjava/prims.cc
@@ -67,6 +67,9 @@ details. */
#include <ltdl.h>
#endif
+// We use placement new.
+#include <new>
+
// We allocate a single OutOfMemoryError exception which we keep
// around for use if we run out of memory.
static java::lang::OutOfMemoryError *no_memory;
@@ -411,8 +414,9 @@ _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);
+ // Use placement new to initialize length field.
+ new (obj) __JArray (count);
+ jobject *ptr = elements(obj);
// We know the allocator returns zeroed memory. So don't bother
// zeroing it again.
if (init)
@@ -446,7 +450,8 @@ _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;
+ // Use placement new to initialize length field.
+ new (arr) __JArray (count);
// Note that we assume we are given zeroed memory by the allocator.
return arr;