This is the mail archive of the java@gcc.gnu.org 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]
Other format: [Raw text]

Re: CNI and interface methods


Stephen Kell wrote:
>> Actually we did implement a rather limited form of interface calls in
>> CNI. Interfaces types are described in CNI headers with __attribute__
>> ((java_interface)), and the C++ compiler knows how to call a method
>> on a type declared as such.
>>
>> What is missing in the C++ compiler (and the CNI headers) is
>> knowledge of interface inheritance, so you have to manually cast
>> interface references if the method you want to call was declared in a
>> super-interface.
>>
>> This limitation is described here:
>>
>> http://gcc.gnu.org/onlinedocs/gcj/Interfaces.html
> 
> Thanks for this. I'm fine with that limitation, but there seems to be a
> second thing missing too (missing in the same sense, i.e. that it
> requires casts that ideally wouldn't be there). The question was: from
> the C++ side, given a pointer p to some object implementing interface
> J, is it safe to pass that pointer to a Java method who CNI prototype
> looks like, for example,
> 
> void foo(J *arg);
> 
> or not? Clearly from C++ we can't do
> 
> foo(p);
> 
> because it won't type-check; but we can do the following.
> 
> foo((J*) p);
> 
> It now appears the answer is "yes, this is okay" (whereas I'd been
> worried that maybe some multiple-inheritance-style pointer adjustment
> was not being done and was causing the segfaults I was seeing). 
> 
> The CNI docs should probably say that these casts are fine and
> indeed required. I'll gladly submit a small patch to the docs if you
> agree (and let me know where's best for me to send it).

java-patches is the best place to send it.  In this case, an example is
worth a thousand words.  If you could write a reasonably small one to
insert in your description, that would be great.

Please don't write much, or we'd need to ask you for a copyright
assignment.

Andrew.


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