[gegl/gsoc2011-opencl: 6/14] Now using gmodule instead of dlopen
- From: Victor Matheus de Araujo Oliveira <vmaolive src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gegl/gsoc2011-opencl: 6/14] Now using gmodule instead of dlopen
- Date: Fri, 20 May 2011 14:22:43 +0000 (UTC)
commit 520dad39084bd846530d8769fd3479b9d5763d19
Author: Victor Matheus de A. Oliveira <victormatheus gmail com>
Date: Sat May 14 00:54:50 2011 -0300
Now using gmodule instead of dlopen
Signed-off-by: Victor Oliveira <victormatheus gmail com>
configure.ac | 2 +-
gegl/opencl/gegl-cl-init.c | 45 ++++++++++++++++++++++++++-----------------
gegl/opencl/gegl-cl-init.h | 3 +-
operations/common/over.c | 2 +-
4 files changed, 31 insertions(+), 21 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 10f65a7..82325ce 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1026,7 +1026,7 @@ AC_SUBST(UMFPACK_LIBS)
#######################
OPENCL_CFLAGS="$OPENCL_CFLAGS"
-OPENCL_LIBS="$OPENCL_LIBS -ldl"
+OPENCL_LIBS="$OPENCL_LIBS"
AC_SUBST(OPENCL_CFLAGS)
AC_SUBST(OPENCL_LIBS)
diff --git a/gegl/opencl/gegl-cl-init.c b/gegl/opencl/gegl-cl-init.c
index 873de27..fc878f5 100644
--- a/gegl/opencl/gegl-cl-init.c
+++ b/gegl/opencl/gegl-cl-init.c
@@ -2,7 +2,7 @@
#include "gegl-cl-init.h"
#undef __GEGL_CL_INIT_MAIN__
-#include <dlfcn.h>
+#include <gmodule.h>
#include <stdio.h>
static gboolean cl_is_accelerated = FALSE;
@@ -13,33 +13,42 @@ gegl_cl_is_accelerated (void)
return cl_is_accelerated;
}
-#define CL_LOAD_FUNCTION(func) \
-gegl_##func = (t_##func) dlsym(handle, #func); \
- \
-dlsym_error = dlerror(); \
-if (dlsym_error) \
- { \
- fprintf(stderr, "Cannot load symbol" #func ": %s\n", dlsym_error); \
- dlclose(handle); \
- return; \
+#define CL_LOAD_FUNCTION(func) \
+if (!g_module_symbol (module, #func, (gpointer *)& gegl_##func)) \
+ { \
+ g_set_error (error, 0, 0, \
+ "%s: %s", "libOpenCL.so", g_module_error ()); \
+ if (!g_module_close (module)) \
+ g_warning ("%s: %s", "libOpenCL.so", g_module_error ()); \
+ return FALSE; \
+ } \
+if (gegl_##func == NULL) \
+ { \
+ g_set_error (error, 0, 0, "symbol gegl_##func is NULL"); \
+ if (!g_module_close (module)) \
+ g_warning ("%s: %s", "libOpenCL.so", g_module_error ()); \
+ return FALSE; \
}
-void gegl_cl_init (void)
+gboolean
+gegl_cl_init (GError **error)
{
- void* handle = dlopen("libOpenCL.so", RTLD_LAZY);
- const char *dlsym_error;
+ GModule *module;
+ module = g_module_open ("libOpenCL.so", G_MODULE_BIND_LAZY);
- if (!handle) {
- fprintf(stderr, "Cannot open library: %s\n", dlerror());
- return;
- }
+ if (!module)
+ {
+ g_set_error (error, 0, 0,
+ "%s", g_module_error ());
+ return FALSE;
+ }
CL_LOAD_FUNCTION (clGetPlatformIDs)
CL_LOAD_FUNCTION (clGetPlatformInfo)
cl_is_accelerated = TRUE;
- return;
+ return TRUE;
}
#undef CL_LOAD_FUNCTION
diff --git a/gegl/opencl/gegl-cl-init.h b/gegl/opencl/gegl-cl-init.h
index 733d596..9dc0aba 100644
--- a/gegl/opencl/gegl-cl-init.h
+++ b/gegl/opencl/gegl-cl-init.h
@@ -2,8 +2,9 @@
#define __GEGL_CL_INIT_H__
#include "gegl-cl-types.h"
+#include <gmodule.h>
-void gegl_cl_init (void);
+gboolean gegl_cl_init (GError **error);
gboolean gegl_cl_is_accelerated (void);
diff --git a/operations/common/over.c b/operations/common/over.c
index 2356b15..85a7c85 100644
--- a/operations/common/over.c
+++ b/operations/common/over.c
@@ -51,7 +51,7 @@ cl_process (GeglOperation *op,
glong n_pixels,
const GeglRectangle *roi)
{
- gegl_cl_init();
+ gegl_cl_init(NULL);
char buffer[65536];
cl_int error;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]