From 804b2c48eab2cb65fb0ae268c8a40e91c24777ff Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Mon, 24 Feb 2003 00:53:21 +0000 Subject: [PATCH] natRuntime.cc (libraries_size, [...]): Removed. * 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. From-SVN: r63348 --- libjava/ChangeLog | 12 +++++++ libjava/java/lang/natRuntime.cc | 59 ++++++++++----------------------- 2 files changed, 29 insertions(+), 42 deletions(-) diff --git a/libjava/ChangeLog b/libjava/ChangeLog index c35bdf2bdb0..ffd0c6e96b6 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -1,3 +1,15 @@ +2003-02-23 Tom Tromey + + * 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. + 2002-02-21 Anthony Green * java/lang/Thread.java (Thread): New constructor taking stack diff --git a/libjava/java/lang/natRuntime.cc b/libjava/java/lang/natRuntime.cc index 9879b259dd5..dee95114538 100644 --- a/libjava/java/lang/natRuntime.cc +++ b/libjava/java/lang/natRuntime.cc @@ -60,48 +60,28 @@ details. */ 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; - } + const char *symname; + void *result; +}; - libraries[libraries_count++] = lib; +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 @@ java::lang::Runtime::_load (jstring path, jboolean do_search) throw new UnsatisfiedLinkError (str); } - add_library (h); - void *onload = lt_dlsym (h, "JNI_OnLoad"); #ifdef WIN32 @@ -289,8 +267,6 @@ java::lang::Runtime::loadLibraryInternal (jstring lib) 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 @@ java::lang::Runtime::init (void) { #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 } -- 2.30.2