This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
Patch: JNI bug fix
- To: Java Patch List <java-patches at gcc dot gnu dot org>
- Subject: Patch: JNI bug fix
- From: Tom Tromey <tromey at redhat dot com>
- Date: 15 Jun 2001 17:37:17 -0600
- Reply-To: tromey at redhat dot com
This is a rewrite of a patch from Martin Kahlert.
With this you can have a JNI `main' in a library which is statically
linked into your application.
Two fixes here:
* Fix Runtime to properly search the program itself for symbols, and
* Fix init code to initialize Runtime before looking for `main'
I'm checking this in.
2001-06-15 Tom Tromey <tromey@redhat.com>
* java/lang/natRuntime.cc (_Jv_FindSymbolInExecutable): Return
NULL if no library on the list has the symbol.
(init): Call add_library on the program itself.
* prims.cc (JvRunMain): Initialize Runtime before searching for
`main'.
(_Jv_RunMain): Likewise.
Tom
Index: prims.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/prims.cc,v
retrieving revision 1.53
diff -u -r1.53 prims.cc
--- prims.cc 2001/06/02 08:34:33 1.53
+++ prims.cc 2001/06/15 23:12:59
@@ -1008,6 +1008,10 @@
_Jv_ThisExecutable (argv[0]);
#endif
+ // Get the Runtime here. We want to initialize it before searching
+ // for `main'; that way it will be set up if `main' is a JNI method.
+ java::lang::Runtime *rtime = java::lang::Runtime::getRuntime ();
+
main_thread = _Jv_AttachCurrentThread (JvNewStringLatin1 ("main"), NULL);
arg_vec = JvConvertArgv (argc - 1, argv + 1);
runFirst (klass, arg_vec);
@@ -1015,7 +1019,7 @@
int status = (int) java::lang::ThreadGroup::had_uncaught_exception;
- java::lang::Runtime::getRuntime ()->_exit (status);
+ rtime->_exit (status);
}
void
@@ -1031,6 +1035,10 @@
_Jv_ThisExecutable (exec_name);
#endif
+ // Get the Runtime here. We want to initialize it before searching
+ // for `main'; that way it will be set up if `main' is a JNI method.
+ java::lang::Runtime *rtime = java::lang::Runtime::getRuntime ();
+
main_thread = _Jv_AttachCurrentThread (JvNewStringLatin1 ("main"), NULL);
if (is_jar)
@@ -1061,7 +1069,7 @@
int status = (int) java::lang::ThreadGroup::had_uncaught_exception;
- java::lang::Runtime::getRuntime ()->exit (status);
+ rtime->exit (status);
}
Index: java/lang/natRuntime.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/natRuntime.cc,v
retrieving revision 1.17
diff -u -r1.17 natRuntime.cc
--- natRuntime.cc 2001/06/02 19:40:53 1.17
+++ natRuntime.cc 2001/06/15 23:12:59
@@ -69,7 +69,7 @@
return r;
}
- return lt_dlsym (NULL, symname);
+ return NULL;
}
#else
@@ -199,6 +199,9 @@
finalize_on_exit = false;
#ifdef USE_LTDL
lt_dlinit ();
+ lt_dlhandle self = lt_dlopen (NULL);
+ if (self != NULL)
+ add_library (self);
#endif
}