[Lldb-commits] [PATCH] PluginManager: Don't cast from void-pointer to pointer-to-function

David Majnemer david.majnemer at gmail.com
Tue Jul 22 13:32:32 PDT 2014


Hi zturner, tfiala,

GCC warns on reinterpret_cast expressions involving a void-pointer
source and a pointer-to-function destination.  Take a detour through
intptr_t to silence it.

http://reviews.llvm.org/D4626

Files:
  source/Core/PluginManager.cpp

Index: source/Core/PluginManager.cpp
===================================================================
--- source/Core/PluginManager.cpp
+++ source/Core/PluginManager.cpp
@@ -79,6 +79,12 @@
     plugin_map[plugin_file_spec] = plugin_info;
 }
 
+template <typename FPtrTy>
+static FPtrTy
+CastToFPtr (void *VPtr)
+{
+    return reinterpret_cast<FPtrTy>(reinterpret_cast<intptr_t>(VPtr));
+}
 
 static FileSpec::EnumerateDirectoryResult 
 LoadPluginCallback 
@@ -115,7 +121,11 @@
             if (plugin_info.plugin_handle)
             {
                 bool success = false;
-                plugin_info.plugin_init_callback = (PluginInitCallback)Host::DynamicLibraryGetSymbol (plugin_info.plugin_handle, "LLDBPluginInitialize", error);
+                plugin_info.plugin_init_callback =
+                    CastToFPtr<PluginInitCallback>(
+                        Host::DynamicLibraryGetSymbol(plugin_info.plugin_handle,
+                                                      "LLDBPluginInitialize",
+                                                      error));
                 if (plugin_info.plugin_init_callback)
                 {
                     // Call the plug-in "bool LLDBPluginInitialize(void)" function
@@ -125,7 +135,11 @@
                 if (success)
                 {
                     // It is ok for the "LLDBPluginTerminate" symbol to be NULL
-                    plugin_info.plugin_term_callback = (PluginTermCallback)Host::DynamicLibraryGetSymbol (plugin_info.plugin_handle, "LLDBPluginTerminate", error);
+                    plugin_info.plugin_term_callback =
+                        CastToFPtr<PluginTermCallback>(
+                            Host::DynamicLibraryGetSymbol(
+                                plugin_info.plugin_handle, "LLDBPluginTerminate",
+                                error));
                 }
                 else 
                 {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D4626.11778.patch
Type: text/x-patch
Size: 1903 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20140722/1366eb6e/attachment.bin>


More information about the lldb-commits mailing list