-rw-r--r-- | microkde/kdecore/klibloader.cpp | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/microkde/kdecore/klibloader.cpp b/microkde/kdecore/klibloader.cpp index 9eee912..1394154 100644 --- a/microkde/kdecore/klibloader.cpp +++ b/microkde/kdecore/klibloader.cpp @@ -285,207 +285,214 @@ KLibWrapPrivate::KLibWrapPrivate(KLibrary *l, QLibrary* h) : lib(l), ref_count(1), handle(h), name(l->name()), filename(l->fileName()) { unload_mode = UNKNOWN; /*US if (lt_dlsym(handle, "__kde_do_not_unload") != 0) { // kdDebug(150) << "Will not unload " << name << endl; unload_mode = DONT_UNLOAD; } else if (lt_dlsym(handle, "__kde_do_unload") != 0) { unload_mode = UNLOAD; } */ //US use instead: if (h->resolve("__kde_do_not_unload") != 0) { // kdDebug(150) << "Will not unload " << name << endl; unload_mode = DONT_UNLOAD; } else if (h->resolve("__kde_do_unload") != 0) { unload_mode = UNLOAD; } } class KLibLoaderPrivate { public: QPtrList<KLibWrapPrivate> loaded_stack; QPtrList<KLibWrapPrivate> pending_close; enum {UNKNOWN, UNLOAD, DONT_UNLOAD} unload_mode; QString errorMessage; }; KLibLoader* KLibLoader::s_self = 0; KLibLoader* KLibLoader::self() { if ( !s_self ) s_self = new KLibLoader; return s_self; } void KLibLoader::cleanUp() { if ( !s_self ) return; delete s_self; s_self = 0; } KLibLoader::KLibLoader( QObject* parent, const char* name ) : QObject( parent, name ) { s_self = this; d = new KLibLoaderPrivate; //US lt_dlinit(); d->unload_mode = KLibLoaderPrivate::UNKNOWN; if (getenv("KDE_NOUNLOAD") != 0) d->unload_mode = KLibLoaderPrivate::DONT_UNLOAD; else if (getenv("KDE_DOUNLOAD") != 0) d->unload_mode = KLibLoaderPrivate::UNLOAD; d->loaded_stack.setAutoDelete( true ); } KLibLoader::~KLibLoader() { // kdDebug(150) << "Deleting KLibLoader " << this << " " << name() << endl; QAsciiDictIterator<KLibWrapPrivate> it( m_libs ); for (; it.current(); ++it ) { kdDebug(150) << "The KLibLoader contains the library " << it.current()->name << " (" << it.current()->lib << ")" << endl; d->pending_close.append(it.current()); } close_pending(0); delete d; } //static QString KLibLoader::findLibrary( const char * name/*US , const KInstance * instance*/ ) { QCString libname( name ); // only append ".la" if there is no extension // this allows to load non-libtool libraries as well // (mhk, 20000228) int pos = libname.findRev('/'); if (pos < 0) pos = 0; /*US if (libname.find('.', pos) < 0) { libname += ".la"; } */ //US in the microedition we work only with shared libraries. + if (libname.find('.', pos) < 0) { +#ifdef _WIN32_ + libname += ".dll"; +#else libname += ".so"; +#endif } // only look up the file if it is not an absolute filename // (mhk, 20000228) QString libfile; if (libname[0] == '/') libfile = libname; else { //US at this point the libname must exist as real filesname. No expansions will be made later // in findResources. Because of that we prepend the lib prefix here to the name //US I add also the "lib" prefix. I do not how could this could have worked before without it? +#ifndef _WIN32_ libname.insert(pos, "lib"); +#endif //US libfile = instance->dirs()->findResource( "module", libname ); //qDebug("libname = %s ",libname.data() ); libfile = KGlobal::dirs()->findResource( "module", libname ); //qDebug("libfile = %s ",libfile.latin1() ); if ( libfile.isEmpty() ) { //US libfile = instance->dirs()->findResource( "lib", libname ); libfile = KGlobal::dirs()->findResource( "lib", libname ); //qDebug("libfile2 = %s ",libfile.latin1() ); #ifndef NDEBUG if ( !libfile.isEmpty() && libname.left(3) == "lib" ) // don't warn for kdeinit modules kdDebug(150) << "library " << libname << " not found under 'module' but under 'lib'" << endl; #endif } if ( libfile.isEmpty() ) { #ifndef NDEBUG kdDebug(150) << "library=" << libname << ": No file names " << libname.data() << " found in paths." << endl; self()->d->errorMessage = i18n("Library files for \"%1\" not found in paths").arg(libname); qDebug("KLibLoader::library could not find library: %s", libname.data()); #endif } else self()->d->errorMessage = QString::null; } //qDebug("return libfile = %s ",libfile.latin1() ); return libfile; } KLibrary* KLibLoader::globalLibrary( const char *name ) { KLibrary *tmp; /*US int olt_dlopen_flag = lt_dlopen_flag; lt_dlopen_flag |= LT_GLOBAL; kdDebug(150) << "Loading the next library global with flag " << lt_dlopen_flag << "." << endl; */ tmp = library(name); /*US lt_dlopen_flag = olt_dlopen_flag; */ return tmp; } KLibrary* KLibLoader::library( const char *name ) { if (!name) return 0; KLibWrapPrivate* wrap = m_libs[name]; if (wrap) { /* Nothing to do to load the library. */ wrap->ref_count++; return wrap->lib; } /* Test if this library was loaded at some time, but got unloaded meanwhile, whithout being dlclose()'ed. */ QPtrListIterator<KLibWrapPrivate> it(d->loaded_stack); for (; it.current(); ++it) { if (it.current()->name == name) wrap = it.current(); } if (wrap) { d->pending_close.removeRef(wrap); if (!wrap->lib) { /* This lib only was in loaded_stack, but not in m_libs. */ wrap->lib = new KLibrary( name, wrap->filename, wrap->handle ); } wrap->ref_count++; } else { QString libfile = findLibrary( name ); if ( libfile.isEmpty() ) return 0; #ifdef DESKTOP_VERSION QLibrary *qlib = new QLibrary( libfile.latin1() ); #else QLibrary *qlib = new QLibrary( libfile.latin1(), QLibrary::Immediately ); #endif //US lt_dlhandle handle = lt_dlopen( libfile.latin1() ); //US if ( !handle ) if ( !qlib ) { |