From 7f48ed429b393b28cb6362af5dcddd9bb27c3901 Mon Sep 17 00:00:00 2001
From: Carl Worth <cworth@cworth.org>
Date: Wed, 24 Apr 2013 22:55:01 -0700
Subject: [PATCH] Generalize glXGetProcAddressARB wrapper to work for all
 wrapper functions

The originally implementation here had a whitelist of function names for
which we would return a wrapped symbol, (a very short whitelist consisting
only of "glXSwapBuffers"). A hard-coded list here would be a maintenance
nightmare.

Instead, we now simply perform a dlsym lookup on the wrapper library itself
and if there's a function that exists in the library matching the name
being requested, we return that.

This way we can add functions to our wrapper library without needing to
change the implementation of glXGetProcAddressARB at all.
---
 glxwrap.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/glxwrap.c b/glxwrap.c
index 80ccf1a..4d16e4d 100644
--- a/glxwrap.c
+++ b/glxwrap.c
@@ -98,6 +98,7 @@ typedef __GLXextFuncPtr (* fips_glXGetProcAddressARB_t)(const GLubyte *func);
 __GLXextFuncPtr
 glXGetProcAddressARB (const GLubyte *func)
 {
+	__GLXextFuncPtr ptr;
 	static fips_glXGetProcAddressARB_t real_glXGetProcAddressARB = NULL;
 	const char *name = "glXGetProcAddressARB";
 
@@ -110,8 +111,11 @@ glXGetProcAddressARB (const GLubyte *func)
 		}
 	}
 
-	if (strcmp ((const char *)func, "glXSwapBuffers") == 0)
-		return (__GLXextFuncPtr) glXSwapBuffers;
-	else
-		return real_glXGetProcAddressARB (func);
+	/* If our library has this symbol, that's what we want to give. */
+	ptr = dlwrap_real_dlsym (NULL, (const char *) func);
+	if (ptr)
+		return ptr;
+
+	/* Otherwise, just defer to the real glXGetProcAddressARB. */
+	return real_glXGetProcAddressARB (func);
 }
-- 
2.45.2