Re: CNI and interface methods

Stephen Kell <[email protected]>
Newsgroups gmane.comp.gcc.java.devel
Message-ID <[email protected]>
> 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).

Stephen
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.