* jnixx - making jni smell more like cni
@ 2008-06-09 15:00 Andrew Cagney
0 siblings, 0 replies; only message in thread
From: Andrew Cagney @ 2008-06-09 15:00 UTC (permalink / raw)
To: frysk
Hi,
As part of translating frysk's CNI bindings to JNI, I mocked up a JNI
bindings generator to simplify the process. Among its features are:
-- generation of name spaces and a class inheritance structure that
reflects the java code:
For instance, the lib.dwfl.ElfException class is generated as:
class lib::dwfl::ElfException : public java::lang::RuntimeException
-- lets you directly invoke methods (wrappers take care of the JNI)
For instance, a static method in LocalMemory can be invoked with:
java::lang::String s = frysk::testbed::LocalMemory::getModuleName(env)
(yes you still need to pass an env variable round)
-- provides get/set methods for class fields
For instance, given the class variable:
jint intVar;
a method can read/modify/write it using:
SetIntVar(env, GetIntVar(env) + 1);
-- lets you use a more natural throw/catch style for handling exceptions
For instance, a try/finally can be implemented using:
try {
callJavaMethodFoo();
catch (java::lang::Throwable e) {
do cleanup stuff;
throw e;
}
(rather than the traditional JNI style of trying to remember to check
return values for failure)
-- provides wrappers to manage references to array and string elements
For instance, to get at and print a java string as a unix string:
jstringUTFChars string = jstringUTFChars(env, javaString);
fprintf(stderr, "string = %s\n", string.elements());
While there are still a few warts and I'd not consider the interfaces
100% pinned down, the basic framework is working very well. The curious
are more than welcome to have a play. Ideas, suggestions, questions,
and code are all most welcome.
Andrew
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2008-06-06 21:18 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-06-09 15:00 jnixx - making jni smell more like cni Andrew Cagney
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).