[clinfo] 15/55: GET_STRING2 macro to get strings
Andreas Beckmann
anbe at moszumanska.debian.org
Sat Jan 13 14:39:59 UTC 2018
This is an automated email from the git hooks/post-receive script.
anbe pushed a commit to branch master
in repository clinfo.
commit b56ccace72f7c084aed4513678ae86d6ddb52ed0
Author: Giuseppe Bilotta <giuseppe.bilotta at gmail.com>
Date: Thu Feb 9 15:28:30 2017 +0100
GET_STRING2 macro to get strings
Refactor the common "get size, resize, get value" idiom for string into
a GET_STRING2 macro. This is one of the last things that weren't
converted with the property table refactoring.
---
src/clinfo.c | 33 +++------------------------------
src/strbuf.h | 13 +++++++++++++
2 files changed, 16 insertions(+), 30 deletions(-)
diff --git a/src/clinfo.c b/src/clinfo.c
index 2909a0b..cf1b7ae 100644
--- a/src/clinfo.c
+++ b/src/clinfo.c
@@ -315,16 +315,7 @@ void show_strbuf(const char *pname, int skip)
int
platform_info_str(cl_platform_id pid, cl_platform_info param, const char* pname, const struct platform_info_checks * chk UNUSED)
{
- error = clGetPlatformInfo(pid, param, 0, NULL, &nusz);
- had_error = REPORT_ERROR2("get %s size");
- if (!had_error) {
- if (nusz > bufsz) {
- REALLOC(strbuf, nusz, current_param);
- bufsz = nusz;
- }
- error = clGetPlatformInfo(pid, param, bufsz, strbuf, NULL);
- had_error = REPORT_ERROR2("get %s");
- }
+ GET_STRING2(clGetPlatformInfo, pid, param);
/* when only listing, do not print anything we're just gathering
* information
*/
@@ -779,16 +770,7 @@ int device_info_str_get(cl_device_id dev, cl_device_info param, const char *pnam
const struct device_info_checks *chk UNUSED)
{
current_param = pname;
- error = clGetDeviceInfo(dev, param, 0, NULL, &nusz);
- had_error = REPORT_ERROR2("get %s size");
- if (!had_error) {
- if (nusz > bufsz) {
- REALLOC(strbuf, nusz, current_param);
- bufsz = nusz;
- }
- error = clGetDeviceInfo(dev, param, bufsz, strbuf, NULL);
- had_error = REPORT_ERROR2("get %s");
- }
+ GET_STRING2(clGetDeviceInfo, dev, param);
return had_error;
}
@@ -2530,16 +2512,7 @@ struct icd_loader_test {
int
icdl_info_str(cl_icdl_info param, const char* pname)
{
- error = clGetICDLoaderInfoOCLICD(param, 0, NULL, &nusz);
- had_error = REPORT_ERROR2("get %s size");
- if (!had_error) {
- if (nusz > bufsz) {
- REALLOC(strbuf, nusz, current_param);
- bufsz = nusz;
- }
- error = clGetICDLoaderInfoOCLICD(param, bufsz, strbuf, NULL);
- had_error = REPORT_ERROR2("get %s");
- }
+ GET_STRING2(clGetICDLoaderInfoOCLICD, param);
show_strbuf(pname, 1);
return had_error;
}
diff --git a/src/strbuf.h b/src/strbuf.h
index c936932..8304050 100644
--- a/src/strbuf.h
+++ b/src/strbuf.h
@@ -21,6 +21,19 @@ size_t bufsz, nusz;
REPORT_ERROR("get " param_str); \
} while (0)
+#define GET_STRING2(cmd, ...) do { \
+ error = cmd(__VA_ARGS__, 0, NULL, &nusz); \
+ had_error = REPORT_ERROR2("get %s size"); \
+ if (!had_error) { \
+ if (nusz > bufsz) { \
+ REALLOC(strbuf, nusz, current_param); \
+ bufsz = nusz; \
+ } \
+ error = cmd(__VA_ARGS__, bufsz, strbuf, NULL); \
+ had_error = REPORT_ERROR2("get %s"); \
+ } \
+} while (0)
+
/* Skip leading whitespace in a string */
static inline const char* skip_leading_ws(const char *str)
{
--
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