ENH: Hopefully have the DynamicLoader to the proper thing.

This commit is contained in:
Mathieu Malaterre 2006-03-10 11:32:09 -05:00
parent 6b47b28867
commit 011de35360
2 changed files with 23 additions and 6 deletions

View File

@ -220,12 +220,24 @@ int DynamicLoader::CloseLibrary(LibHandle lib)
DynamicLoaderFunction DynamicLoader::GetSymbolAddress(LibHandle lib, const char* sym) DynamicLoaderFunction DynamicLoader::GetSymbolAddress(LibHandle lib, const char* sym)
{ {
void *result; void *result;
#ifdef __BORLANDC__
// Need to prepend symbols with '_' on borland compilers
size_t len = strlen(sym);
char *rsym = new char[len + 1 + 1];
strcpy(rsym, "_");
strcat(rsym+1, sym);
#else
const char *rsym = sym;
#endif
#ifdef UNICODE #ifdef UNICODE
wchar_t wsym[MB_CUR_MAX]; wchar_t wsym[MB_CUR_MAX];
mbstowcs(wsym, sym, MB_CUR_MAX); mbstowcs(wsym, rsym, MB_CUR_MAX);
result = GetProcAddress(lib, wsym); result = GetProcAddress(lib, wsym);
#else #else
result = (void*)GetProcAddress(lib, sym); result = (void*)GetProcAddress(lib, rsym);
#endif
#ifdef __BORLANDC__
delete[] rsym;
#endif #endif
// Hack to cast pointer-to-data to pointer-to-function. // Hack to cast pointer-to-data to pointer-to-function.
return *reinterpret_cast<DynamicLoaderFunction*>(&result); return *reinterpret_cast<DynamicLoaderFunction*>(&result);
@ -317,7 +329,11 @@ const char* DynamicLoader::LibPrefix()
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
const char* DynamicLoader::LibExtension() const char* DynamicLoader::LibExtension()
{ {
#ifdef __CYGWIN__
return ".dll";
#else
return ".so"; return ".so";
#endif
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------

View File

@ -46,6 +46,7 @@ kwsys_stl::string GetLibName(const char* lname)
*/ */
int TestDynamicLoader(const char* libname, const char* symbol, int r1, int r2, int r3) int TestDynamicLoader(const char* libname, const char* symbol, int r1, int r2, int r3)
{ {
//kwsys_ios::cerr << "Testing: " << libname << kwsys_ios::endl;
kwsys::LibHandle l = kwsys::DynamicLoader::OpenLibrary(libname); kwsys::LibHandle l = kwsys::DynamicLoader::OpenLibrary(libname);
// If result is incompatible with expectation just fails (xor): // If result is incompatible with expectation just fails (xor):
if( (r1 && !l) || (!r1 && l) ) if( (r1 && !l) || (!r1 && l) )
@ -85,10 +86,10 @@ int main(int , char *[])
res += TestDynamicLoader("libdl.so", "TestDynamicLoader",1,0,1); res += TestDynamicLoader("libdl.so", "TestDynamicLoader",1,0,1);
#endif #endif
// Now try on the generated library // Now try on the generated library
//kwsys_stl::string libname = GetLibName("testDynload"); kwsys_stl::string libname = GetLibName("testDynload");
//res += TestDynamicLoader(libname.c_str(), "dummy",1,0,1); res += TestDynamicLoader(libname.c_str(), "dummy",1,0,1);
//res += TestDynamicLoader(libname.c_str(), "TestDynamicLoaderFunction",1,1,1); res += TestDynamicLoader(libname.c_str(), "TestDynamicLoaderFunction",1,1,1);
//res += TestDynamicLoader(libname.c_str(), "TestDynamicLoaderData",1,1,1); res += TestDynamicLoader(libname.c_str(), "TestDynamicLoaderData",1,1,1);
return res; return res;
} }