Login  Register

Re: java interface

Posted by Luigi Ballabio-3 on Jul 10, 2001; 10:49am
URL: http://quantlib.414.s1.nabble.com/java-interface-tp1736p1737.html

At 07:40 PM 7/9/01 +0200, Gilbert Peffer wrote:
>What are the steps one has to take in order to interface Java with the
>QuantLib C++ code? One method is through JNI (as far as I understood it),
>but I think the other is through Python using the SWIG stuff.

Hi Gilbert,
         I think you meant Jython - I don't know of other mainstream
methods of interfacing Python and Java. Unfortunately, Jython can only
import pure Python modules or Java classes, but not C/C++ Python
extensions, so we're left in the cold there.

The only way out - apart from high-level protocols like CORBA, but somehow
I don't think that you want to write a C++ servant and a Java client first
thing in the morning - seems to be JNI.

SWIG used to have some Java support which was recently broken and is going
to be reintroduced in release 1.3.6, due any day. I was about to take a
look to the release candidate right now.

We also thought of interfacing QL with Java through SWIG, but there was an
issue which made it a painful experience, namely, C++ objects allocated on
the heap by the constructor of the Java shadow object should be deallocated
in its finalize() method. Unfortunately, finalize() is not guaranteed to be
called upon destruction. This leads either to possible memory leaks or to
having to manually call finalize() or some other delete() method whenever a
QuantLib object goes out of scope.

So thoughtful of the Java designers, but then again, I suppose that from
day 1 JNI was designed to discourage developers from using it and have them
go 100% Java instead...

But enough with the rambling. The bottom line is: I'll have a look at the
new SWIG release and report faithfully to the list.

Bye for now,
                 Luigi