Re: CNI and interface methods

Andrew Haley <[email protected]>
Newsgroups gmane.comp.gcc.java.devel
Message-ID <[email protected]>
Bryce McKinlay wrote:
> On Fri, Apr 3, 2009 at 9:37 AM, Andrew Haley <[email protected]> wrote:
> 
>> Stephen Kell wrote:
>>
>>> I'm using CNI for the first time and have hit a query. What exactly is
>>> and isn't supposed to work when invoking interface methods through
>>> *object* references (from C++, so I mean pointers), and passing these
>>> references around?
>>>
>>> The CNI chapter in the gcj manual says a lot about interface references,
>>> but not about the case of using object references where that object's
>>> class implements one or more interfaces. One thing that would appear to
>>> be worth mentioning is that clearly, passing them to methods wanting an
>>> interface reference won't compile without some sort of cast, since the
>>> gcjh-generated headers don't encode the subtyping relationship between
>>> interfaces and their implementing classes. I'm guessing a simple static
>>> cast isn't the right thing to do though, because I'm getting segfaults
>>> when I try.
>
>> Right.  To put it simply, we have never got around to implementing Java
>> interface calls in CNI.  It wouldn't be enormously difficult, but it
>> needs some way to tell the C++ compiler about interface calls.  We could
>> have implemented Java interfaces via C++ multiple inheritance but we
>> didn't, so we would need to invent some sort of notation to express the
>> idea of an interface to the C++ compiler.
> 
> 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

Ah yes, thanks for the clarification.

Andrew.
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.