[gegl] opencl: Fill in the GError when an error occurs



commit 586deb663056f2245bcb51c1886ff917da8da9d2
Author: Daniel Sabo <DanielSabo gmail com>
Date:   Tue Oct 1 01:19:52 2013 -0700

    opencl: Fill in the GError when an error occurs

 gegl/opencl/gegl-cl-init.c |   30 ++++++++++++++++++++++++------
 1 files changed, 24 insertions(+), 6 deletions(-)
---
diff --git a/gegl/opencl/gegl-cl-init.c b/gegl/opencl/gegl-cl-init.c
index 5ab3df0..e53eac0 100644
--- a/gegl/opencl/gegl-cl-init.c
+++ b/gegl/opencl/gegl-cl-init.c
@@ -27,6 +27,7 @@
 #include "gegl-cl-init.h"
 #undef __GEGL_CL_INIT_MAIN__
 
+#include <glib.h>
 #include <gmodule.h>
 #include <string.h>
 #include <stdio.h>
@@ -36,6 +37,16 @@
 #include "gegl/gegl-debug.h"
 #include "gegl-config.h"
 
+GQuark gegl_opencl_error_quark (void);
+
+GQuark
+gegl_opencl_error_quark (void)
+{
+  return g_quark_from_static_string ("gegl-opencl-error-quark");
+}
+
+#define GEGL_OPENCL_ERROR (gegl_opencl_error_quark ())
+
 const char *gegl_cl_errstring(cl_int err) {
   static const char* strings[] =
   {
@@ -199,7 +210,7 @@ gegl_cl_get_iter_height (void)
 #define CL_LOAD_FUNCTION(func)                                                    \
 if ((gegl_##func = (t_##func) GetProcAddress(module, #func)) == NULL)             \
   {                                                                               \
-    g_set_error (error, 0, 0, "symbol gegl_##func is NULL");                      \
+    g_set_error (error, GEGL_OPENCL_ERROR, 0, "symbol gegl_##func is NULL");      \
     FreeLibrary(module);                                                          \
     return FALSE;                                                                 \
   }
@@ -215,16 +226,18 @@ if ((gegl_##func = (t_##func) GetProcAddress(module, #func)) == NULL)
 #define CL_LOAD_FUNCTION(func)                                                    \
 if (!g_module_symbol (module, #func, (gpointer *)& gegl_##func))                  \
   {                                                                               \
-    GEGL_NOTE (GEGL_DEBUG_OPENCL, "%s: %s", CL_LIBRARY_NAME, g_module_error ());   \
+    GEGL_NOTE (GEGL_DEBUG_OPENCL, "%s: %s", CL_LIBRARY_NAME, g_module_error ());  \
+    g_set_error (error, GEGL_OPENCL_ERROR, 0, "%s: %s", CL_LIBRARY_NAME, g_module_error ()); \
     if (!g_module_close (module))                                                 \
-      g_warning ("%s: %s", CL_LIBRARY_NAME, g_module_error ());                    \
+      g_warning ("%s: %s", CL_LIBRARY_NAME, g_module_error ());                   \
     return FALSE;                                                                 \
   }                                                                               \
 if (gegl_##func == NULL)                                                          \
   {                                                                               \
     GEGL_NOTE (GEGL_DEBUG_OPENCL, "symbol gegl_##func is NULL");                  \
+    g_set_error (error, GEGL_OPENCL_ERROR, 0, "symbol gegl_##func is NULL");      \
     if (!g_module_close (module))                                                 \
-      g_warning ("%s: %s", CL_LIBRARY_NAME, g_module_error ());                    \
+      g_warning ("%s: %s", CL_LIBRARY_NAME, g_module_error ());                   \
     return FALSE;                                                                 \
   }
 
@@ -252,6 +265,7 @@ gegl_cl_init (GError **error)
       if (!module)
         {
           GEGL_NOTE (GEGL_DEBUG_OPENCL, "Unable to load OpenCL library");
+          g_set_error (error, GEGL_OPENCL_ERROR, 0, "Unable to load OpenCL library");
           return FALSE;
         }
 
@@ -305,6 +319,7 @@ gegl_cl_init (GError **error)
       if(err != CL_SUCCESS)
         {
           GEGL_NOTE (GEGL_DEBUG_OPENCL, "Could not create platform");
+          g_set_error (error, GEGL_OPENCL_ERROR, 0, "Could not create platform");
           return FALSE;
         }
 
@@ -315,8 +330,8 @@ gegl_cl_init (GError **error)
       err = gegl_clGetDeviceIDs (cl_state.platform, CL_DEVICE_TYPE_DEFAULT, 1, &cl_state.device, NULL);
       if(err != CL_SUCCESS)
         {
-          GEGL_NOTE (GEGL_DEBUG_OPENCL, "Error: %s", gegl_cl_errstring(err));
-          GEGL_NOTE (GEGL_DEBUG_OPENCL, "Could not create device");
+          GEGL_NOTE (GEGL_DEBUG_OPENCL, "Could not create device: %s", gegl_cl_errstring(err));
+          g_set_error (error, GEGL_OPENCL_ERROR, 0, "Could not create device: %s", gegl_cl_errstring(err));
           return FALSE;
         }
 
@@ -356,6 +371,7 @@ gegl_cl_init (GError **error)
       else
         {
           GEGL_NOTE (GEGL_DEBUG_OPENCL, "Image Support Error");
+          g_set_error (error, GEGL_OPENCL_ERROR, 0, "Image Support Error");
           return FALSE;
         }
 
@@ -363,6 +379,7 @@ gegl_cl_init (GError **error)
       if(err != CL_SUCCESS)
         {
           GEGL_NOTE (GEGL_DEBUG_OPENCL, "Could not create context");
+          g_set_error (error, GEGL_OPENCL_ERROR, 0, "Could not create context");
           return FALSE;
         }
 
@@ -371,6 +388,7 @@ gegl_cl_init (GError **error)
       if(err != CL_SUCCESS)
         {
           GEGL_NOTE (GEGL_DEBUG_OPENCL, "Could not create command queue");
+          g_set_error (error, GEGL_OPENCL_ERROR, 0, "Could not create command queue");
           return FALSE;
         }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]