This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
Patch: FYI: minor runtime cleanup
- From: Tom Tromey <tromey at redhat dot com>
- To: java-patches at gcc dot gnu dot org
- Date: 23 Feb 2003 17:44:00 -0700
- Subject: Patch: FYI: minor runtime cleanup
- Reply-to: tromey at redhat dot com
I'm checking this in to the trunk.
This cleans up Runtime a little. libltdl already has all the
information needed to iterate over all loaded libraries. There's no
need for us to duplicate this information.
Tom
Index: ChangeLog
from Tom Tromey <tromey at redhat dot com>
* java/lang/natRuntime.cc (libraries_size, libraries_count,
libraries): Removed.
(add_library): Removed.
(_load): Don't call add_library.
(loadLibraryInternal): Likewise.
(init): Likewise.
(lookup_data): New struct.
(find_symbol): New function.
(_Jv_FindSymbolInExecutable): Use it.
Index: java/lang/natRuntime.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/natRuntime.cc,v
retrieving revision 1.32
diff -u -r1.32 natRuntime.cc
--- java/lang/natRuntime.cc 19 Feb 2003 16:28:37 -0000 1.32
+++ java/lang/natRuntime.cc 24 Feb 2003 00:21:35 -0000
@@ -60,48 +60,28 @@
AC_LTDL_PREOPEN to see if we do. */
extern const lt_dlsymlist lt_preloaded_symbols[1] = { { 0, 0 } };
-// We keep track of all the libraries loaded by this application. For
-// now we use them to look up symbols for JNI. `libraries_size' holds
-// the total size of the buffer. `libraries_count' is the number of
-// items which are in use.
-static int libraries_size;
-static int libraries_count;
-static lt_dlhandle *libraries;
-
-static void
-add_library (lt_dlhandle lib)
+struct lookup_data
{
- if (libraries_count == libraries_size)
- {
- int ns = libraries_size * 2;
- if (ns == 0)
- ns = 10;
- lt_dlhandle *n = (lt_dlhandle *) _Jv_Malloc (ns * sizeof (lt_dlhandle));
- if (libraries)
- {
- memcpy (n, libraries, libraries_size * sizeof (lt_dlhandle));
- _Jv_Free (libraries);
- }
- libraries = n;
- libraries_size = ns;
- for (int i = libraries_count; i < libraries_size; ++i)
- libraries[i] = NULL;
- }
-
- libraries[libraries_count++] = lib;
+ const char *symname;
+ void *result;
+};
+
+static int
+find_symbol (lt_dlhandle handle, lt_ptr_t data)
+{
+ lookup_data *ld = (lookup_data *) data;
+ ld->result = lt_dlsym (handle, ld->symname);
+ return ld->result != NULL;
}
void *
_Jv_FindSymbolInExecutable (const char *symname)
{
- for (int i = 0; i < libraries_count; ++i)
- {
- void *r = lt_dlsym (libraries[i], symname);
- if (r)
- return r;
- }
-
- return NULL;
+ lookup_data data;
+ data.symname = symname;
+ data.result = NULL;
+ lt_dlforeach (find_symbol, (lt_ptr_t) &data);
+ return data.result;
}
void
@@ -237,8 +217,6 @@
throw new UnsatisfiedLinkError (str);
}
- add_library (h);
-
void *onload = lt_dlsym (h, "JNI_OnLoad");
#ifdef WIN32
@@ -289,8 +267,6 @@
buf[total] = '\0';
// FIXME: make sure path is absolute.
lt_dlhandle h = lt_dlopenext (buf);
- if (h != NULL)
- add_library (h);
return h != NULL;
#else
return false;
@@ -302,9 +278,8 @@
{
#ifdef USE_LTDL
lt_dlinit ();
- lt_dlhandle self = lt_dlopen (NULL);
- if (self != NULL)
- add_library (self);
+ // Make sure self is opened.
+ lt_dlopen (NULL);
#endif
}