libgcj/4439: CNI: would be nice to be able to create Java array with 'new'

Bryce McKinlay bryce@waitaki.otago.ac.nz
Tue Oct 2 22:46:00 GMT 2001


>
>
>> This is wrong. I'm not trying to create a Java array, I'm trying to 
>> create a C array of a Java primitive type, that I can pass to 
>> GetBooleanArrayRegion as the "jboolean*" parameter:
>>
>>     jboolean* buffer = new jboolean[n];     // compiler fails here
>>     env->GetBooleanArrayRegion(javaArray,0,n,buffer);
>>     foo(buffer);
>>     delete[] buffer;
>>
>
> OK. This is a problem with our jni.h: jboolean is declared within an 
> extern "Java" when building a C++ file.
>
> Tom, can we avoid including gcj/javaprims.h from jni.h? 



On second thought, the syntax for creating a Java array in CNI would be 
"new JArray<jboolean>[1]", so I guess "new jboolean[1]" should do what 
Ashley expects and create a non-GC-allocated C array.

Ashley, could you try this (untested) patch?

Bryce.


Index: init.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/init.c,v
retrieving revision 1.248
diff -u -r1.248 init.c
--- init.c      2001/08/02 10:51:16     1.248
+++ init.c      2001/10/03 05:45:00
@@ -2350,7 +2350,9 @@
 
   /* Allocate the object.  */
  
-  if (! placement && TYPE_FOR_JAVA (true_type))
+  if (! placement
+      && TREE_CODE (true_type) == RECORD_TYPE
+      && TYPE_FOR_JAVA (true_type))
     {
       tree class_addr, alloc_decl;
       tree class_decl = build_java_class_ref (true_type);

regards

Bryce.




More information about the Gcc-bugs mailing list