[arrayfire] 187/284: Cleaning up exception handling in src/api/c

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Sun Feb 7 18:59:32 UTC 2016


This is an automated email from the git hooks/post-receive script.

ghisvail-guest pushed a commit to branch debian/experimental
in repository arrayfire.

commit 2f16824e77568bc83bb698280692e657ce565a1b
Author: Pavan Yalamanchili <pavan at arrayfire.com>
Date:   Sun Jan 10 03:22:38 2016 -0500

    Cleaning up exception handling in src/api/c
---
 src/api/c/assign.cpp |  4 ++--
 src/api/c/device.cpp | 18 ++++++++++++------
 src/api/c/flip.cpp   |  2 +-
 src/api/c/image.cpp  |  2 +-
 src/api/c/index.cpp  |  6 ++----
 5 files changed, 18 insertions(+), 14 deletions(-)

diff --git a/src/api/c/assign.cpp b/src/api/c/assign.cpp
index 50224d3..bf2c185 100644
--- a/src/api/c/assign.cpp
+++ b/src/api/c/assign.cpp
@@ -350,10 +350,10 @@ af_err af_assign_gen(af_array *out,
             throw;
         }
         if (is_vector) { AF_CHECK(af_release_array(rhs)); }
+
+        std::swap(*out, output);
     }
     CATCHALL;
 
-    std::swap(*out, output);
-
     return AF_SUCCESS;
 }
diff --git a/src/api/c/device.cpp b/src/api/c/device.cpp
index 8f33299..731e98e 100644
--- a/src/api/c/device.cpp
+++ b/src/api/c/device.cpp
@@ -39,7 +39,9 @@ af_err af_get_backend_count(unsigned* num_backends)
 
 af_err af_get_available_backends(int* result)
 {
-    *result = getBackend();
+    try {
+        *result = getBackend();
+    } CATCHALL;
     return AF_SUCCESS;
 }
 
@@ -67,7 +69,9 @@ af_err af_init()
 
 af_err af_info()
 {
-    printf("%s", getInfo().c_str());
+    try {
+        printf("%s", getInfo().c_str());
+    } CATCHALL;
     return AF_SUCCESS;
 }
 
@@ -326,7 +330,6 @@ af_err af_free_pinned(void *ptr)
 af_err af_alloc_host(void **ptr, const dim_t bytes)
 {
     try {
-        AF_CHECK(af_init());
         *ptr = malloc(bytes);
     } CATCHALL;
     return AF_SUCCESS;
@@ -335,7 +338,6 @@ af_err af_alloc_host(void **ptr, const dim_t bytes)
 af_err af_free_host(void *ptr)
 {
     try {
-        AF_CHECK(af_init());
         free(ptr);
     } CATCHALL;
     return AF_SUCCESS;
@@ -376,12 +378,16 @@ af_err af_device_mem_info(size_t *alloc_bytes, size_t *alloc_buffers,
 
 af_err af_set_mem_step_size(const size_t step_bytes)
 {
-    detail::setMemStepSize(step_bytes);
+    try{
+        detail::setMemStepSize(step_bytes);
+    } CATCHALL;
     return AF_SUCCESS;
 }
 
 af_err af_get_mem_step_size(size_t *step_bytes)
 {
-    *step_bytes =  detail::getMemStepSize();
+    try {
+        *step_bytes =  detail::getMemStepSize();
+    } CATCHALL;
     return AF_SUCCESS;
 }
diff --git a/src/api/c/flip.cpp b/src/api/c/flip.cpp
index 3d5bf53..09cbaf7 100644
--- a/src/api/c/flip.cpp
+++ b/src/api/c/flip.cpp
@@ -74,9 +74,9 @@ af_err af_flip(af_array *result, const af_array in, const unsigned dim)
         case u8:     out = flipArray<uchar>   (in, dim);  break;
         default:    TYPE_ERROR(1, in_type);
         }
+        swap(*result, out);
     }
     CATCHALL
 
-    swap(*result, out);
     return AF_SUCCESS;
 }
diff --git a/src/api/c/image.cpp b/src/api/c/image.cpp
index 1d3e097..db40934 100644
--- a/src/api/c/image.cpp
+++ b/src/api/c/image.cpp
@@ -141,9 +141,9 @@ af_err af_create_window(af_window *out, const int width, const int height, const
 
         wnd = new fg::Window(width, height, title, mainWnd);
         wnd->setFont(fgMngr.getFont());
+        *out = reinterpret_cast<af_window>(wnd);
     }
     CATCHALL;
-    *out = reinterpret_cast<af_window>(wnd);
     return AF_SUCCESS;
 #else
     AF_RETURN_ERROR("ArrayFire compiled without graphics support", AF_ERR_NO_GFX);
diff --git a/src/api/c/index.cpp b/src/api/c/index.cpp
index 2f5b06a..f5a214f 100644
--- a/src/api/c/index.cpp
+++ b/src/api/c/index.cpp
@@ -67,10 +67,10 @@ af_err af_index(af_array *result, const af_array in, const unsigned ndims, const
         case u8:     indexArray<uchar>   (out, in, ndims, index);  break;
         default:    TYPE_ERROR(1, in_type);
         }
+        swap(*result, out);
     }
     CATCHALL
 
-    swap(*result, out);
     return AF_SUCCESS;
 }
 
@@ -127,11 +127,9 @@ af_err af_lookup(af_array *out, const af_array in, const af_array indices, const
             case  u8: output = lookup<uchar   >(in, indices, dim); break;
             default : TYPE_ERROR(1, idxType);
         }
+        std::swap(*out, output);
     }
     CATCHALL;
-
-    std::swap(*out, output);
-
     return AF_SUCCESS;
 }
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/arrayfire.git



More information about the debian-science-commits mailing list