Changeset 102
- Timestamp:
- 03/28/05 23:51:27 (4 years ago)
- Files:
-
- trunk/DerelictUtil/derelict/util/exception.d (modified) (1 diff)
- trunk/DerelictUtil/derelict/util/loader.d (modified) (6 diffs)
- trunk/docs/index.html (modified) (3 diffs)
- trunk/docs/loading.html (modified) (1 diff)
- trunk/docs/selective.html (added)
- trunk/docs/util.html (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/DerelictUtil/derelict/util/exception.d
r99 r102 65 65 } 66 66 67 /** 68 * This exception *might* be thrown when an attempt is made to use a shared library 69 * handle that references an unloaded shared library. 70 */ 71 class InvalidSharedLibHandleException : DerelictException 72 { 73 public: 74 75 this(char[] sharedLibName) 76 { 77 super("Attempted to use handle to unloaded shared library " ~ sharedLibName); 78 _sharedLibName = sharedLibName.dup; 79 } 80 81 char[] sharedLibName() 82 { 83 return _sharedLibName; 84 } 85 86 private: 87 char[] _sharedLibName; 88 } 89 67 90 //****************************************************************************** 68 91 trunk/DerelictUtil/derelict/util/loader.d
r99 r102 7 7 } 8 8 9 10 private alias void* SharedLibHandle; 11 12 //============================================================================== 13 class SharedLib 14 { 15 private: 16 SharedLibHandle _handle; 17 char[] _name; 18 19 this(SharedLibHandle handle, char[] name) 20 { 21 _handle = handle; 22 _name = name; 23 } 24 } 25 //============================================================================== 26 SharedLib Derelict_LoadSharedLib(char[] libName) 27 in 28 { 29 assert(libName !== null); 30 } 31 body 32 { 33 return Platform_LoadSharedLib(libName); 34 } 35 //============================================================================== 36 void Derelict_UnloadSharedLib(SharedLib lib) 37 { 38 if(lib !== null && lib._handle !== null) 39 Platform_UnloadSharedLib(lib); 40 } 41 //============================================================================== 42 void* Derelict_GetProc(SharedLib lib, char[] procName) 43 in 44 { 45 assert(lib !== null); 46 assert(procName !== null); 47 } 48 body 49 { 50 if(lib._handle is null) 51 throw new InvalidSharedLibHandleException(lib._name); 52 return Platform_GetProc(lib, procName); 53 } 54 //============================================================================== 9 55 version(Windows) 10 56 { 11 57 import std.c.windows.windows; 12 58 13 class SharedLib 14 { 15 private: 16 HMODULE _handle; 17 char[] _name; 18 19 this(HMODULE handle, char[] name) 20 { 21 _handle = handle; 22 _name = name; 23 } 24 } 25 26 SharedLib Derelict_LoadSharedLib(char[] libName) 27 in 28 { 29 assert(libName !== null); 30 } 31 body 59 SharedLib Platform_LoadSharedLib(char[] libName) 32 60 { 33 61 HMODULE hlib = LoadLibraryA(toStringz(libName)); … … 38 66 } 39 67 40 void Derelict_UnloadSharedLib(SharedLib lib)68 void Platform_UnloadSharedLib(SharedLib lib) 41 69 { 42 if(lib !== null && lib._handle !== null) 43 { 44 FreeLibrary(lib._handle); 45 lib._handle = null; 46 } 70 FreeLibrary(cast(HMODULE)lib._handle); 71 lib._handle = null; 47 72 } 48 73 49 void* Derelict_GetProc(SharedLib lib, char[] procName) 50 in 74 void* Platform_GetProc(SharedLib lib, char[] procName) 51 75 { 52 assert(lib !== null); 53 assert(procName !== null); 54 } 55 body 56 { 57 void* proc = GetProcAddress(lib._handle, toStringz(procName)); 76 void* proc = GetProcAddress(cast(HMODULE)lib._handle, toStringz(procName)); 58 77 if(null is proc) 59 78 Derelict_HandleMissingProc(lib._name, procName); … … 64 83 } 65 84 else version(linux) 66 { 67 alias void* HMODULE; 68 85 { 69 86 extern(C) 70 87 { … … 74 91 void* dlsym(void* hlib, char* symbolName); 75 92 } 76 77 class SharedLib78 {79 private:80 HMODULE _handle;81 char[] _name;82 93 83 this(HMODULE handle, char[] name) 84 { 85 _handle = handle; 86 _name = name; 87 } 88 } 89 90 SharedLib Derelict_LoadSharedLib(char[] libName) 91 in 92 { 93 assert(libName !== null); 94 } 95 body 94 SharedLib Platform_LoadSharedLib(char[] libName) 96 95 { 97 96 void* hlib = dlopen(toStringz(libName), RTLD_NOW); … … 102 101 } 103 102 104 void Derelict_UnloadSharedLib(SharedLib lib)103 void Platform_UnloadSharedLib(SharedLib lib) 105 104 { 106 if(lib !== null && lib._handle !== null) 107 { 108 dlclose(lib._handle); 109 lib._handle = null; 110 } 105 dlclose(lib._handle); 106 lib._handle = null; 111 107 } 112 108 113 void* Derelict_GetProc(SharedLib lib, char[] procName) 114 in 115 { 116 assert(lib !== null); 117 assert(procName !== null); 118 } 119 body 109 void* Platform_GetProc(SharedLib lib, char[] procName) 120 110 { 121 111 void* proc = dlsym(lib._handle, toStringz(procName)); … … 130 120 static assert(0); 131 121 } 122 trunk/docs/index.html
r101 r102 72 72 </p><p> 73 73 While some of the functionality that Derelict provides is baked into the process 74 of manually loading libraries, other features (such as selective symbol loading)75 are provided through the DerelictUtil package. As a side effect, all Derelict 76 packages have an implicit dependency upon DerelictUtil. This means that when 77 compiling any individual packages, DerelictUtil must be available on the import 78 path, and when linking, DerelictUtil must be linked into the application. See the 79 DerelictUtil documenation for more details.74 of manually loading libraries, other features (such as <a href="selective.html"> 75 selective symbol exceptions</a>) are provided through the DerelictUtil package. 76 As a side effect, all Derelict packages have an implicit dependency upon DerelictUtil. 77 This means that when compiling any individual packages, DerelictUtil must be 78 available on the import path, and when linking, DerelictUtil must be linked into 79 the application. See the DerelictUtil documentation for more details. 80 80 </p><p> 81 81 The documents linked in the first section below give a general overview of … … 87 87 <ul> 88 88 <li><a href="loading.html">Loading/Unloading Shared Libraries</a></li> 89 <li> Selective Symbol Loading</li>89 <li><a href="selective.html">Selective Symbol Exceptions</a></li> 90 90 <li>Contributors</li> 91 91 <li>Licenses</li> … … 102 102 <li>DerelictSDLNet</li> 103 103 <li>DerelictSDLttf</li> 104 <li> DerelictUtil</li>104 <li><a href="util.html">DerelictUtil</a></li> 105 105 </ul> 106 106 </body> trunk/docs/loading.html
r101 r102 43 43 than expected, is corrupt, or otherwise cannot be loaded. In the case that a 44 44 shared library fails to load, the Load functions will throw an appropriate 45 excetpion. Following are the descriptions of the two possible exceptions the Load 46 functions can throw. 47 48 <p><hr></p><p> 49 <tt><b>SharedLibLoadException</b></tt></br> 50 This exception is thrown when the shared library cannot be loaded. This indicates 51 that the library is not on the user's system, is not on the path, or perhaps has 52 a name that is different than expected. In otherwords, no library could be found 53 that matches the name returned by the <tt>sharedLibName</tt> property of this 54 exception.</p> 55 56 <p><tt><b>SharedLibProcLoadException</b></tt></br> 57 This exception is thrown when a symbol cannot be loaded from a shared library. 58 This might indicate that the library is corrupt, or that it is a different version 59 than what was expected. In other words, the library exists on the system, but 60 no symbol that matches the name returned by the <tt>procName</tt> property of 61 this exception could be found. In some cases, it may be desirable to prevent this 62 exception from being thrown. You can learn how by reading about 63 <a href="selective.html">Selective Symbol Loading</a>.</p> 64 <p><hr></p> 65 66 <p> 67 In order to make use of the exceptions in your code, you need to import the 68 <tt>exceptions</tt> module from <a href="util.html">DerelictUtil</a></p> 45 excetpion. You can read more about these exceptions in the doumentation for 46 <a href="util.html">DerelictUtil</a>. 69 47 70 48 <h3>Unloading Shared Libraries</h3>
