summaryrefslogtreecommitdiffstats
path: root/Source/kwsys/DynamicLoader.cxx
diff options
context:
space:
mode:
authorAndy Cedilnik <andy.cedilnik@kitware.com>2006-03-16 16:01:05 (GMT)
committerAndy Cedilnik <andy.cedilnik@kitware.com>2006-03-16 16:01:05 (GMT)
commitf483e48d2a2f3361dcf3c60096bbfe9975f90ddf (patch)
tree2909a53a3efb79bf633ba0be2fa93d7c7b68181f /Source/kwsys/DynamicLoader.cxx
parent4102949bf95eee1ce88544fafdf80439aece85b2 (diff)
downloadCMake-f483e48d2a2f3361dcf3c60096bbfe9975f90ddf.zip
CMake-f483e48d2a2f3361dcf3c60096bbfe9975f90ddf.tar.gz
CMake-f483e48d2a2f3361dcf3c60096bbfe9975f90ddf.tar.bz2
ENH: Cleanup DynamicLoader so that the symbols have more consistent names, start using dynamic loader from kwsys in CMake
Diffstat (limited to 'Source/kwsys/DynamicLoader.cxx')
-rw-r--r--Source/kwsys/DynamicLoader.cxx45
1 files changed, 24 insertions, 21 deletions
diff --git a/Source/kwsys/DynamicLoader.cxx b/Source/kwsys/DynamicLoader.cxx
index fed90ea..486d5b3 100644
--- a/Source/kwsys/DynamicLoader.cxx
+++ b/Source/kwsys/DynamicLoader.cxx
@@ -37,8 +37,8 @@
// 1. HP machines which uses shl_load
// 2. Mac OS X 10.2.x and earlier which uses NSLinkModule
// 3. Windows which uses LoadLibrary
-// 4. Most unix systems (including Mac OS X 10.3 and later) which use dlopen (default)
-// Each part of the ifdef contains a complete implementation for
+// 4. Most unix systems (including Mac OS X 10.3 and later) which use dlopen
+// (default) Each part of the ifdef contains a complete implementation for
// the static methods of DynamicLoader.
namespace KWSYS_NAMESPACE
@@ -66,25 +66,25 @@ namespace KWSYS_NAMESPACE
{
//----------------------------------------------------------------------------
-LibHandle DynamicLoader::OpenLibrary(const char* libname )
+DynamicLoader::LibraryHandle DynamicLoader::OpenLibrary(const char* libname )
{
return shl_load(libname, BIND_DEFERRED | DYNAMIC_PATH, 0L);
}
//----------------------------------------------------------------------------
-int DynamicLoader::CloseLibrary(LibHandle lib)
+int DynamicLoader::CloseLibrary(DynamicLoader::LibraryHandle lib)
{
return !shl_unload(lib);
}
//----------------------------------------------------------------------------
-DynamicLoaderFunction
-DynamicLoader::GetSymbolAddress(LibHandle lib, const char* sym)
+DynamicLoader::SymbolPointer
+DynamicLoader::GetSymbolAddress(DynamicLoader::LibraryHandle lib, const char* sym)
{
void* addr;
int status;
- /* TYPE_PROCEDURE Look for a function or procedure.
+ /* TYPE_PROCEDURE Look for a function or procedure. (This used to be default)
* TYPE_DATA Look for a symbol in the data segment (for example, variables).
* TYPE_UNDEFINED Look for any symbol.
*/
@@ -92,7 +92,7 @@ DynamicLoader::GetSymbolAddress(LibHandle lib, const char* sym)
void* result = (status < 0) ? (void*)0 : addr;
// Hack to cast pointer-to-data to pointer-to-function.
- return *reinterpret_cast<DynamicLoaderFunction*>(&result);
+ return *reinterpret_cast<DynamicLoader::SymbolPointer*>(&result);
}
//----------------------------------------------------------------------------
@@ -149,7 +149,7 @@ namespace KWSYS_NAMESPACE
{
//----------------------------------------------------------------------------
-LibHandle DynamicLoader::OpenLibrary(const char* libname )
+DynamicLoader::LibraryHandle DynamicLoader::OpenLibrary(const char* libname )
{
NSObjectFileImageReturnCode rc;
NSObjectFileImage image = 0;
@@ -167,7 +167,7 @@ LibHandle DynamicLoader::OpenLibrary(const char* libname )
}
//----------------------------------------------------------------------------
-int DynamicLoader::CloseLibrary( LibHandle lib)
+int DynamicLoader::CloseLibrary( DynamicLoader::LibraryHandle lib)
{
// NSUNLINKMODULE_OPTION_KEEP_MEMORY_MAPPED
// With this option the memory for the module is not deallocated
@@ -179,7 +179,8 @@ int DynamicLoader::CloseLibrary( LibHandle lib)
}
//----------------------------------------------------------------------------
-DynamicLoaderFunction DynamicLoader::GetSymbolAddress(LibHandle lib, const char* sym)
+DynamicLoader::SymbolPointer DynamicLoader::GetSymbolAddress(
+ DynamicLoader::LibraryHandle lib, const char* sym)
{
void *result=0;
// Need to prepend symbols with '_' on Apple-gcc compilers
@@ -196,7 +197,7 @@ DynamicLoaderFunction DynamicLoader::GetSymbolAddress(LibHandle lib, const char*
delete[] rsym;
// Hack to cast pointer-to-data to pointer-to-function.
- return *reinterpret_cast<DynamicLoaderFunction*>(&result);
+ return *reinterpret_cast<DynamicLoader::SymbolPointer*>(&result);
}
//----------------------------------------------------------------------------
@@ -235,9 +236,9 @@ namespace KWSYS_NAMESPACE
{
//----------------------------------------------------------------------------
-LibHandle DynamicLoader::OpenLibrary(const char* libname)
+DynamicLoader::LibraryHandle DynamicLoader::OpenLibrary(const char* libname)
{
- LibHandle lh;
+ DynamicLoader::LibraryHandle lh;
#ifdef UNICODE
wchar_t libn[MB_CUR_MAX];
mbstowcs(libn, libname, MB_CUR_MAX);
@@ -249,13 +250,14 @@ LibHandle DynamicLoader::OpenLibrary(const char* libname)
}
//----------------------------------------------------------------------------
-int DynamicLoader::CloseLibrary(LibHandle lib)
+int DynamicLoader::CloseLibrary(DynamicLoader::LibraryHandle lib)
{
return (int)FreeLibrary(lib);
}
//----------------------------------------------------------------------------
-DynamicLoaderFunction DynamicLoader::GetSymbolAddress(LibHandle lib, const char* sym)
+DynamicLoader::SymbolPointer DynamicLoader::GetSymbolAddress(
+ DynamicLoader::LibraryHandle lib, const char* sym)
{
void *result;
#ifdef __BORLANDC__
@@ -278,7 +280,7 @@ DynamicLoaderFunction DynamicLoader::GetSymbolAddress(LibHandle lib, const char*
delete[] rsym;
#endif
// Hack to cast pointer-to-data to pointer-to-function.
- return *reinterpret_cast<DynamicLoaderFunction*>(&result);
+ return *reinterpret_cast<DynamicLoader::SymbolPointer*>(&result);
}
//----------------------------------------------------------------------------
@@ -336,13 +338,13 @@ namespace KWSYS_NAMESPACE
{
//----------------------------------------------------------------------------
-LibHandle DynamicLoader::OpenLibrary(const char* libname )
+DynamicLoader::LibraryHandle DynamicLoader::OpenLibrary(const char* libname )
{
return dlopen(libname, RTLD_LAZY);
}
//----------------------------------------------------------------------------
-int DynamicLoader::CloseLibrary(LibHandle lib)
+int DynamicLoader::CloseLibrary(DynamicLoader::LibraryHandle lib)
{
if (lib)
{
@@ -354,12 +356,13 @@ int DynamicLoader::CloseLibrary(LibHandle lib)
}
//----------------------------------------------------------------------------
-DynamicLoaderFunction DynamicLoader::GetSymbolAddress(LibHandle lib, const char* sym)
+DynamicLoader::SymbolPointer DynamicLoader::GetSymbolAddress(
+ DynamicLoader::LibraryHandle lib, const char* sym)
{
void* result = dlsym(lib, sym);
// Hack to cast pointer-to-data to pointer-to-function.
- return *reinterpret_cast<DynamicLoaderFunction*>(&result);
+ return *reinterpret_cast<DynamicLoader::SymbolPointer*>(&result);
}
//----------------------------------------------------------------------------