From: James Alan Farrell <jfarrell@nospam.com>
Subject: Re: Java wrappers around Ada?
Date: Fri, 24 Mar 2006 16:40:55 -0500
Date: 2006-03-24T16:40:55-05:00 [thread overview]
Message-ID: <442466a1_1@newsfeed.slurp.net> (raw)
In-Reply-To: <1143154793.188596.117060@j33g2000cwa.googlegroups.com>
[-- Attachment #1: Type: text/plain, Size: 2532 bytes --]
kk_oop@yahoo.com wrote:
> James Alan Farrell wrote:
>
>>We have a similar problem with C, and found it is pretty straight
>>forward to wrap Ada in C calls. Could you do that, then call the C
>>calls from Java?
>>
>>JAF
>
>
> JNI seems to support the Java/C connection. So this may work. In your
> problem space, did you have bi-directional communication between C and
> Ada? In other words, were you able to have C invoke Ada calls and Ada
> invoke C calls?
>
> Thanks!
>
> Ken
>
Yes.
Our Ada compiler is the gnat (gcc) compiler, and our main program is in
C. The tool runs on linux, so we use gcc all around and the tools work
very nicely together.
We call ada_init() in the C code (you will probably have to do the
same). From there it is mostly a matter of making sure both languages
have the correct interface and calling in either direction is really
pretty easy. In Ada, use pragma(C, ...).
On the C side things are a bit messy. Out and in/out parameters become
pointers. This works rather better than I would've thought (probably
the pragma forces such parameters to be pointers where they would not
always be otherwise). But even so, we have a lot of C functions with
void * parameters instead of typed pointers and ints instead of Boolean,
etc.
When an Ada function returns an unsized array (such as Wide_String(<>))
we wrap it in an Ada procedure that returns a wchar_t and string size.
(There is a way to ensure the string is null terminated so C does not
need the size, but this method is good for any array type. See ARM B.3.1)
One interesting problem we had was converting Ada access types to C
pointers. An Ada access type is a higher level construct than a C
pointer, which means it may or might not actually "point" to the desired
location in memory. What we found in practice is that arrays that are
sized dynamically have a 64 bit entity in which the first 32 bits do
point to the object of interest.
I'm not sure I'm happy with our solution and others here probably have
better ideas than we, so instead of saying what we did, I'll look to see
if anyone posts any suggestions ;)
For exceptions raised in Ada, we catch them in Ada and call a C function
that passes to C information on the raised exception. (I wouldn't
want to mess with anything like trying to pass the exception itself to
C++ then on to Java)
I can't think of any other gotcha's that we experienced. It really has
been a lot easier than I thought coming in to the project.
Have fun!
James
[-- Attachment #2: jfarrell.vcf --]
[-- Type: text/x-vcard, Size: 88 bytes --]
begin:vcard
fn:James Alan Farrell
n:Farrell;James
org:GrammaTech
version:2.1
end:vcard
next prev parent reply other threads:[~2006-03-24 21:40 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-03-22 13:01 Java wrappers around Ada? kk_oop
2006-03-22 13:33 ` Larry Kilgallen
2006-03-23 6:57 ` Anders Wirzenius
2006-03-23 13:10 ` Larry Kilgallen
2006-03-22 13:33 ` Georg Bauhaus
2006-03-22 23:25 ` Jeffrey R. Carter
2006-03-23 22:24 ` James Alan Farrell
2006-03-23 22:59 ` kk_oop
2006-03-24 21:40 ` James Alan Farrell [this message]
2006-03-25 0:37 ` Jeffrey R. Carter
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox