Changeset 156
- Timestamp:
- Nov 15, 2006, 2:45:23 AM (19 years ago)
- Location:
- trunk/src/tools
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/tools/qlibrary_p.h
r8 r156 63 63 public: 64 64 QLibraryPrivate( QLibrary *lib ); 65 #if defined(Q_OS_OS2) 66 ~QLibraryPrivate() { derefLib( FALSE ); } 67 #endif 65 68 66 69 #if defined(Q_WS_WIN) … … 77 80 78 81 private: 82 #if defined(Q_OS_OS2) 83 bool derefLib( bool doFree ); 84 #endif 85 79 86 QLibrary *library; 80 87 }; -
trunk/src/tools/qlibrary_pm.cpp
r8 r156 45 45 #ifndef QT_H 46 46 #include "qfile.h" 47 #include "qdir.h" 47 48 #endif // QT_H 48 49 … … 55 56 }; 56 57 57 static QMap<QString, LibInstance*> *map = 0; 58 typedef QMap<QCString, LibInstance*> LibInstanceMap; 59 60 static LibInstanceMap map; 58 61 /* 59 62 The platform dependent implementations of … … 70 73 { 71 74 if ( pHnd ) 72 75 return TRUE; 73 76 74 77 #ifdef QT_THREAD_SUPPORT 75 78 // protect map creation/access 76 79 QMutexLocker locker( qt_global_mutexpool ? 77 80 qt_global_mutexpool->get( &map ) : 0 ); 78 81 #endif // QT_THREAD_SUPPORT 79 82 80 if ( !map ) 81 map = new QMap<QString, LibInstance*>; 82 83 QString filename = library->library(); 84 if ( map->find(filename) != map->end() ) { 85 LibInstance *lib = (*map)[filename]; 86 lib->refCount++; 87 pHnd = lib->module; 88 } 89 else { 90 APIRET rc = 0; 91 char errModule [256]; 92 if ( (rc = DosLoadModule( 93 errModule, sizeof(errModule), 94 QFile::encodeName( filename ).data(), &pHnd 95 ))) { 83 QCString filename = 84 QFile::encodeName( QDir::convertSeparators ( library->library() ) ); 85 if ( map.find(filename) != map.end() ) { 86 LibInstance *lib = map[filename]; 87 lib->refCount++; 88 pHnd = lib->module; 89 } else { 90 APIRET rc = NO_ERROR; 91 char errModule [CCHMAXPATH]; 92 if ( (rc = DosLoadModule( errModule, sizeof(errModule), 93 filename.data(), &pHnd 94 )) != NO_ERROR ) { 96 95 pHnd = 0; 97 96 #if defined(QT_DEBUG) || defined(QT_DEBUG_COMPONENT) 98 99 .arg( filename ).arg( errModule ), rc97 qSystemWarning( QString("Failed to load library %1 (reason: %2)!") 98 .arg( filename.data() ).arg( errModule ), rc 100 99 ); 101 100 #endif 102 101 } 103 104 105 106 107 map->insert( filename, lib );108 102 if ( pHnd ) { 103 LibInstance *lib = new LibInstance; 104 lib->module = pHnd; 105 lib->refCount++; 106 map.insert( filename, lib ); 107 } 109 108 } 110 109 return pHnd != 0; … … 113 112 bool QLibraryPrivate::freeLibrary() 114 113 { 115 if ( !pHnd ) 116 return TRUE; 117 118 #ifdef QT_THREAD_SUPPORT 119 // protect map access 120 QMutexLocker locker( qt_global_mutexpool ? 121 qt_global_mutexpool->get( &map ) : 0 ); 122 #endif // QT_THREAD_SUPPORT 123 124 bool ok = FALSE; 125 QMap<QString, LibInstance*>::iterator it; 126 for ( it = map->begin(); it != map->end(); ++it ) { 127 LibInstance *lib = *it; 128 if ( lib->module == pHnd ) { 129 lib->refCount--; 130 if ( lib->refCount == 0 ) { 131 ok = DosFreeModule( pHnd ) == 0; 132 if ( ok ) { 133 map->remove( it ); 134 if ( map->count() == 0 ) { 135 delete map; 136 map = 0; 137 } 138 } 139 delete lib; 140 } else 141 ok = TRUE; 142 break; 143 } 144 } 145 if ( ok ) 146 pHnd = 0; 147 #if defined(QT_DEBUG) || defined(QT_DEBUG_COMPONENT) 148 else 149 qSystemWarning( "Failed to unload library!" ); 150 #endif 151 return ok; 114 return derefLib( TRUE ); 152 115 } 153 116 … … 155 118 { 156 119 if ( !pHnd ) 157 120 return 0; 158 121 159 void* address; 160 if ( DosQueryProcAddr( pHnd, 0, f, (PFN*) &address) ) address = 0; 122 void *address = 0; 123 APIRET rc = NO_ERROR; 124 if ( (rc = DosQueryProcAddr( pHnd, 0, f, (PFN*) &address)) != NO_ERROR ) 125 address = 0; 161 126 #if defined(QT_DEBUG_COMPONENT) 162 127 if ( !address ) 163 qSystemWarning( QString("Couldn't resolve symbol \"%1\"").arg( f ));128 qSystemWarning( QString("Couldn't resolve symbol \"%1\"").arg( f ), rc ); 164 129 #endif 165 130 … … 167 132 } 168 133 134 bool QLibraryPrivate::derefLib( bool doFree ) 135 { 136 if ( !pHnd ) 137 return TRUE; 138 139 #ifdef QT_THREAD_SUPPORT 140 // protect map access 141 QMutexLocker locker( qt_global_mutexpool ? 142 qt_global_mutexpool->get( &map ) : 0 ); 143 #endif // QT_THREAD_SUPPORT 144 145 APIRET rc = ERROR_INVALID_HANDLE; 146 LibInstanceMap::iterator it; 147 for ( it = map.begin(); it != map.end(); ++it ) { 148 LibInstance *lib = *it; 149 if ( lib->module == pHnd ) { 150 lib->refCount--; 151 if ( lib->refCount == 0 ) { 152 if ( doFree ) 153 rc = DosFreeModule( pHnd ); 154 else 155 rc = NO_ERROR; 156 if ( rc == NO_ERROR ) { 157 map.remove( it ); 158 delete lib; 159 } else 160 lib->refCount++; 161 } else 162 rc = NO_ERROR; 163 break; 164 } 165 } 166 if ( rc == NO_ERROR ) 167 pHnd = 0; 168 #if defined(QT_DEBUG) || defined(QT_DEBUG_COMPONENT) 169 else 170 qSystemWarning( "Failed to unload library!", rc ); 171 #endif 172 return rc == NO_ERROR; 173 } 174 169 175 #endif //QT_NO_LIBRARY
Note:
See TracChangeset
for help on using the changeset viewer.