From 4c9aa86792078b0fce3bde1938ee2260b3209b25 Mon Sep 17 00:00:00 2001
From: Yichao Yu <yyc1992@gmail.com>
Date: Thu, 19 Jun 2014 14:43:42 +0800
Subject: [PATCH] print string

---
 src/c_wrapper/debug.cpp | 10 ++++++++++
 src/c_wrapper/debug.h   | 10 +++++++++-
 src/c_wrapper/error.h   |  1 -
 src/c_wrapper/utils.h   |  8 +++-----
 4 files changed, 22 insertions(+), 7 deletions(-)

diff --git a/src/c_wrapper/debug.cpp b/src/c_wrapper/debug.cpp
index 4dd17f9a..95cb8084 100644
--- a/src/c_wrapper/debug.cpp
+++ b/src/c_wrapper/debug.cpp
@@ -1,8 +1,18 @@
 #include "debug.h"
+#include <iostream>
 #include <stdlib.h>
 
 namespace pyopencl {
 
+void
+dbg_print_str(std::ostream &stm, const char *str, size_t len)
+{
+    // TODO escape
+    stm << '"';
+    stm.write(str, len);
+    stm << '"';
+}
+
 static PYOPENCL_INLINE bool
 _get_debug_env()
 {
diff --git a/src/c_wrapper/debug.h b/src/c_wrapper/debug.h
index cd4b0d7e..1b8c2ca7 100644
--- a/src/c_wrapper/debug.h
+++ b/src/c_wrapper/debug.h
@@ -1,5 +1,6 @@
 #include "wrap_cl.h"
-#include "utils.h"
+#include "function.h"
+#include <string.h>
 
 #ifndef __PYOPENCL_DEBUG_H
 #define __PYOPENCL_DEBUG_H
@@ -15,6 +16,13 @@ extern bool debug_enabled;
 
 #define DEBUG_ON (PYOPENCL_EXPECT(debug_enabled, DEFAULT_DEBUG))
 
+void dbg_print_str(std::ostream&, const char*, size_t);
+static PYOPENCL_INLINE void
+dbg_print_str(std::ostream &stm, const char *str)
+{
+    return dbg_print_str(stm, str, strlen(str));
+}
+
 }
 
 #endif
diff --git a/src/c_wrapper/error.h b/src/c_wrapper/error.h
index 5014ea87..d98e0b5a 100644
--- a/src/c_wrapper/error.h
+++ b/src/c_wrapper/error.h
@@ -1,7 +1,6 @@
 #include "wrap_cl.h"
 #include "pyhelper.h"
 #include "clobj.h"
-#include "debug.h"
 
 #include <string.h>
 #include <stdexcept>
diff --git a/src/c_wrapper/utils.h b/src/c_wrapper/utils.h
index f1b24740..c935b553 100644
--- a/src/c_wrapper/utils.h
+++ b/src/c_wrapper/utils.h
@@ -1,5 +1,6 @@
 #include "wrap_cl.h"
 #include "function.h"
+#include "debug.h"
 
 #include <string>
 #include <sstream>
@@ -83,10 +84,7 @@ template<>
 PYOPENCL_INLINE void
 _print_buf_content<char>(std::ostream &stm, const char *p, size_t len)
 {
-    // TODO escape
-    stm << '"';
-    stm.write(p, len);
-    stm << '"';
+    dbg_print_str(stm, p, len);
 }
 
 template<typename T>
@@ -164,7 +162,7 @@ struct CLGenericArgPrinter<
     static PYOPENCL_INLINE void
     print(std::ostream &stm, const char *str)
     {
-        _print_buf_content<char>(stm, str, strlen(str));
+        dbg_print_str(stm, str);
     }
 };
 
-- 
GitLab