-rw-r--r-- | library/qlibrary_unix.cpp | 113 |
1 files changed, 112 insertions, 1 deletions
diff --git a/library/qlibrary_unix.cpp b/library/qlibrary_unix.cpp index 7740321..0229b7b 100644 --- a/library/qlibrary_unix.cpp +++ b/library/qlibrary_unix.cpp | |||
@@ -31,97 +31,208 @@ | |||
31 | It's not too hard to guess what the functions do. | 31 | It's not too hard to guess what the functions do. |
32 | */ | 32 | */ |
33 | #if defined(Q_OS_HPUX) | 33 | #if defined(Q_OS_HPUX) |
34 | // for HP-UX < 11.x and 32 bit | 34 | // for HP-UX < 11.x and 32 bit |
35 | #include <dl.h> | 35 | #include <dl.h> |
36 | 36 | ||
37 | bool QLibraryPrivate::loadLibrary() | 37 | bool QLibraryPrivate::loadLibrary() |
38 | { | 38 | { |
39 | if ( pHnd ) | 39 | if ( pHnd ) |
40 | return TRUE; | 40 | return TRUE; |
41 | 41 | ||
42 | QString filename = library->library(); | 42 | QString filename = library->library(); |
43 | 43 | ||
44 | pHnd = (void*)shl_load( filename.latin1(), BIND_DEFERRED | BIND_NONFATAL | DYNAMIC_PATH, 0 ); | 44 | pHnd = (void*)shl_load( filename.latin1(), BIND_DEFERRED | BIND_NONFATAL | DYNAMIC_PATH, 0 ); |
45 | #if defined(QT_DEBUG) || defined(QT_DEBUG_COMPONENT) | 45 | #if defined(QT_DEBUG) || defined(QT_DEBUG_COMPONENT) |
46 | if ( !pHnd ) | 46 | if ( !pHnd ) |
47 | qDebug( "Failed to load library %s!", filename.latin1() ); | 47 | qDebug( "Failed to load library %s!", filename.latin1() ); |
48 | #endif | 48 | #endif |
49 | return pHnd != 0; | 49 | return pHnd != 0; |
50 | } | 50 | } |
51 | 51 | ||
52 | bool QLibraryPrivate::freeLibrary() | 52 | bool QLibraryPrivate::freeLibrary() |
53 | { | 53 | { |
54 | if ( !pHnd ) | 54 | if ( !pHnd ) |
55 | return TRUE; | 55 | return TRUE; |
56 | 56 | ||
57 | if ( !shl_unload( (shl_t)pHnd ) ) { | 57 | if ( !shl_unload( (shl_t)pHnd ) ) { |
58 | pHnd = 0; | 58 | pHnd = 0; |
59 | return TRUE; | 59 | return TRUE; |
60 | } | 60 | } |
61 | return FALSE; | 61 | return FALSE; |
62 | } | 62 | } |
63 | 63 | ||
64 | void* QLibraryPrivate::resolveSymbol( const char* symbol ) | 64 | void* QLibraryPrivate::resolveSymbol( const char* symbol ) |
65 | { | 65 | { |
66 | if ( !pHnd ) | 66 | if ( !pHnd ) |
67 | return 0; | 67 | return 0; |
68 | 68 | ||
69 | void* address = 0; | 69 | void* address = 0; |
70 | if ( shl_findsym( (shl_t*)&pHnd, symbol, TYPE_UNDEFINED, address ) < 0 ) { | 70 | if ( shl_findsym( (shl_t*)&pHnd, symbol, TYPE_UNDEFINED, address ) < 0 ) { |
71 | #if defined(QT_DEBUG) || defined(QT_DEBUG_COMPONENT) | 71 | #if defined(QT_DEBUG) || defined(QT_DEBUG_COMPONENT) |
72 | qDebug( "Couldn't resolve symbol \"%s\"", symbol ); | 72 | qDebug( "Couldn't resolve symbol \"%s\"", symbol ); |
73 | #endif | 73 | #endif |
74 | return 0; | 74 | return 0; |
75 | } | 75 | } |
76 | return address; | 76 | return address; |
77 | } | 77 | } |
78 | 78 | ||
79 | #else // Q_OS_HPUX | 79 | #elif defined(_NULL_LIB_) |
80 | |||
81 | bool QLibraryPrivate::loadLibrary() | ||
82 | { | ||
83 | //qDebug("QLibraryPrivate::loadLibrary\n"); | ||
84 | return FALSE; | ||
85 | } | ||
86 | bool QLibraryPrivate::freeLibrary() | ||
87 | { | ||
88 | //qDebug("QLibraryPrivate::freeLibrary\n"); | ||
89 | return FALSE; | ||
90 | } | ||
91 | void* QLibraryPrivate::resolveSymbol( const char* symbol ) | ||
92 | { | ||
93 | //qDebug("QLibraryPrivate::resolveSymbol\n"); | ||
94 | return FALSE; | ||
95 | } | ||
96 | |||
97 | #elif defined(Q_OS_MACX) | ||
98 | |||
99 | #define ENUM_DYLD_BOOL | ||
100 | enum DYLD_BOOL { | ||
101 | DYLD_FALSE, | ||
102 | DYLD_TRUE | ||
103 | }; | ||
104 | #include <mach-o/dyld.h> | ||
105 | typedef struct { | ||
106 | NSObjectFileImage img; | ||
107 | NSModule mod; | ||
108 | } DyldLibDesc; | ||
109 | |||
110 | bool QLibraryPrivate::loadLibrary() | ||
111 | { | ||
112 | // qDebug("QLibraryPrivate::loadLibrary\n"); | ||
113 | // return FALSE; | ||
114 | if ( pHnd ) | ||
115 | return TRUE; | ||
116 | |||
117 | QString filename = library->library(); | ||
118 | |||
119 | NSObjectFileImage img = 0; | ||
120 | NSModule mod = 0; | ||
121 | NSObjectFileImageReturnCode ret = NSCreateObjectFileImageFromFile( filename.latin1() , &img ); | ||
122 | if ( ret != NSObjectFileImageSuccess ) { | ||
123 | qWarning( "Error in NSCreateObjectFileImageFromFile(): %d; Filename: %s", ret, filename.latin1() ); | ||
124 | if (ret == NSObjectFileImageAccess) { | ||
125 | qWarning ("(NSObjectFileImageAccess)" ); | ||
126 | } | ||
127 | } else { | ||
128 | mod = NSLinkModule(img, filename.latin1(), NSLINKMODULE_OPTION_BINDNOW | | ||
129 | NSLINKMODULE_OPTION_PRIVATE | | ||
130 | NSLINKMODULE_OPTION_RETURN_ON_ERROR); | ||
131 | if (mod == 0) { | ||
132 | qWarning( "Error in NSLinkModule()" ); | ||
133 | NSDestroyObjectFileImage(img); | ||
134 | } | ||
135 | } | ||
136 | DyldLibDesc* desc = 0; | ||
137 | if (img != 0 && mod != 0) { | ||
138 | desc = new DyldLibDesc; | ||
139 | desc->img = img; | ||
140 | desc->mod = mod; | ||
141 | } | ||
142 | pHnd = desc; | ||
143 | return pHnd != 0; | ||
144 | } | ||
145 | |||
146 | bool QLibraryPrivate::freeLibrary() | ||
147 | { | ||
148 | //qDebug("QLibraryPrivate::freeLibrary\n"); | ||
149 | //return FALSE; | ||
150 | if ( !pHnd ) | ||
151 | return TRUE; | ||
152 | |||
153 | DyldLibDesc* desc = (DyldLibDesc*) pHnd; | ||
154 | NSModule mod = desc->mod; | ||
155 | NSObjectFileImage img = desc->img; | ||
156 | DYLD_BOOL success = NSUnLinkModule(mod, NSUNLINKMODULE_OPTION_NONE); | ||
157 | if ( success ) { | ||
158 | NSDestroyObjectFileImage(img); | ||
159 | delete desc; | ||
160 | pHnd = 0; | ||
161 | } | ||
162 | #if defined(QT_DEBUG) || defined(QT_DEBUG_COMPONENT) | ||
163 | else { | ||
164 | qWarning( "Error in NSUnLinkModule(): %d", ret ); | ||
165 | } | ||
166 | #endif | ||
167 | return pHnd == 0; | ||
168 | } | ||
169 | |||
170 | void* QLibraryPrivate::resolveSymbol( const char* symbol ) | ||
171 | { | ||
172 | //qDebug("QLibraryPrivate::resolveSymbol\n"); | ||
173 | //return FALSE; | ||
174 | if ( !pHnd ) | ||
175 | return 0; | ||
176 | |||
177 | DyldLibDesc* desc = (DyldLibDesc*) pHnd; | ||
178 | NSSymbol sym = NSLookupSymbolInModule(desc->mod, symbol); | ||
179 | void* address = 0; | ||
180 | if (sym != 0) { | ||
181 | address = NSAddressOfSymbol(sym); | ||
182 | } | ||
183 | #if defined(QT_DEBUG) || defined(QT_DEBUG_COMPONENT) | ||
184 | if ( address == 0 ) | ||
185 | qWarning( "Cannot find symbol: %s", symbol ); | ||
186 | #endif | ||
187 | return address; | ||
188 | } | ||
189 | |||
190 | #else | ||
80 | // Something else, assuming POSIX | 191 | // Something else, assuming POSIX |
81 | #include <dlfcn.h> | 192 | #include <dlfcn.h> |
82 | 193 | ||
83 | bool QLibraryPrivate::loadLibrary() | 194 | bool QLibraryPrivate::loadLibrary() |
84 | { | 195 | { |
85 | if ( pHnd ) | 196 | if ( pHnd ) |
86 | return TRUE; | 197 | return TRUE; |
87 | 198 | ||
88 | QString filename = library->library(); | 199 | QString filename = library->library(); |
89 | 200 | ||
90 | pHnd = dlopen( filename.latin1() , RTLD_LAZY ); | 201 | pHnd = dlopen( filename.latin1() , RTLD_LAZY ); |
91 | #if defined(QT_DEBUG) || defined(QT_DEBUG_COMPONENT) | 202 | #if defined(QT_DEBUG) || defined(QT_DEBUG_COMPONENT) |
92 | if ( !pHnd ) | 203 | if ( !pHnd ) |
93 | qWarning( "%s", dlerror() ); | 204 | qWarning( "%s", dlerror() ); |
94 | #endif | 205 | #endif |
95 | return pHnd != 0; | 206 | return pHnd != 0; |
96 | } | 207 | } |
97 | 208 | ||
98 | bool QLibraryPrivate::freeLibrary() | 209 | bool QLibraryPrivate::freeLibrary() |
99 | { | 210 | { |
100 | if ( !pHnd ) | 211 | if ( !pHnd ) |
101 | return TRUE; | 212 | return TRUE; |
102 | 213 | ||
103 | int ec = dlclose( pHnd ); | 214 | int ec = dlclose( pHnd ); |
104 | if ( !ec ) | 215 | if ( !ec ) |
105 | pHnd = 0; | 216 | pHnd = 0; |
106 | #if defined(QT_DEBUG) || defined(QT_DEBUG_COMPONENT) | 217 | #if defined(QT_DEBUG) || defined(QT_DEBUG_COMPONENT) |
107 | else { | 218 | else { |
108 | const char* error = dlerror(); | 219 | const char* error = dlerror(); |
109 | if ( error ) | 220 | if ( error ) |
110 | qWarning( "%s", error ); | 221 | qWarning( "%s", error ); |
111 | } | 222 | } |
112 | #endif | 223 | #endif |
113 | return pHnd == 0; | 224 | return pHnd == 0; |
114 | } | 225 | } |
115 | 226 | ||
116 | void* QLibraryPrivate::resolveSymbol( const char* f ) | 227 | void* QLibraryPrivate::resolveSymbol( const char* f ) |
117 | { | 228 | { |
118 | if ( !pHnd ) | 229 | if ( !pHnd ) |
119 | return 0; | 230 | return 0; |
120 | 231 | ||
121 | void* address = dlsym( pHnd, f ); | 232 | void* address = dlsym( pHnd, f ); |
122 | #if defined(QT_DEBUG) || defined(QT_DEBUG_COMPONENT) | 233 | #if defined(QT_DEBUG) || defined(QT_DEBUG_COMPONENT) |
123 | const char* error = dlerror(); | 234 | const char* error = dlerror(); |
124 | if ( error ) | 235 | if ( error ) |
125 | qWarning( "%s", error ); | 236 | qWarning( "%s", error ); |
126 | #endif | 237 | #endif |
127 | return address; | 238 | return address; |