va: generate __vaDriverInit_*() function name at run-time. 52/852/1
authorGwenole Beauchesne <gwenole.beauchesne@intel.com>
Tue, 18 Oct 2011 12:25:52 +0000 (14:25 +0200)
committerGwenole Beauchesne <gwenole.beauchesne@intel.com>
Tue, 18 Oct 2011 12:26:37 +0000 (14:26 +0200)
Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
configure.ac
va/va.c

index e618337..00b047b 100644 (file)
@@ -125,14 +125,6 @@ AM_CONDITIONAL(USE_GLX, test "$USE_GLX" = "yes")
 USE_EGL="yes"
 AM_CONDITIONAL(USE_EGL, test "$USE_EGL" = "yes")
 
-
-# Make sure drivers use the correctly versioned __vaDriverInit*() function name
-VA_DRIVER_INIT_FUNC="__vaDriverInit_${LIBVA_MAJOR_VERSION}_${LIBVA_MINOR_VERSION}"
-AC_DEFINE_UNQUOTED([VA_DRIVER_INIT_FUNC], [$VA_DRIVER_INIT_FUNC],
-    [Defined to the versioned __vaDriverInit function name])
-AC_DEFINE_UNQUOTED([VA_DRIVER_INIT_FUNC_S], ["$VA_DRIVER_INIT_FUNC"],
-    [Defined to the versioned __vaDriverInit function name (in string form)])
-
 # We only need the headers, we don't link against the DRM libraries
 LIBVA_CFLAGS="$DRM_CFLAGS"
 AC_SUBST(LIBVA_CFLAGS)
diff --git a/va/va.c b/va/va.c
index 450b88f..aab00f0 100644 (file)
--- a/va/va.c
+++ b/va/va.c
@@ -149,6 +149,13 @@ static Bool va_checkString(const char* value, char *variable)
     return True;
 }
 
+static inline int
+va_getDriverInitName(char *name, int namelen, int major, int minor)
+{
+    int ret = snprintf(name, namelen, "__vaDriverInit_%d_%d", major, minor);
+    return ret > 0 && ret < namelen;
+}
+
 static VAStatus va_getDriverName(VADisplay dpy, char **driver_name)
 {
     VADisplayContextP pDisplayContext = (VADisplayContextP)dpy;
@@ -193,10 +200,14 @@ static VAStatus va_openDriver(VADisplay dpy, char *driver_name)
             if (0 == access( driver_path, F_OK))
                 va_errorMessage("dlopen of %s failed: %s\n", driver_path, dlerror());
         } else {
-            VADriverInit init_func;
-            init_func = (VADriverInit) dlsym(handle, VA_DRIVER_INIT_FUNC_S);
+            VADriverInit init_func = NULL;
+            char init_func_s[256];
+            if (va_getDriverInitName(init_func_s, sizeof(init_func_s),
+                                     VA_MAJOR_VERSION, VA_MINOR_VERSION))
+                init_func = (VADriverInit) dlsym(handle, init_func_s);
             if (!init_func) {
-                va_errorMessage("%s has no function %s\n", driver_path, VA_DRIVER_INIT_FUNC_S);
+                va_errorMessage("%s has no function %s\n",
+                                driver_path, init_func_s);
                 dlclose(handle);
             } else {
                 struct VADriverVTable *vtable = ctx->vtable;