Hi,

The fix patch changes cl_uint to cl_device_type in Device class, it
fix some tests errors and the second one fix a segfault in context
creation and implement some errors messages.

Igor
From 6ea02fdfe3e69bafcfa04e693dfd2469b3b76386 Mon Sep 17 00:00:00 2001
From: Igor Oliveira <igor.olive...@openbossa.org>
Date: Tue, 5 Jan 2010 11:19:13 -0400
Subject: [PATCH 1/2] fix Device::type type, change cl_uint by cl_device_type and fix return information

---
 src/core/device.cpp |   21 +++++++++++++--------
 src/core/device.h   |   10 +++++-----
 2 files changed, 18 insertions(+), 13 deletions(-)

diff --git a/src/core/device.cpp b/src/core/device.cpp
index 20e6f2b..6c7e7d5 100644
--- a/src/core/device.cpp
+++ b/src/core/device.cpp
@@ -11,7 +11,7 @@
 #include "softpipe/sp_winsys.h"
 
 
-Device * Device::create(cl_uint type)
+Device * Device::create(cl_device_type type)
 {
    switch(type) {
    case CL_DEVICE_TYPE_CPU: {
@@ -54,15 +54,16 @@ cl_int Device::info(cl_device_info opcode,
                     void * paramValue,
                     size_t * paramValueSizeRet) const
 {
+   size_t sizeRet = 0;
+
    if (!paramValue)
        return CL_SUCCESS;
 
    switch (opcode) {
    case CL_DEVICE_TYPE:
-      if (paramValueSizeRet)
-         *paramValueSizeRet = sizeof(type());
 
-      ((cl_int*)paramValue)[0] = type();
+      sizeRet = sizeof(type());
+      ((cl_device_type*)paramValue)[0] = type();
       break;
    case CL_DEVICE_VENDOR_ID:
       break;
@@ -168,19 +169,23 @@ cl_int Device::info(cl_device_info opcode,
       break;
    }
 
-   if (paramValueSizeRet && paramValueSize != *paramValueSizeRet)
-      return CL_INVALID_VALUE;
+   if (paramValueSizeRet)
+      *paramValueSizeRet = sizeRet;
+
+   if (paramValueSize != sizeRet) {
+       return CL_INVALID_VALUE;
+   }
 
    return CL_SUCCESS;
 }
 
-Device::Device(cl_uint type, struct pipe_screen *screen)
+Device::Device(cl_device_type type, struct pipe_screen *screen)
    : m_screen(screen)
 {
    fillInfo(type);
 }
 
-void Device::fillInfo(cl_uint type)
+void Device::fillInfo(cl_device_type type)
 {
    m_info.type = type;
    m_info.vendorId = 0;//should be a PCIe ID
diff --git a/src/core/device.h b/src/core/device.h
index 5a3d43f..5ba0a43 100644
--- a/src/core/device.h
+++ b/src/core/device.h
@@ -11,9 +11,9 @@ struct pipe_screen;
 class Device
 {
 public:
-   static Device *create(cl_uint type);
+   static Device *create(cl_device_type type);
 public:
-   inline cl_uint type() const;
+   inline cl_device_type type() const;
    inline struct pipe_screen *screen() const;
 
    cl_int info(cl_device_info  opcode,
@@ -22,8 +22,8 @@ public:
                size_t *        paramValueSizeRet) const;
 
 private:
-   Device(cl_uint type, struct pipe_screen *screen);
-   void fillInfo(cl_uint type);
+   Device(cl_device_type type, struct pipe_screen *screen);
+   void fillInfo(cl_device_type type);
 
 private:
    DeviceInfo m_info;
@@ -31,7 +31,7 @@ private:
    struct pipe_screen *m_screen;
 };
 
-inline cl_uint Device::type() const
+inline cl_device_type Device::type() const
 {
    return m_info.type;
 }
-- 
1.6.3.3

From cdb70b3ee991304db3888a710d1c43817dfb4841 Mon Sep 17 00:00:00 2001
From: Igor Oliveira <igor.olive...@openbossa.org>
Date: Tue, 5 Jan 2010 11:23:25 -0400
Subject: [PATCH 2/2] context: fix segfault and returns

---
 src/api/api_context.cpp |   17 ++++++++++++++---
 1 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/src/api/api_context.cpp b/src/api/api_context.cpp
index 8393dcb..1703fde 100644
--- a/src/api/api_context.cpp
+++ b/src/api/api_context.cpp
@@ -16,15 +16,26 @@ clCreateContext(cl_context_properties   properties,
 {
     cl_context ret_context = NULL;
     cl_device_type type;
-    cl_device_id device = devices[0];
+    cl_device_id device = devices?devices[0]:NULL;
     cl_int device_info;
 
+    if (num_devices <= 0) {
+       if (errcode_ret)
+          *errcode_ret = CL_INVALID_VALUE;
+       goto fail;
+    }
+
     device_info = clGetDeviceInfo(device, CL_DEVICE_TYPE, sizeof(type), &type, NULL);
-    if (device_info != CL_INVALID_DEVICE) {
+    if (device_info == CL_SUCCESS) {
         ret_context =  clCreateContextFromType(properties, type,
                 pfn_notify, user_data, errcode_ret);
+    } else {
+       if (device_info == CL_INVALID_DEVICE) {
+          if (errcode_ret)
+             *errcode_ret = CL_INVALID_VALUE;
+       }
     }
-
+fail:
     return ret_context;
 }
 
-- 
1.6.3.3

------------------------------------------------------------------------------
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev 
_______________________________________________
Mesa3d-dev mailing list
Mesa3d-dev@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mesa3d-dev

Reply via email to