[Scummvm-cvs-logs] SF.net SVN: scummvm: [23945] scummvm/trunk/base/plugins.cpp

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Wed Sep 20 13:54:19 CEST 2006


Revision: 23945
          http://svn.sourceforge.net/scummvm/?rev=23945&view=rev
Author:   fingolfin
Date:     2006-09-20 04:54:15 -0700 (Wed, 20 Sep 2006)

Log Message:
-----------
Work around conflict between ISO C++ and POSIX, to allow ISO C++ compliant compilers like GCC 4.x to compile the plugin code again

Modified Paths:
--------------
    scummvm/trunk/base/plugins.cpp

Modified: scummvm/trunk/base/plugins.cpp
===================================================================
--- scummvm/trunk/base/plugins.cpp	2006-09-20 06:39:27 UTC (rev 23944)
+++ scummvm/trunk/base/plugins.cpp	2006-09-20 11:54:15 UTC (rev 23945)
@@ -141,6 +141,9 @@
 #ifdef DYNAMIC_MODULES
 
 class DynamicPlugin : public Plugin {
+protected:
+	typedef void (*VoidFunc)();
+	
 	void *_dlHandle;
 	Common::String _filename;
 
@@ -151,7 +154,7 @@
 	DetectFunc _df;
 	GameList _games;
 
-	void *findSymbol(const char *symbol);
+	VoidFunc findSymbol(const char *symbol);
 
 public:
 	DynamicPlugin(const Common::String &filename)
@@ -181,22 +184,29 @@
 	void unloadPlugin();
 };
 
-void *DynamicPlugin::findSymbol(const char *symbol) {
+DynamicPlugin::VoidFunc DynamicPlugin::findSymbol(const char *symbol) {
 #if defined(UNIX) || defined(__DC__)
 	void *func = dlsym(_dlHandle, symbol);
 	if (!func)
 		warning("Failed loading symbol '%s' from plugin '%s' (%s)", symbol, _filename.c_str(), dlerror());
-	return func;
 #else
 #if defined(_WIN32)
-	void *func = (void*)GetProcAddress((HMODULE)_dlHandle, symbol);
+	void *func = (void *)GetProcAddress((HMODULE)_dlHandle, symbol);
 	if (!func)
 		warning("Failed loading symbol '%s' from plugin '%s'", symbol, _filename.c_str());
-	return func;
 #else
 #error TODO
 #endif
 #endif
+
+	// FIXME HACK: This is a HACK to circumvent a clash between the ISO C++
+	// standard and POSIX: ISO C++ disallows casting between function pointers
+	// and data pointers, but dlsym always returns a void pointer. For details,
+	// see e.g. <http://www.trilithium.com/johan/2004/12/problem-with-dlsym/>.
+	assert(sizeof(VoidFunc) == sizeof(func));
+	VoidFunc tmp;
+	memcpy(&tmp, &func, sizeof(VoidFunc));
+	return tmp;
 }
 
 bool DynamicPlugin::loadPlugin() {


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list