KDE/kdelibs/kdecore/util

Jaroslaw Staniek js at iidea.pl
Mon Nov 12 16:18:01 CET 2007


SVN commit 735763 by staniek:

Safe change for Windows only - allows to keep WITH_PREFIX flag in cmake files,
while plugins eventually can be loaded on windows.

(a) add a "lib" prefix for an init_ symbol name in case when a symbol without
the "lib" prefix is not found
(b) by the way simplify some redundant windows lib/plugin loading code

Discussed at http://lists.kde.org/?t=119365039600003&r=1&w=2

CCMAIL:kde-windows at kde.org



 M  +20 -28    klibloader.cpp  
 M  +5 -0      klibrary.cpp  
 M  +7 -1      kpluginloader.cpp  


--- trunk/KDE/kdelibs/kdecore/util/klibloader.cpp #735762:735763
@@ -59,41 +59,33 @@
 
 extern QString makeLibName( const QString &libname );
 
-extern QString findLibraryInternal(const QString &name, const KComponentData &cData);
+extern QString findLibrary(const QString &name, const KComponentData &cData);
 
-//static
-QString KLibLoader::findLibrary(const QString &_name, const KComponentData &cData)
-{
-    QString libname = findLibraryInternal(QDir::fromNativeSeparators(_name), cData);
 #ifdef Q_OS_WIN
-    // we don't have 'lib' prefix on windows -> remove it and try again
-    if( libname.isEmpty() )
+// removes "lib" prefix, if present
+QString fixLibPrefix(const QString& libname)
+{
+    int pos = libname.lastIndexOf( '/' );
+    if ( pos >= 0 )
     {
-      libname = _name;
-      QString file, path;
-
-      int pos = libname.lastIndexOf( '/' );
-      if ( pos >= 0 )
-      {
-        file = libname.mid( pos + 1 );
-        path = libname.left( pos );
-        libname = path + '/' + file.mid( 3 );
-      }
-      else
-      {
-        file = libname;
-        libname = file.mid( 3 );
-      }
-      if( !file.startsWith( "lib" ) )
-          return libname;
-
-      libname = findLibraryInternal(libname, cData);
+        QString file = libname.mid( pos + 1 );
+        QString path = libname.left( pos );
+        if( !file.startsWith( "lib" ) )
+            return libname;
+        return path + '/' + file.mid( 3 );
     }
+    if( !libname.startsWith( "lib" ) )
+        return libname;
+    return libname.mid( 3 );
+}
 #endif
-    return libname;
+
+//static
+QString KLibLoader::findLibrary(const QString &_name, const KComponentData &cData)
+{
+    return ::findLibrary(_name, cData);
 }
 
-
 KLibrary* KLibLoader::library( const QString &_name, QLibrary::LoadHints hint )
 {
     if (_name.isEmpty())
--- trunk/KDE/kdelibs/kdecore/util/klibrary.cpp #735762:735763
@@ -113,6 +113,11 @@
     t_func func = reinterpret_cast<t_func>(lib->resolveFunction( symname ));
     if ( !func )
     {
+#ifdef Q_OS_WIN
+        // a backup for cases when developer has set lib prefix for a plugin name (she should not...)
+        if (!factoryname.startsWith("lib"))
+            return kde3Factory(lib, QByteArray("lib")+symname.mid(5 /*"init_"*/));
+#endif
         kDebug(150) << "The library" << lib->fileName() << "does not offer an"
                     << symname << "function.";
         return 0;
--- trunk/KDE/kdelibs/kdecore/util/kpluginloader.cpp #735762:735763
@@ -73,6 +73,10 @@
 #endif
 }
 
+#ifdef Q_OS_WIN
+extern QString fixLibPrefix(const QString& libname);
+#endif
+
 inline QString findLibraryInternal(const QString &name, const KComponentData &cData)
 {
     QString libname = makeLibName(name);
@@ -87,7 +91,9 @@
     if (QDir::isRelativePath(libname)) {
         libfile = cData.dirs()->findResource("module", libname);
         if (libfile.isEmpty()) {
-#ifndef Q_OS_WIN
+#ifdef Q_OS_WIN
+            libname = fixLibPrefix(libname);
+#else
             if (!hasPrefix)
                 libname = fileinfo.path() + QLatin1String("/lib") + fileinfo.fileName();
 #endif



More information about the Kde-windows mailing list