[arrayfire] 72/284: Using af_alloc_host when allocating user-return string

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Sun Feb 7 18:59:20 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 1de97de812499e6b969e9e23e0e35306246b96f0
Author: Shehzan Mohammed <shehzan at arrayfire.com>
Date:   Mon Dec 14 17:33:06 2015 -0500

    Using af_alloc_host when allocating user-return string
---
 src/api/c/device.cpp     | 14 ++++++++------
 src/api/c/err_common.cpp |  5 +++--
 2 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/src/api/c/device.cpp b/src/api/c/device.cpp
index 365ccbe..84cd246 100644
--- a/src/api/c/device.cpp
+++ b/src/api/c/device.cpp
@@ -72,13 +72,15 @@ af_err af_info()
 
 af_err af_info_string(char **str, const bool verbose)
 {
-    std::string infoStr = getInfo();
-    *str = (char*)malloc(sizeof(char) * (infoStr.size() + 1));
+    try {
+        std::string infoStr = getInfo();
+        af_alloc_host((void**)str, sizeof(char) * (infoStr.size() + 1));
 
-    // Need to do a deep copy
-    // str.c_str wont cut it
-    infoStr.copy(*str, infoStr.size());
-    (*str)[infoStr.size()] = '\0';
+        // Need to do a deep copy
+        // str.c_str wont cut it
+        infoStr.copy(*str, infoStr.size());
+        (*str)[infoStr.size()] = '\0';
+    } CATCHALL;
 
     return AF_SUCCESS;
 }
diff --git a/src/api/c/err_common.cpp b/src/api/c/err_common.cpp
index 371bbd9..3271423 100644
--- a/src/api/c/err_common.cpp
+++ b/src/api/c/err_common.cpp
@@ -8,6 +8,7 @@
  ********************************************************/
 
 #include <af/exception.h>
+#include <af/device.h>
 #include <err_common.hpp>
 #include <type_util.hpp>
 #include <string>
@@ -156,8 +157,8 @@ void af_get_last_error(char **str, dim_t *len)
         *str = NULL;
     }
 
-    *str = new char[*len + 1];
-    memcpy(*str, global_err_string.c_str(), *len * sizeof(char));
+    af_alloc_host((void**)str, sizeof(char) * (*len + 1));
+    global_err_string.copy(*str, *len);
 
     (*str)[*len] = '\0';
     global_err_string = std::string("");

-- 
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