[Mesa-dev] [PATCH 2/2] Move _mesa_dl* functions into dlopen.h and inline them

Matt Turner mattst88 at gmail.com
Wed Aug 22 12:48:45 PDT 2012


No point in having an extra function call for inlinable functions.

Cc: Tapani Pälli <tapani.palli at intel.com>
---
 src/mesa/SConscript    |    1 -
 src/mesa/main/dlopen.c |  112 ------------------------------------------------
 src/mesa/main/dlopen.h |   83 ++++++++++++++++++++++++++++++++---
 src/mesa/sources.mak   |    1 -
 4 files changed, 75 insertions(+), 122 deletions(-)
 delete mode 100644 src/mesa/main/dlopen.c

diff --git a/src/mesa/SConscript b/src/mesa/SConscript
index 1b98b04..5668962 100644
--- a/src/mesa/SConscript
+++ b/src/mesa/SConscript
@@ -60,7 +60,6 @@ main_sources = [
     'main/debug.c',
     'main/depth.c',
     'main/dlist.c',
-    'main/dlopen.c',
     'main/drawpix.c',
     'main/drawtex.c',
     'main/enable.c',
diff --git a/src/mesa/main/dlopen.c b/src/mesa/main/dlopen.c
deleted file mode 100644
index aaee963..0000000
--- a/src/mesa/main/dlopen.c
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
- * Mesa 3-D graphics library
- *
- * Copyright (C) 1999-2008  Brian Paul   All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-
-/**
- * Wrapper functions for dlopen(), dlsym(), dlclose().
- * Note that the #ifdef tests for various environments should be expanded.
- */
-
-
-#include "compiler.h"
-#include "dlopen.h"
-
-#if defined(HAVE_DLOPEN)
-#include <dlfcn.h>
-#endif
-#if defined(_WIN32)
-#include <windows.h>
-#endif
-
-
-/**
- * Wrapper for dlopen().
- * Note that 'flags' isn't used at this time.
- */
-void *
-_mesa_dlopen(const char *libname, int flags)
-{
-#if defined(__blrts)
-   return NULL;
-#elif defined(HAVE_DLOPEN)
-   flags = RTLD_LAZY | RTLD_GLOBAL; /* Overriding flags at this time */
-   return dlopen(libname, flags);
-#elif defined(__MINGW32__)
-   return LoadLibraryA(libname);
-#else
-   return NULL;
-#endif
-}
-
-
-/**
- * Wrapper for dlsym() that does a cast to a generic function type,
- * rather than a void *.  This reduces the number of warnings that are
- * generated.
- */
-GenericFunc
-_mesa_dlsym(void *handle, const char *fname)
-{
-   union {
-      void *v;
-      GenericFunc f;
-   } u;
-#if defined(__blrts)
-   u.v = NULL;
-#elif defined(__DJGPP__)
-   /* need '_' prefix on symbol names */
-   char fname2[1000];
-   fname2[0] = '_';
-   strncpy(fname2 + 1, fname, 998);
-   fname2[999] = 0;
-   u.v = dlsym(handle, fname2);
-#elif defined(HAVE_DLOPEN)
-   u.v = dlsym(handle, fname);
-#elif defined(__MINGW32__)
-   u.v = (void *) GetProcAddress(handle, fname);
-#else
-   u.v = NULL;
-#endif
-   return u.f;
-}
-
-
-/**
- * Wrapper for dlclose().
- */
-void
-_mesa_dlclose(void *handle)
-{
-#if defined(__blrts)
-   (void) handle;
-#elif defined(HAVE_DLOPEN)
-   dlclose(handle);
-#elif defined(__MINGW32__)
-   FreeLibrary(handle);
-#else
-   (void) handle;
-#endif
-}
-
-
-
diff --git a/src/mesa/main/dlopen.h b/src/mesa/main/dlopen.h
index 9895a22..a5366a1 100644
--- a/src/mesa/main/dlopen.h
+++ b/src/mesa/main/dlopen.h
@@ -25,18 +25,85 @@
 #ifndef DLOPEN_H
 #define DLOPEN_H
 
+/**
+ * Wrapper functions for dlopen(), dlsym(), dlclose().
+ * Note that the #ifdef tests for various environments should be expanded.
+ */
 
-typedef void (*GenericFunc)(void);
-
+#if defined(HAVE_DLOPEN)
+#include <dlfcn.h>
+#endif
+#if defined(_WIN32)
+#include <windows.h>
+#endif
 
-extern void *
-_mesa_dlopen(const char *libname, int flags);
+typedef void (*GenericFunc)(void);
 
-extern GenericFunc
-_mesa_dlsym(void *handle, const char *fname);
+/**
+ * Wrapper for dlopen().
+ * Note that 'flags' isn't used at this time.
+ */
+static inline void *
+_mesa_dlopen(const char *libname, int flags)
+{
+#if defined(__blrts)
+   return NULL;
+#elif defined(HAVE_DLOPEN)
+   flags = RTLD_LAZY | RTLD_GLOBAL; /* Overriding flags at this time */
+   return dlopen(libname, flags);
+#elif defined(__MINGW32__)
+   return LoadLibraryA(libname);
+#else
+   return NULL;
+#endif
+}
 
-extern void
-_mesa_dlclose(void *handle);
+/**
+ * Wrapper for dlsym() that does a cast to a generic function type,
+ * rather than a void *.  This reduces the number of warnings that are
+ * generated.
+ */
+static inline GenericFunc
+_mesa_dlsym(void *handle, const char *fname)
+{
+   union {
+      void *v;
+      GenericFunc f;
+   } u;
+#if defined(__blrts)
+   u.v = NULL;
+#elif defined(__DJGPP__)
+   /* need '_' prefix on symbol names */
+   char fname2[1000];
+   fname2[0] = '_';
+   strncpy(fname2 + 1, fname, 998);
+   fname2[999] = 0;
+   u.v = dlsym(handle, fname2);
+#elif defined(HAVE_DLOPEN)
+   u.v = dlsym(handle, fname);
+#elif defined(__MINGW32__)
+   u.v = (void *) GetProcAddress(handle, fname);
+#else
+   u.v = NULL;
+#endif
+   return u.f;
+}
 
+/**
+ * Wrapper for dlclose().
+ */
+static inline void
+_mesa_dlclose(void *handle)
+{
+#if defined(__blrts)
+   (void) handle;
+#elif defined(HAVE_DLOPEN)
+   dlclose(handle);
+#elif defined(__MINGW32__)
+   FreeLibrary(handle);
+#else
+   (void) handle;
+#endif
+}
 
 #endif
diff --git a/src/mesa/sources.mak b/src/mesa/sources.mak
index ee260cb..965222c 100644
--- a/src/mesa/sources.mak
+++ b/src/mesa/sources.mak
@@ -32,7 +32,6 @@ MAIN_FILES = \
 	$(SRCDIR)main/debug.c \
 	$(SRCDIR)main/depth.c \
 	$(SRCDIR)main/dlist.c \
-	$(SRCDIR)main/dlopen.c \
 	$(SRCDIR)main/drawpix.c \
 	$(SRCDIR)main/drawtex.c \
 	$(SRCDIR)main/enable.c \
-- 
1.7.8.6



More information about the mesa-dev mailing list