search libraries for symbols in the order they are loaded

This commit is contained in:
Joel Dice 2008-01-25 16:25:30 -07:00
parent 618684de6e
commit 35ada0ea65
6 changed files with 26 additions and 20 deletions

View File

@ -537,12 +537,9 @@ Java_java_lang_Runtime_load(Thread* t, jclass, jstring name, jboolean mapName)
}
}
System::Library* lib;
if (LIKELY(t->m->system->success
(t->m->system->load(&lib, n, mapName, t->m->libraries))))
if (UNLIKELY(not t->m->system->success
(t->m->system->load(&(t->m->libraries), n, mapName))))
{
t->m->libraries = lib;
} else {
object message = makeString(t, "library not found: %s", n);
t->exception = makeUnsatisfiedLinkError(t, message);
}

View File

@ -400,8 +400,8 @@ class BuiltinElement: public JarElement {
virtual void init() {
if (index == 0) {
System::Library* library;
if (s->success(s->load(&library, 0, false, 0))) {
System::Library* library = 0;
if (s->success(s->load(&library, 0, false))) {
void* p = library->resolve(name);
if (p) {
uint8_t* (*function)(unsigned*);

View File

@ -1812,7 +1812,7 @@ Machine::Machine(System* system, Heap* heap, Finder* finder,
not system->success(system->make(&heapLock)) or
not system->success(system->make(&classLock)) or
not system->success(system->make(&referenceLock)) or
not system->success(system->load(&libraries, 0, false, 0)))
not system->success(system->load(&libraries, 0, false)))
{
system->abort();
}

View File

@ -447,13 +447,13 @@ class MySystem: public System {
class Library: public System::Library {
public:
Library(System* s, void* p, const char* name, unsigned nameLength,
bool mapName, System::Library* next):
bool mapName):
s(s),
p(p),
name_(name),
nameLength(nameLength),
mapName_(mapName),
next_(next)
next_(0)
{ }
virtual void* resolve(const char* function) {
@ -639,8 +639,7 @@ class MySystem: public System {
virtual Status load(System::Library** lib,
const char* name,
bool mapName,
System::Library* next)
bool mapName)
{
void* p;
unsigned nameLength = (name ? strlen(name) : 0);
@ -666,8 +665,14 @@ class MySystem: public System {
n = 0;
}
*lib = new (allocate(this, sizeof(Library)))
Library(this, p, n, nameLength, mapName, next);
Library* newLib = new (allocate(this, sizeof(Library)))
Library(this, p, n, nameLength, mapName);
if (*lib) {
static_cast<Library*>(*lib)->next_ = newLib;
}
*lib = newLib;
return 0;
} else {
// fprintf(stderr, "dlerror: %s\n", dlerror());

View File

@ -104,8 +104,7 @@ class System {
unsigned returnType) = 0;
virtual Status map(Region**, const char* name) = 0;
virtual FileType identify(const char* name) = 0;
virtual Status load(Library**, const char* name, bool mapName, Library* next)
= 0;
virtual Status load(Library**, const char* name, bool mapName) = 0;
virtual char pathSeparator() = 0;
virtual int64_t now() = 0;
virtual void exit(int code) = 0;

View File

@ -606,8 +606,7 @@ class MySystem: public System {
virtual Status load(System::Library** lib,
const char* name,
bool mapName,
System::Library* next)
bool mapName)
{
HMODULE handle;
unsigned nameLength = (name ? strlen(name) : 0);
@ -635,8 +634,14 @@ class MySystem: public System {
n = 0;
}
*lib = new (allocate(this, sizeof(Library)))
Library(this, handle, n, mapName, nameLength, next);
Library* newLib = new (allocate(this, sizeof(Library)))
Library(this, p, n, nameLength, mapName);
if (*lib) {
static_cast<Library*>(*lib)->next = newLib;
}
*lib = newLib;
return 0;
} else {
return 1;