Changeset 102

Show
Ignore:
Timestamp:
03/28/05 23:51:27 (4 years ago)
Author:
aldacron
Message:

[Docs]
* added selective.html and util.html
* updated index.html and selective.html
[DerelictUtil?]
* added InvalidSharedLibHandleException?
* reduced the amount of platform-specific code in loader.d

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/DerelictUtil/derelict/util/exception.d

    r99 r102  
    6565} 
    6666 
     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*/ 
     71class InvalidSharedLibHandleException : DerelictException 
     72{ 
     73public: 
     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     
     86private: 
     87    char[] _sharedLibName; 
     88} 
     89 
    6790//****************************************************************************** 
    6891 
  • trunk/DerelictUtil/derelict/util/loader.d

    r99 r102  
    77} 
    88 
     9 
     10private alias void* SharedLibHandle; 
     11 
     12//==============================================================================     
     13class SharedLib 
     14{ 
     15private: 
     16    SharedLibHandle _handle; 
     17    char[] _name; 
     18     
     19    this(SharedLibHandle handle, char[] name) 
     20    { 
     21        _handle = handle; 
     22        _name = name; 
     23    } 
     24} 
     25//============================================================================== 
     26SharedLib Derelict_LoadSharedLib(char[] libName) 
     27in 
     28{ 
     29    assert(libName !== null); 
     30} 
     31body 
     32{ 
     33    return Platform_LoadSharedLib(libName);  
     34} 
     35//============================================================================== 
     36void Derelict_UnloadSharedLib(SharedLib lib) 
     37{ 
     38    if(lib !== null && lib._handle !== null) 
     39        Platform_UnloadSharedLib(lib); 
     40} 
     41//============================================================================== 
     42void* Derelict_GetProc(SharedLib lib, char[] procName) 
     43in 
     44{ 
     45    assert(lib !== null); 
     46    assert(procName !== null); 
     47} 
     48body 
     49{ 
     50    if(lib._handle is null) 
     51        throw new InvalidSharedLibHandleException(lib._name); 
     52    return Platform_GetProc(lib, procName);  
     53} 
     54//============================================================================== 
    955version(Windows) 
    1056{ 
    1157    import std.c.windows.windows; 
    1258     
    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) 
    3260    { 
    3361        HMODULE hlib = LoadLibraryA(toStringz(libName)); 
     
    3866    } 
    3967     
    40     void Derelict_UnloadSharedLib(SharedLib lib) 
     68    void Platform_UnloadSharedLib(SharedLib lib) 
    4169    { 
    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; 
    4772    } 
    4873     
    49     void* Derelict_GetProc(SharedLib lib, char[] procName) 
    50     in 
     74    void* Platform_GetProc(SharedLib lib, char[] procName) 
    5175    { 
    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)); 
    5877        if(null is proc) 
    5978            Derelict_HandleMissingProc(lib._name, procName); 
     
    6483} 
    6584else version(linux) 
    66 
    67     alias void* HMODULE; 
    68      
     85{    
    6986    extern(C) 
    7087    { 
     
    7491        void* dlsym(void* hlib, char* symbolName); 
    7592    } 
    76      
    77     class SharedLib 
    78     { 
    79     private: 
    80         HMODULE _handle; 
    81         char[] _name; 
    8293         
    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) 
    9695    { 
    9796        void* hlib = dlopen(toStringz(libName), RTLD_NOW); 
     
    102101    } 
    103102     
    104     void Derelict_UnloadSharedLib(SharedLib lib) 
     103    void Platform_UnloadSharedLib(SharedLib lib) 
    105104    { 
    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; 
    111107    } 
    112108     
    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) 
    120110    { 
    121111        void* proc = dlsym(lib._handle, toStringz(procName)); 
     
    130120    static assert(0); 
    131121} 
     122 
  • trunk/docs/index.html

    r101 r102  
    7272</p><p> 
    7373While 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. 
     74of manually loading libraries, other features (such as <a href="selective.html"> 
     75selective symbol exceptions</a>) are provided through the DerelictUtil package. 
     76As a side effect, all Derelict packages have an implicit dependency upon DerelictUtil.  
     77This means that when compiling any individual packages, DerelictUtil must be 
     78available on the import path, and when linking, DerelictUtil must be linked into 
     79the application. See the DerelictUtil documentation for more details. 
    8080</p><p> 
    8181The documents linked in the first section below give a general overview of  
     
    8787<ul> 
    8888<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> 
    9090<li>Contributors</li> 
    9191<li>Licenses</li> 
     
    102102<li>DerelictSDLNet</li> 
    103103<li>DerelictSDLttf</li> 
    104 <li>DerelictUtil</li> 
     104<li><a href="util.html">DerelictUtil</a></li> 
    105105</ul> 
    106106</body> 
  • trunk/docs/loading.html

    r101 r102  
    4343than expected, is corrupt, or otherwise cannot be loaded. In the case that a  
    4444shared 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> 
     45excetpion. You can read more about these exceptions in the doumentation for  
     46<a href="util.html">DerelictUtil</a>. 
    6947 
    7048<h3>Unloading Shared Libraries</h3>