[Piglit] [PATCH 5/6] dispatch: use do_dlsym() helper on all posix platforms

Emil Velikov emil.l.velikov at gmail.com
Mon Jun 27 16:58:04 UTC 2016


From: Emil Velikov <emil.velikov at collabora.com>

In order to do that move the function further up, and while where doing
that use tabs to indent, as the rest of the file.

Signed-off-by: Emil Velikov <emil.velikov at collabora.com>
---
 tests/util/piglit-dispatch-init.c | 56 +++++++++++++++++----------------------
 1 file changed, 24 insertions(+), 32 deletions(-)

diff --git a/tests/util/piglit-dispatch-init.c b/tests/util/piglit-dispatch-init.c
index 56b7a3d..d137f71 100644
--- a/tests/util/piglit-dispatch-init.c
+++ b/tests/util/piglit-dispatch-init.c
@@ -79,6 +79,29 @@ default_get_proc_address_failure(const char *function_name)
 	piglit_report_result(PIGLIT_FAIL);
 }
 
+#if defined(__APPLE__) || defined(PIGLIT_HAS_EGL)
+static void *
+do_dlsym(void **handle, const char *lib_name, const char *function_name)
+{
+	void *result;
+
+	if (!*handle)
+		*handle = dlopen(lib_name, RTLD_LAZY);
+
+	if (!*handle) {
+		fprintf(stderr, "Could not open %s: %s\n", lib_name, dlerror());
+		return NULL;
+	}
+
+	result = dlsym(*handle, function_name);
+	if (!result)
+		fprintf(stderr, "%s() not found in %s: %s\n", function_name,
+			lib_name, dlerror());
+
+    return result;
+}
+#endif
+
 #if defined(_WIN32)
 
 /**
@@ -128,15 +151,7 @@ get_ext_proc_address(const char *function_name)
 		"/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL";
 	static void *opengl_lib = NULL;
 
-	/* Dynamically load lib */
-	if (!opengl_lib)
-	{
-		opengl_lib = dlopen(opengl_path, RTLD_LAZY);
-		if (!opengl_lib)
-			return NULL;
-	}
-
-	return (piglit_dispatch_function_ptr) dlsym(opengl_lib, function_name);
+	return do_dlsym(&opengl_lib, opengl_path, function_name);
 }
 
 /**
@@ -156,29 +171,6 @@ get_core_proc_address(const char *function_name, int gl_10x_version)
 
 #else /* Linux */
 
-#if defined(PIGLIT_HAS_EGL)
-static void *
-do_dlsym(void **handle, const char *lib_name, const char *function_name)
-{
-    void *result;
-
-    if (!*handle)
-        *handle = dlopen(lib_name, RTLD_LAZY);
-
-    if (!*handle) {
-        fprintf(stderr, "Could not open %s: %s\n", lib_name, dlerror());
-        return NULL;
-    }
-
-    result = dlsym(*handle, function_name);
-    if (!result)
-        fprintf(stderr, "%s() not found in %s: %s\n", function_name, lib_name,
-                dlerror());
-
-    return result;
-}
-#endif
-
 /**
  * This function is used to retrieve the address of all GL functions
  * on Linux.
-- 
2.8.2



More information about the Piglit mailing list