Gems in categories Mixed Language

One of the main issues raised by interfacing Ada and C++ is propagation of exceptions from one environment to the other. In this Gem, we’ll demonstrate how the new exception mechanism implemented in GNAT allows catching Ada exceptions in C++, and vice versa. Note that the following code will work starting with GNAT Pro 7. Continue Reading in Ada Answers »

This series of two Gems explains how to use the GNAT Components
Collection to interface your Ada code with Python. The first Gem described what
benefits this could bring to your application, and the difficulties there would
be in interfacing directly to the Python library. The second Gem shows how
to get started with GNATCOLL to make the interfacing much easier.

This series of two Gems explains how to use the GNAT Components
Collection to interface your Ada code with Python. The first Gem describes the
benefits this could bring to your application as well as the difficulties there would
be in interfacing directly to the Python library. The second Gem will show how
to get started with GNATCOLL to greatly simplify the interfacing process.

Ada Gem #61 — In the previous Gem about generating bindings from C++ headers,
we mentioned, without going into details, how to interface with
C++ constructors in Ada using the CPP_Constructor pragma.

In this Gem we present some common uses of C++ constructors
in mixed-language programs in GNAT, and in the next Gem, we will show
the use of some powerful Ada 2005 features in conjunction with C++ constructors.

Ada Gem #60 — In Gem #59 we saw how simple it is to automatically generate Ada
bindings for C header files. In this Gem, we will see that, similarly,
it's now also possible to generate Ada bindings for C++ header files. Continue Reading in Ada Answers »

Ada Gem #59 — One of the delicate areas of Ada that is often unfamiliar to developers
is how to intermix Ada code with other programming languages. While Ada
provides very powerful and complete capabilities to interface with other
compiled languages such as C, C++, and Fortran, writing the Ada glue code
that enables a programmer to use complex and large APIs can be tedious and
error-prone.
In this Gem, we will explore a new tool provided by AdaCore to automate the
interface generation of C header files through the compiler.
Continue Reading in Ada Answers »

Ada Gem #58 — Ada and Java are two languages that rely heavily on exceptions. A large
part of the Ada data model is based on the fact that data is checked at
run time, and will raise various kinds of exceptions such as
Constraint_Error when constraints are violated. Similarly, there are
many cases where Java performs checks that can raise exceptions, among
the most common being checks on casts and null dereferences. It is
therefore extremely important to support exceptions that are
properly propagated from one language to the other and even
potentially caught/handled, without having to worry about the language of origin. Continue Reading in Ada Answers »

Ada Gem #57 — In the preceding Ada/Java interfacing Gem, we saw how to create calls from Ada to Java using ada2java and callbacks. We’re now going to go one step further, and discuss a cross-language dispatching mechanism that supports extension of an Ada tagged type in Java, allowing the possibility of making dispatching calls equally well from either side. Continue Reading in Ada Answers »

Ada Gem #56 — In a previous Gem we introduced ada2java, which maps an Ada specification to a Java specification, to support calls from Java to Ada. Even though ada2java doesn't support creating Ada bindings of Java specs, it’s still possible to use it to support calls from Ada to Java. In this Gem we’ll look at a first possibility of doing this, using callbacks (in Ada terms, access-to-subprogram calls). Continue Reading in Ada Answers »

Interfacing Ada and Java is a very tricky problem. As opposed to C, C++, or Fortran, the two languages execute on two different environments, Java on the JVM and Ada directly on the underlying OS. For this reason, it is not possible to directly bind Java functions to natively compiled Ada through a pragma Import. Two solutions are offered to the developer: either compiling the code directly to Java bytecode, using GNAT for the JVM, or using the Java Native Interface (JNI), allowing communication between the native and JVM environments. In this Gem we will take a look at the latter.

Using this JNI layer manually is very error-prone and tedious. Fortunately, AdaCore provides a set of tools for automating the interface generation, through GNAT-AJIS. This Gem is the first of a series showing how this toolset can be used to create a mixed Ada / Java application. Continue Reading in Ada Answers »