[clinfo] 24/36: More separator stuff

Andreas Beckmann anbe at moszumanska.debian.org
Wed Feb 17 18:32:38 UTC 2016


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

anbe pushed a commit to branch master
in repository clinfo.

commit 15a2cc8b0be8075797043bc32a8a8d849a338d07
Author: Giuseppe Bilotta <giuseppe.bilotta at gmail.com>
Date:   Wed Dec 9 22:58:31 2015 +0100

    More separator stuff
---
 src/clinfo.c | 23 +++++++++--------------
 src/strbuf.h | 16 ++++++++++------
 2 files changed, 19 insertions(+), 20 deletions(-)

diff --git a/src/clinfo.c b/src/clinfo.c
index 64d59d4..57b77c1 100644
--- a/src/clinfo.c
+++ b/src/clinfo.c
@@ -1204,8 +1204,7 @@ int device_info_partition_types(cl_device_id dev, cl_device_info param, const ch
 				slen = strlen(ptstr[str_idx]);
 				if (output_mode == CLINFO_RAW && str_idx > 1)
 					slen -= 4;
-				strncpy(strbuf + szval, ptstr[str_idx], slen);
-				szval += slen;
+				szval += bufcpy_len(szval, ptstr[str_idx], slen);
 			}
 			if (szval >= bufsz) {
 				trunc_strbuf();
@@ -1411,9 +1410,9 @@ int device_info_fpconf(cl_device_id dev, cl_device_info param, const char *pname
 	if (!had_error) {
 		size_t szval = 0;
 		cl_uint i = 0;
-		const char *sep = vbar_str;
 		const char * const *fpstr = (output_mode == CLINFO_HUMAN ?
 			fp_conf_str : fp_conf_raw_str);
+		set_separator(vbar_str);
 		if (output_mode == CLINFO_HUMAN) {
 			const char *why = na;
 			switch (param) {
@@ -1443,8 +1442,7 @@ int device_info_fpconf(cl_device_id dev, cl_device_info param, const char *pname
 					szval += sprintf(strbuf + szval, "\n%s" I2_STR "%s",
 						line_pfx, fpstr[i], bool_str[!!(val & cur)]);
 				} else if (val & cur) {
-					if (szval > 0)
-						szval += bufcpy(szval, sep);
+					add_separator(&szval);
 					szval += bufcpy(szval, fpstr[i]);
 				}
 			}
@@ -1466,17 +1464,16 @@ int device_info_qprop(cl_device_id dev, cl_device_info param, const char *pname,
 	if (!had_error) {
 		size_t szval = 0;
 		cl_uint i = 0;
-		const char *sep = vbar_str;
 		const char * const *qpstr = (output_mode == CLINFO_HUMAN ?
 			queue_prop_str : queue_prop_raw_str);
+		set_separator(vbar_str);
 		for (i = 0; i < queue_prop_count; ++i) {
 			cl_command_queue_properties cur = (cl_command_queue_properties)(1) << i;
 			if (output_mode == CLINFO_HUMAN) {
 				szval += sprintf(strbuf + szval, "\n%s" I2_STR "%s",
 					line_pfx, qpstr[i], bool_str[!!(val & cur)]);
 			} else if (val & cur) {
-				if (szval > 0)
-					szval += bufcpy(szval, sep);
+				add_separator(&szval);
 				szval += bufcpy(szval, qpstr[i]);
 			}
 		}
@@ -1498,17 +1495,16 @@ int device_info_execap(cl_device_id dev, cl_device_info param, const char *pname
 	if (!had_error) {
 		size_t szval = 0;
 		cl_uint i = 0;
-		const char *sep = vbar_str;
 		const char * const *qpstr = (output_mode == CLINFO_HUMAN ?
 			execap_str : execap_raw_str);
+		set_separator(vbar_str);
 		for (i = 0; i < execap_count; ++i) {
 			cl_device_exec_capabilities cur = (cl_device_exec_capabilities)(1) << i;
 			if (output_mode == CLINFO_HUMAN) {
 				szval += sprintf(strbuf + szval, "\n%s" I2_STR "%s",
 					line_pfx, qpstr[i], bool_str[!!(val & cur)]);
 			} else if (val & cur) {
-				if (szval > 0)
-					szval += bufcpy(szval, sep);
+				add_separator(&szval);
 				szval += bufcpy(szval, qpstr[i]);
 			}
 		}
@@ -1553,9 +1549,9 @@ int device_info_svm_cap(cl_device_id dev, cl_device_info param, const char *pnam
 	if (!had_error) {
 		size_t szval = 0;
 		cl_uint i = 0;
-		const char *sep = vbar_str;
 		const char * const *scstr = (output_mode == CLINFO_HUMAN ?
 			svm_cap_str : svm_cap_raw_str);
+		set_separator(vbar_str);
 		if (output_mode == CLINFO_HUMAN) {
 			/* show 'why' it's being shown */
 			szval += sprintf(strbuf, "(%s%s%s)",
@@ -1569,8 +1565,7 @@ int device_info_svm_cap(cl_device_id dev, cl_device_info param, const char *pnam
 				szval += sprintf(strbuf + szval, "\n%s" I2_STR "%s",
 					line_pfx, scstr[i], bool_str[!!(val & cur)]);
 			} else if (val & cur) {
-				if (szval > 0)
-					szval += bufcpy(szval, sep);
+				add_separator(&szval);
 				szval += bufcpy(szval, scstr[i]);
 			}
 		}
diff --git a/src/strbuf.h b/src/strbuf.h
index c2f44c7..8fc112f 100644
--- a/src/strbuf.h
+++ b/src/strbuf.h
@@ -41,9 +41,8 @@ static void trunc_strbuf(void)
  * returning the amount of bytes written (excluding the
  * closing NULL byte)
  */
-static inline size_t bufcpy(size_t offset, const char *str)
+static inline size_t bufcpy_len(size_t offset, const char *str, size_t len)
 {
-	size_t len = strlen(str);
 	size_t maxlen = bufsz - offset - 1;
 	char *dst = strbuf + offset;
 	int trunc = 0;
@@ -67,6 +66,13 @@ static inline size_t bufcpy(size_t offset, const char *str)
 	return len;
 }
 
+/* As above, auto-compute string length */
+static inline size_t bufcpy(size_t offset, const char *str)
+{
+	return bufcpy_len(offset, str, strlen(str));
+}
+
+
 /* Separators: we want to be able to prepend separators as needed to strbuf,
  * which we do only if halfway through the buffer. The callers should first
  * call a 'set_separator' and then use add_separator(&offset) to add it, where szval
@@ -85,8 +91,6 @@ void set_separator(const char* _sep)
 /* Note that no overflow check is done: it is assumed that strbuf will have enough room */
 void add_separator(size_t *offset)
 {
-	if (*offset) {
-		memcpy(strbuf + *offset, sep, sepsz);
-		*offset += sepsz;
-	}
+	if (*offset)
+		*offset += bufcpy_len(*offset, sep, sepsz);
 }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-opencl/clinfo.git



More information about the Pkg-opencl-commits mailing list