This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
Re: CNI and interface methods
- From: Stephen Kell <srk31 at srcf dot ucam dot org>
- To: Bryce McKinlay <bmckinlay at gmail dot com>
- Cc: Andrew Haley <aph at redhat dot com>, java at gcc dot gnu dot org
- Date: Fri, 3 Apr 2009 18:53:55 +0100
- Subject: Re: CNI and interface methods
- References: <20090402193827.GD4939@font.cl.cam.ac.uk> <49D5CAD4.8040700@redhat.com> <7230133d0904030328o55069f0do9147f879bcbd5e4f@mail.gmail.com>
> 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