public inbox for java@gcc.gnu.org
 help / color / mirror / Atom feed
From: Andrew Haley <aph@redhat.com>
To: Stephen Kell <srk31@srcf.ucam.org>
Cc: Bryce McKinlay <bmckinlay@gmail.com>, java@gcc.gnu.org
Subject: Re: CNI and interface methods
Date: Sat, 04 Apr 2009 09:12:00 -0000	[thread overview]
Message-ID: <49D72466.10309@redhat.com> (raw)
In-Reply-To: <20090403185355.1ba66c55@ernest-2.christs.cam.ac.uk>

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.

  parent reply	other threads:[~2009-04-04  9:12 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-02 19:38 Stephen Kell
2009-04-03  8:37 ` Andrew Haley
2009-04-03 10:35   ` Bryce McKinlay
2009-04-03 13:57   ` Stephen Kell
2009-04-03 14:13     ` Andrew Haley
2009-04-03 18:42       ` Stephen Kell
     [not found]   ` <7230133d0904030328o55069f0do9147f879bcbd5e4f@mail.gmail.com>
2009-04-03 10:44     ` Andrew Haley
2009-04-03 18:54     ` Stephen Kell
2009-04-03 19:06       ` David Daney
2009-04-04  9:12       ` Andrew Haley [this message]
  -- strict thread matches above, loose matches on Subject: below --
2000-04-01  0:00 Oskar Liljeblad
2000-04-01  0:00 ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=49D72466.10309@redhat.com \
    --to=aph@redhat.com \
    --cc=bmckinlay@gmail.com \
    --cc=java@gcc.gnu.org \
    --cc=srk31@srcf.ucam.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).