[cmake-commits] king committed DynamicLoader.cxx 1.18 1.19

cmake-commits at cmake.org cmake-commits at cmake.org
Thu Apr 19 11:31:57 EDT 2007


Update of /cvsroot/CMake/CMake/Source/kwsys
In directory public:/mounts/ram/cvs-serv23880/Source/kwsys

Modified Files:
	DynamicLoader.cxx 
Log Message:
ENH: Added support for Watcom compiler.  Added TODO comment about calling conventions.


Index: DynamicLoader.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/kwsys/DynamicLoader.cxx,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- DynamicLoader.cxx	9 Dec 2006 16:25:25 -0000	1.18
+++ DynamicLoader.cxx	19 Apr 2007 15:31:55 -0000	1.19
@@ -251,13 +251,35 @@
 DynamicLoader::SymbolPointer DynamicLoader::GetSymbolAddress(
   DynamicLoader::LibraryHandle lib, const char* sym)
 {
+  // TODO: The calling convention affects the name of the symbol.  We
+  // should have a tool to help get the symbol with the desired
+  // calling convention.  Currently we assume cdecl.
+  //
+  // Borland:
+  //   __cdecl    = "_func" (default)
+  //   __fastcall = "@_func"
+  //   __stdcall  = "func"
+  //
+  // Watcom:
+  //   __cdecl    = "_func"
+  //   __fastcall = "@_func at X"
+  //   __stdcall  = "_func at X"
+  //   __watcall  = "func_" (default)
+  //
+  // MSVC:
+  //   __cdecl    = "func" (default)
+  //   __fastcall = "@_func at X"
+  //   __stdcall  = "_func at X"
+  //
+  // Note that the "@X" part of the name above is the total size (in
+  // bytes) of the arguments on the stack.
   void *result;
-#ifdef __BORLANDC__
-  // Need to prepend symbols with '_' on borland compilers
+#if defined(__BORLANDC__) || defined(__WATCOMC__)
+  // Need to prepend symbols with '_'
   size_t len = strlen(sym);
   char *rsym = new char[len + 1 + 1];
   strcpy(rsym, "_");
-  strcat(rsym+1, sym);
+  strcat(rsym, sym);
 #else
   const char *rsym = sym;
 #endif
@@ -268,11 +290,15 @@
 #else
   result = (void*)GetProcAddress(lib, rsym);
 #endif
-#ifdef __BORLANDC__
+#if defined(__BORLANDC__) || defined(__WATCOMC__)
   delete[] rsym;
 #endif
   // Hack to cast pointer-to-data to pointer-to-function.
+#ifdef __WATCOMC__
+  return *(DynamicLoader::SymbolPointer*)(&result);
+#else
   return *reinterpret_cast<DynamicLoader::SymbolPointer*>(&result);
+#endif
 }
 
 //----------------------------------------------------------------------------



More information about the Cmake-commits mailing list