From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 31759 invoked by alias); 3 Apr 2009 10:44:34 -0000 Received: (qmail 31750 invoked by uid 22791); 3 Apr 2009 10:44:33 -0000 X-SWARE-Spam-Status: No, hits=-1.1 required=5.0 tests=AWL,BAYES_50,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: sourceware.org Received: from mx2.redhat.com (HELO mx2.redhat.com) (66.187.237.31) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 03 Apr 2009 10:43:58 +0000 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n33Ahuno007721; Fri, 3 Apr 2009 06:43:56 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx2.corp.redhat.com (8.13.1/8.13.1) with ESMTP id n33Ahvws001817; Fri, 3 Apr 2009 06:43:57 -0400 Received: from zebedee.pink (vpn-12-137.rdu.redhat.com [10.11.12.137]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n33AhsQV002344; Fri, 3 Apr 2009 06:43:54 -0400 Message-ID: <49D5E868.50409@redhat.com> Date: Fri, 03 Apr 2009 10:44:00 -0000 From: Andrew Haley User-Agent: Thunderbird 2.0.0.17 (X11/20081009) MIME-Version: 1.0 To: Bryce McKinlay CC: Stephen Kell , java@gcc.gnu.org Subject: Re: CNI and interface methods References: <20090402193827.GD4939@font.cl.cam.ac.uk> <49D5CAD4.8040700@redhat.com> <7230133d0904030328o55069f0do9147f879bcbd5e4f@mail.gmail.com> In-Reply-To: <7230133d0904030328o55069f0do9147f879bcbd5e4f@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact java-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: java-owner@gcc.gnu.org X-SW-Source: 2009-04/txt/msg00010.txt.bz2 Bryce McKinlay wrote: > On Fri, Apr 3, 2009 at 9:37 AM, Andrew Haley 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.