]> git.cworth.org Git - fips/commitdiff
Add a new GLWRAP_DEFER_WITH_RETURN macro.
authorCarl Worth <cworth@cworth.org>
Mon, 10 Jun 2013 21:40:43 +0000 (14:40 -0700)
committerCarl Worth <cworth@cworth.org>
Mon, 10 Jun 2013 21:48:26 +0000 (14:48 -0700)
This allows for the elimination of some code duplication from our
implementation of glXGetPrcAddressARB. The previous implementation
duplicated code from glwrap_lookup simply because the GLWRAP_DEFER
macro did not provide access to the return value of the wrapped
function.

With the new macro, (very much like GLWRAP_DEFER but accepting a
parameter for a variable to accept the return value), we can eliminate
this code duplication.

Of course, our symbol-extraction script is now a bit more complicated
since it has to find occurrences of DEFER_WITH_RETURN in addition to
occurrences of DEFER, and pull out the function name as the second
argument rather than the first.

extract-wrapped-symbols
glwrap.h
glxwrap.c

index 2b9f76a6344af7c35af5d4c3f804b1d57d1e4c0d..8cdd035070d5b8c974ee128773c0b876a8d7bcca 100755 (executable)
@@ -8,12 +8,16 @@
 # libfips, while all other symbols are private.
 
 # We have two different patterns for identifying wrapped
-# functions. The first is a call to a macro ending in "DEFER" (such as
-# DEFER or TIMED_DEFER). In this case, the first argument to the macro
-# is the name of the wrapped function.
+# functions. The first is a call to one of the DEFER macros
+# (GLWRAP_DEFER, TIMED_DEFER, WGLWRAP_DEFER_WITH_RETURN, etc.). In
+# this case, the name of the wrapped function appears as the first or
+# second argument to the macro, (second for the case of of
+# _WITH_RETURN macro).
 
 deferred=`grep 'DEFER[ (]*e*gl' $@ | sed -s 's/.*DEFER *(\([^,)]*\).*/\1/'`
 
+deferred_return=`grep 'DEFER_WITH_RETURN *([^,]*, *e*gl' $@ | sed -s 's/.*DEFER_WITH_RETURN *([^,]*, *\([^,)]*\).*/\1/'`
+
 # The second-case is functions for which we either implement or call
 # the underlying "real" function. In these cases, the code uses the
 # convention of having a function or a function-pointer with a name of
@@ -32,6 +36,7 @@ global:
 EOF
 
 echo "$deferred
+$deferred_return
 $wrapped" | sort | uniq | sed -e 's/\(.*\)/    \1;/'
 
 cat <<EOF
index 9195007c4b51b15cd8eb38eea9439ee0c15d4579..bd2e265dac5e9d26c7d7a12821e08ea9f0c0e40a 100644 (file)
--- a/glwrap.h
+++ b/glwrap.h
@@ -37,4 +37,12 @@ glwrap_lookup (char *name);
        real_ ## function(__VA_ARGS__);                         \
 } while (0);
 
+/* As GLWRAP_DEFER, but also set 'ret' to the return value */
+#define GLWRAP_DEFER_WITH_RETURN(ret, function,...) do {       \
+       static typeof(&function) real_ ## function;             \
+       if (! real_ ## function)                                \
+               real_ ## function = glwrap_lookup (#function);  \
+       (ret) = real_ ## function(__VA_ARGS__);                 \
+} while (0);
+
 #endif
index 6da42e6622abf2a613f373e5db2ef0014c9d80bc..84bf48522565e489de274cd87e752d5a470ebd01 100644 (file)
--- a/glxwrap.c
+++ b/glxwrap.c
@@ -45,24 +45,15 @@ glXSwapBuffers (Display *dpy, GLXDrawable drawable)
  */
 void (*glXGetProcAddressARB (const GLubyte *func))(void)
 {
-       void *ptr;
-       static typeof(&glXGetProcAddressARB) glxwrap_real_glXGetProcAddressARB = NULL;
-       char *name = "glXGetProcAddressARB";
-
-       if (! glxwrap_real_glXGetProcAddressARB) {
-               glxwrap_real_glXGetProcAddressARB = glwrap_lookup (name);
-               if (! glxwrap_real_glXGetProcAddressARB) {
-                       fprintf (stderr, "Error: Failed to find function %s.\n",
-                                name);
-                       return NULL;
-               }
-       }
+       void *ret;
 
        /* 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;
+       ret = dlwrap_real_dlsym (NULL, (const char *) func);
+       if (ret)
+               return ret;
 
        /* Otherwise, just defer to the real glXGetProcAddressARB. */
-       return glxwrap_real_glXGetProcAddressARB (func);
+       GLWRAP_DEFER_WITH_RETURN (ret, glXGetProcAddressARB, func);
+
+       return ret;
 }