Revision: 44805
          http://brlcad.svn.sourceforge.net/brlcad/?rev=44805&view=rev
Author:   erikgreenwald
Date:     2011-06-07 20:40:33 +0000 (Tue, 07 Jun 2011)

Log Message:
-----------
add/use dlfcn wrapper

Modified Paths:
--------------
    brlcad/trunk/include/bu.h
    brlcad/trunk/src/adrt/librender/camera.c
    brlcad/trunk/src/libbu/CMakeLists.txt
    brlcad/trunk/src/libbu/Makefile.am
    brlcad/trunk/src/liboptical/material.c

Added Paths:
-----------
    brlcad/trunk/src/libbu/dlfcn.c

Modified: brlcad/trunk/include/bu.h
===================================================================
--- brlcad/trunk/include/bu.h   2011-06-07 20:10:49 UTC (rev 44804)
+++ brlcad/trunk/include/bu.h   2011-06-07 20:40:33 UTC (rev 44805)
@@ -6248,7 +6248,30 @@
 
 /** @} */
 
+/** @addtogroup file */
+/** @{ */
+/** @file dlfcn.c
+ * Dynamic Library functionality
+ */
+#ifdef HAVE_DLOPEN
+# define BU_RTLD_LAZY RTLD_LAZY
+# define BU_RTLD_NOW RTLD_NOW
+# define BU_RTLD_GLOBAL RTLD_GLOBAL
+# define BU_RTLD_LOCAL RTLD_LOCAL
+#else
+# define BU_RTLD_LAZY 1
+# define BU_RTLD_NOW 2
+# define BU_RTLD_GLOBAL 0x100
+# define BU_RTLD_LOCAL 0
+#endif
+BU_EXPORT BU_EXTERN(void *bu_dlopen, (const char *path, int mode));
+BU_EXPORT BU_EXTERN(void *bu_dlsym, (void *path, const char *symbol));
+BU_EXPORT BU_EXTERN(int bu_dlclose, (void *handle));
+BU_EXPORT BU_EXTERN(const char *bu_dlerror, ());
 
+/** @} */
+
+
 __END_DECLS
 
 #endif  /* __BU_H__ */

Modified: brlcad/trunk/src/adrt/librender/camera.c
===================================================================
--- brlcad/trunk/src/adrt/librender/camera.c    2011-06-07 20:10:49 UTC (rev 
44804)
+++ brlcad/trunk/src/adrt/librender/camera.c    2011-06-07 20:40:33 UTC (rev 
44805)
@@ -617,13 +617,13 @@
     char *name;
     struct render_shader_s *s;
 
-    lh = dlopen(filename, RTLD_LOCAL|RTLD_LAZY);
+    lh = bu_dlopen(filename, RTLD_LOCAL|RTLD_LAZY);
 
-    if(lh == NULL) { bu_log("Faulty plugin %s: %s\n", filename, dlerror()); 
return NULL; }
-    name = dlsym(lh, "name");
+    if(lh == NULL) { bu_log("Faulty plugin %s: %s\n", filename, bu_dlerror()); 
return NULL; }
+    name = bu_dlsym(lh, "name");
     if(name == NULL) { bu_log("Faulty plugin %s: No name\n", filename); return 
NULL; }
     /* assumes function pointers can be stored as a number, which ISO C does 
not guarantee */
-    init = (int (*) (render_t *, const char *))(intptr_t)dlsym(lh, "init");
+    init = (int (*) (render_t *, const char *))(intptr_t)bu_dlsym(lh, "init");
     if(init == NULL) { bu_log("Faulty plugin %s: No init\n", filename); return 
NULL; }
     s = render_shader_register(name, init);
     s->dlh = lh;
@@ -653,7 +653,7 @@
 LOADED:
 
        if(s->dlh)
-           dlclose(s->dlh);
+           bu_dlclose(s->dlh);
        bu_free(s, "unload first shader");
        shaders = t;
        return 0;
@@ -664,7 +664,7 @@
            if(r)
                render_shader_init(r, s->name, NULL);
            if(s->next->dlh)
-               dlclose(s->next->dlh);
+               bu_dlclose(s->next->dlh);
            t = s->next;
            s->next = s->next->next;
            bu_free(t, "unload shader");

Modified: brlcad/trunk/src/libbu/CMakeLists.txt
===================================================================
--- brlcad/trunk/src/libbu/CMakeLists.txt       2011-06-07 20:10:49 UTC (rev 
44804)
+++ brlcad/trunk/src/libbu/CMakeLists.txt       2011-06-07 20:40:33 UTC (rev 
44805)
@@ -12,7 +12,7 @@
     basename.c
     bitv.c
     bomb.c
-        booleanize.c
+    booleanize.c
     brlcad_path.c
     cmd.c
     cmdhist.c
@@ -22,6 +22,7 @@
     crashreport.c
     dirent.c
     dirname.c
+    dlfcn.c
     endian.c
     fchmod.c
     fgets.c

Modified: brlcad/trunk/src/libbu/Makefile.am
===================================================================
--- brlcad/trunk/src/libbu/Makefile.am  2011-06-07 20:10:49 UTC (rev 44804)
+++ brlcad/trunk/src/libbu/Makefile.am  2011-06-07 20:40:33 UTC (rev 44805)
@@ -22,6 +22,7 @@
        crashreport.c \
        dirent.c \
        dirname.c \
+       dlfcn.c \
        endian.c \
        fchmod.c \
        fgets.c \

Added: brlcad/trunk/src/libbu/dlfcn.c
===================================================================
--- brlcad/trunk/src/libbu/dlfcn.c                              (rev 0)
+++ brlcad/trunk/src/libbu/dlfcn.c      2011-06-07 20:40:33 UTC (rev 44805)
@@ -0,0 +1,88 @@
+/*                        D L F C N . C
+ * BRL-CAD
+ *
+ * Copyright (c) 2004-2011 United States Government as represented by
+ * the U.S. Army Research Laboratory.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this file; see the file named COPYING for more
+ * information.
+ */
+
+#include "common.h"
+
+#include <stdio.h>
+#include <string.h>
+
+#ifdef HAVE_DLFCN_H
+# include <dlfcn.h>
+/* this should not be needed. Maybe an explicit cmake test? */
+# ifndef HAVE_DLOPEN
+#  define HAVE_DLOPEN 1
+# endif
+#endif
+
+#include "bu.h"
+
+void *
+bu_dlopen(const char *path, int mode)
+{
+#ifdef HAVE_DLOPEN
+    return dlopen(path, mode);
+#else
+    bu_log("dlopen not supported\n");
+    return NULL;
+#endif
+}
+
+void *
+bu_dlsym(void *handle, const char *symbol)
+{
+#ifdef HAVE_DLOPEN
+    return dlsym(handle, symbol);
+#else
+    bu_log("dlsym not supported\n");
+    return NULL;
+#endif
+}
+
+int
+bu_dlclose(void *handle)
+{
+#ifdef HAVE_DLOPEN
+    return dlclose(handle);
+#else
+    bu_log("dlclose not supported\n");
+    return 0;
+#endif
+}
+
+const char *
+bu_dlerror(void)
+{
+#ifdef HAVE_DLOPEN
+    return dlerror();
+#else
+    bu_log("dlerror not supported\n");
+    return NULL;
+#endif
+}
+
+/*
+ * Local Variables:
+ * mode: C
+ * tab-width: 8
+ * indent-tabs-mode: t
+ * c-file-style: "stroustrup"
+ * End:
+ * ex: shiftwidth=4 tabstop=8
+ */


Property changes on: brlcad/trunk/src/libbu/dlfcn.c
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:eol-style
   + native

Modified: brlcad/trunk/src/liboptical/material.c
===================================================================
--- brlcad/trunk/src/liboptical/material.c      2011-06-07 20:10:49 UTC (rev 
44804)
+++ brlcad/trunk/src/liboptical/material.c      2011-06-07 20:40:33 UTC (rev 
44805)
@@ -80,9 +80,9 @@
     const char *dl_error_str;
     char sym[MAXPATHLEN];
 
-    if (! (handle = dlopen(path, RTLD_NOW))) {
+    if (! (handle = bu_dlopen(path, BU_RTLD_NOW))) {
        if (R_DEBUG&RDEBUG_MATERIAL)
-           bu_log("dlopen failed on \"%s\"\n", path);
+           bu_log("bu_dlopen failed on \"%s\"\n", path);
        return (struct mfuncs *)NULL;
     } else if (R_DEBUG&RDEBUG_MATERIAL) {
        bu_log("%s open... ", path);
@@ -90,18 +90,18 @@
 
     /* Find the {shader}_mfuncs symbol in the library */
     snprintf(sym, MAXPATHLEN, "%s_mfuncs", shader_name);
-    shader_mfuncs = dlsym(handle, sym);
-    if ((dl_error_str=dlerror()) == (char *)NULL) goto found;
+    shader_mfuncs = bu_dlsym(handle, sym);
+    if ((dl_error_str=bu_dlerror()) == (char *)NULL) goto found;
 
 
     /* We didn't find a {shader}_mfuncs symbol, so
      * try the generic "shader_mfuncs" symbol.
      */
-    shader_mfuncs = dlsym(handle, "shader_mfuncs");
-    if ((dl_error_str=dlerror()) != (char *)NULL) {
+    shader_mfuncs = bu_dlsym(handle, "shader_mfuncs");
+    if ((dl_error_str=bu_dlerror()) != (char *)NULL) {
        /* didn't find anything appropriate, give up */
        if (R_DEBUG&RDEBUG_MATERIAL) bu_log("%s has no %s table, %s\n", 
material, sym, dl_error_str);
-       dlclose(handle);
+       bu_dlclose(handle);
        return (struct mfuncs *)NULL;
     }
 
@@ -120,7 +120,7 @@
     if (R_DEBUG&RDEBUG_MATERIAL) bu_log("shader '%s' not found in library\n", 
shader_name);
 
     /* found the library, but not the shader */
-    dlclose(handle);
+    bu_dlclose(handle);
     return (struct mfuncs *)NULL;
 }
 


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
EditLive Enterprise is the world's most technically advanced content
authoring tool. Experience the power of Track Changes, Inline Image
Editing and ensure content is compliant with Accessibility Checking.
http://p.sf.net/sfu/ephox-dev2dev
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to