linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: linux-kernel@vger.kernel.org,
	Arnaldo Carvalho de Melo <acme@redhat.com>,
	Adrian Hunter <adrian.hunter@intel.com>,
	David Ahern <dsahern@gmail.com>, Jiri Olsa <jolsa@kernel.org>,
	Namhyung Kim <namhyung@kernel.org>,
	Wang Nan <wangnan0@huawei.com>
Subject: [PATCH 18/28] perf tools: Move extra string util functions to util/string2.h
Date: Wed, 19 Apr 2017 13:17:13 -0300	[thread overview]
Message-ID: <20170419161723.21011-19-acme@kernel.org> (raw)
In-Reply-To: <20170419161723.21011-1-acme@kernel.org>

From: Arnaldo Carvalho de Melo <acme@redhat.com>

Moving them from util.h, where they don't belong. Since libc already
have string.h, name it slightly differently, as string2.h.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/n/tip-eh3vz5sqxsrdd8lodoro4jrw@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/bench/mem-functions.c |  1 +
 tools/perf/builtin-script.c      |  1 +
 tools/perf/builtin-stat.c        |  1 +
 tools/perf/builtin-trace.c       |  1 +
 tools/perf/ui/browser.c          |  1 +
 tools/perf/ui/browsers/hists.c   |  1 +
 tools/perf/ui/gtk/hists.c        |  1 +
 tools/perf/ui/stdio/hist.c       |  1 +
 tools/perf/util/annotate.c       |  1 +
 tools/perf/util/dso.c            |  1 +
 tools/perf/util/dwarf-aux.c      |  1 +
 tools/perf/util/event.c          |  2 +-
 tools/perf/util/header.c         |  1 +
 tools/perf/util/parse-events.c   |  2 +-
 tools/perf/util/pmu.c            |  1 +
 tools/perf/util/probe-event.c    |  1 +
 tools/perf/util/probe-file.c     |  1 +
 tools/perf/util/probe-finder.c   |  1 +
 tools/perf/util/strfilter.c      |  2 +-
 tools/perf/util/string.c         | 16 +++++++++------
 tools/perf/util/string2.h        | 42 ++++++++++++++++++++++++++++++++++++++++
 tools/perf/util/thread_map.c     |  1 +
 tools/perf/util/util.h           | 32 ------------------------------
 23 files changed, 72 insertions(+), 41 deletions(-)
 create mode 100644 tools/perf/util/string2.h

diff --git a/tools/perf/bench/mem-functions.c b/tools/perf/bench/mem-functions.c
index d1dea33dcfcf..fbd732b54047 100644
--- a/tools/perf/bench/mem-functions.c
+++ b/tools/perf/bench/mem-functions.c
@@ -12,6 +12,7 @@
 #include <subcmd/parse-options.h>
 #include "../util/header.h"
 #include "../util/cloexec.h"
+#include "../util/string2.h"
 #include "bench.h"
 #include "mem-memcpy-arch.h"
 #include "mem-memset-arch.h"
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 5f4e36a4c444..a710f6867954 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -21,6 +21,7 @@
 #include "util/cpumap.h"
 #include "util/thread_map.h"
 #include "util/stat.h"
+#include "util/string2.h"
 #include "util/thread-stack.h"
 #include "util/time-utils.h"
 #include "print_binary.h"
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 5abef25f9983..1da86e6708c0 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -64,6 +64,7 @@
 #include "util/session.h"
 #include "util/tool.h"
 #include "util/group.h"
+#include "util/string2.h"
 #include "asm/bug.h"
 
 #include <linux/time64.h>
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index 9a8b9e6f47f7..4160d946a34d 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -37,6 +37,7 @@
 #include "util/bpf-loader.h"
 #include "callchain.h"
 #include "print_binary.h"
+#include "string2.h"
 #include "syscalltbl.h"
 #include "rb_resort.h"
 
diff --git a/tools/perf/ui/browser.c b/tools/perf/ui/browser.c
index 73bdd07321c4..a4d3762cd825 100644
--- a/tools/perf/ui/browser.c
+++ b/tools/perf/ui/browser.c
@@ -1,4 +1,5 @@
 #include "../util.h"
+#include "../string2.h"
 #include "../config.h"
 #include "../../perf.h"
 #include "libslang.h"
diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c
index ac7f6a3e4a86..bc397bbbc3a7 100644
--- a/tools/perf/ui/browsers/hists.c
+++ b/tools/perf/ui/browsers/hists.c
@@ -20,6 +20,7 @@
 #include "map.h"
 #include "annotate.h"
 #include "srcline.h"
+#include "string2.h"
 
 #include "sane_ctype.h"
 
diff --git a/tools/perf/ui/gtk/hists.c b/tools/perf/ui/gtk/hists.c
index a4f02de7c1b5..c42de4dcc055 100644
--- a/tools/perf/ui/gtk/hists.c
+++ b/tools/perf/ui/gtk/hists.c
@@ -4,6 +4,7 @@
 #include "../sort.h"
 #include "../hist.h"
 #include "../helpline.h"
+#include "../string2.h"
 #include "gtk.h"
 
 #define MAX_COLUMNS			32
diff --git a/tools/perf/ui/stdio/hist.c b/tools/perf/ui/stdio/hist.c
index 66aa4eb369f1..5565105c9688 100644
--- a/tools/perf/ui/stdio/hist.c
+++ b/tools/perf/ui/stdio/hist.c
@@ -5,6 +5,7 @@
 #include "../../util/sort.h"
 #include "../../util/evsel.h"
 #include "../../util/srcline.h"
+#include "../../util/string2.h"
 #include "../../util/sane_ctype.h"
 
 static size_t callchain__fprintf_left_margin(FILE *fp, int left_margin)
diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index d69fdafba274..297bf5c66609 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -19,6 +19,7 @@
 #include "annotate.h"
 #include "evsel.h"
 #include "block-range.h"
+#include "string2.h"
 #include "arch/common.h"
 #include <regex.h>
 #include <pthread.h>
diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c
index 385c82e12473..6ad57730a0ed 100644
--- a/tools/perf/util/dso.c
+++ b/tools/perf/util/dso.c
@@ -8,6 +8,7 @@
 #include "auxtrace.h"
 #include "util.h"
 #include "debug.h"
+#include "string2.h"
 #include "vdso.h"
 
 static const char * const debuglink_paths[] = {
diff --git a/tools/perf/util/dwarf-aux.c b/tools/perf/util/dwarf-aux.c
index 5fb186d142f6..780ee4629bd0 100644
--- a/tools/perf/util/dwarf-aux.c
+++ b/tools/perf/util/dwarf-aux.c
@@ -22,6 +22,7 @@
 #include "util.h"
 #include "debug.h"
 #include "dwarf-aux.h"
+#include "string2.h"
 
 /**
  * cu_find_realpath - Find the realpath of the target file
diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
index f8a706ba72f2..53b81b2283c1 100644
--- a/tools/perf/util/event.c
+++ b/tools/perf/util/event.c
@@ -8,7 +8,7 @@
 #include "hist.h"
 #include "machine.h"
 #include "sort.h"
-#include "string.h"
+#include "string2.h"
 #include "strlist.h"
 #include "thread.h"
 #include "thread_map.h"
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index faf046fc398f..51865b8cb9f3 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -1,5 +1,6 @@
 #include <inttypes.h>
 #include "util.h"
+#include "string2.h"
 #include <sys/types.h>
 #include <byteswap.h>
 #include <unistd.h>
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index 6b498aea9fde..535c7cbb2bfb 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -7,7 +7,7 @@
 #include <subcmd/parse-options.h>
 #include "parse-events.h"
 #include <subcmd/exec-cmd.h>
-#include "string.h"
+#include "string2.h"
 #include "symbol.h"
 #include "cache.h"
 #include "header.h"
diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
index 11c752561c55..7503fa170249 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -15,6 +15,7 @@
 #include "header.h"
 #include "pmu-events/pmu-events.h"
 #include "cache.h"
+#include "string2.h"
 
 struct perf_pmu_format {
 	char *name;
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index 7caba7003734..8f1374071cfc 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -47,6 +47,7 @@
 #include "probe-finder.h"
 #include "probe-file.h"
 #include "session.h"
+#include "string2.h"
 
 #include "sane_ctype.h"
 
diff --git a/tools/perf/util/probe-file.c b/tools/perf/util/probe-file.c
index 88714dec8912..7942ea5c7e81 100644
--- a/tools/perf/util/probe-file.c
+++ b/tools/perf/util/probe-file.c
@@ -28,6 +28,7 @@
 #include "probe-file.h"
 #include "session.h"
 #include "perf_regs.h"
+#include "string2.h"
 
 /* 4096 - 2 ('\n' + '\0') */
 #define MAX_CMDLEN 4094
diff --git a/tools/perf/util/probe-finder.c b/tools/perf/util/probe-finder.c
index 9ddd7dad2e6e..3f3cd11d3b7c 100644
--- a/tools/perf/util/probe-finder.c
+++ b/tools/perf/util/probe-finder.c
@@ -41,6 +41,7 @@
 #include "symbol.h"
 #include "probe-finder.h"
 #include "probe-file.h"
+#include "string2.h"
 
 /* Kprobe tracer basic type is up to u64 */
 #define MAX_BASIC_TYPE_BITS	64
diff --git a/tools/perf/util/strfilter.c b/tools/perf/util/strfilter.c
index c663c9153245..3b068e0e2d59 100644
--- a/tools/perf/util/strfilter.c
+++ b/tools/perf/util/strfilter.c
@@ -1,5 +1,5 @@
 #include "util.h"
-#include "string.h"
+#include "string2.h"
 #include "strfilter.h"
 
 #include "sane_ctype.h"
diff --git a/tools/perf/util/string.c b/tools/perf/util/string.c
index e716a6e5bb19..cca53b693a48 100644
--- a/tools/perf/util/string.c
+++ b/tools/perf/util/string.c
@@ -1,5 +1,7 @@
-#include "util.h"
-#include "linux/string.h"
+#include "string2.h"
+#include <linux/kernel.h>
+#include <linux/string.h>
+#include <stdlib.h>
 
 #include "sane_ctype.h"
 
@@ -101,8 +103,10 @@ static int count_argc(const char *str)
 void argv_free(char **argv)
 {
 	char **p;
-	for (p = argv; *p; p++)
-		zfree(p);
+	for (p = argv; *p; p++) {
+		free(*p);
+		*p = NULL;
+	}
 
 	free(argv);
 }
@@ -122,7 +126,7 @@ void argv_free(char **argv)
 char **argv_split(const char *str, int *argcp)
 {
 	int argc = count_argc(str);
-	char **argv = zalloc(sizeof(*argv) * (argc+1));
+	char **argv = calloc(argc + 1, sizeof(*argv));
 	char **argvp;
 
 	if (argv == NULL)
@@ -379,7 +383,7 @@ char *asprintf_expr_inout_ints(const char *var, bool in, size_t nints, int *ints
 				goto out_err_overflow;
 
 			if (i > 0)
-				printed += snprintf(e + printed, size - printed, " %s ", or_and);
+				printed += scnprintf(e + printed, size - printed, " %s ", or_and);
 			printed += scnprintf(e + printed, size - printed,
 					     "%s %s %d", var, eq_neq, ints[i]);
 		}
diff --git a/tools/perf/util/string2.h b/tools/perf/util/string2.h
new file mode 100644
index 000000000000..2f619681bd6a
--- /dev/null
+++ b/tools/perf/util/string2.h
@@ -0,0 +1,42 @@
+#ifndef PERF_STRING_H
+#define PERF_STRING_H
+
+#include <linux/types.h>
+#include <stddef.h>
+#include <string.h>
+
+s64 perf_atoll(const char *str);
+char **argv_split(const char *str, int *argcp);
+void argv_free(char **argv);
+bool strglobmatch(const char *str, const char *pat);
+bool strglobmatch_nocase(const char *str, const char *pat);
+bool strlazymatch(const char *str, const char *pat);
+static inline bool strisglob(const char *str)
+{
+	return strpbrk(str, "*?[") != NULL;
+}
+int strtailcmp(const char *s1, const char *s2);
+char *strxfrchar(char *s, char from, char to);
+
+char *ltrim(char *s);
+char *rtrim(char *s);
+
+static inline char *trim(char *s)
+{
+	return ltrim(rtrim(s));
+}
+
+char *asprintf_expr_inout_ints(const char *var, bool in, size_t nints, int *ints);
+
+static inline char *asprintf_expr_in_ints(const char *var, size_t nints, int *ints)
+{
+	return asprintf_expr_inout_ints(var, true, nints, ints);
+}
+
+static inline char *asprintf_expr_not_in_ints(const char *var, size_t nints, int *ints)
+{
+	return asprintf_expr_inout_ints(var, false, nints, ints);
+}
+
+
+#endif /* PERF_STRING_H */
diff --git a/tools/perf/util/thread_map.c b/tools/perf/util/thread_map.c
index 9026408ea55b..ef86bf517e01 100644
--- a/tools/perf/util/thread_map.c
+++ b/tools/perf/util/thread_map.c
@@ -6,6 +6,7 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <unistd.h>
+#include "string2.h"
 #include "strlist.h"
 #include <string.h>
 #include <api/fs/fs.h>
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h
index 46cfdccc32bc..850ca54d17a5 100644
--- a/tools/perf/util/util.h
+++ b/tools/perf/util/util.h
@@ -98,18 +98,6 @@ int copyfile(const char *from, const char *to);
 int copyfile_mode(const char *from, const char *to, mode_t mode);
 int copyfile_offset(int fromfd, loff_t from_ofs, int tofd, loff_t to_ofs, u64 size);
 
-s64 perf_atoll(const char *str);
-char **argv_split(const char *str, int *argcp);
-void argv_free(char **argv);
-bool strglobmatch(const char *str, const char *pat);
-bool strglobmatch_nocase(const char *str, const char *pat);
-bool strlazymatch(const char *str, const char *pat);
-static inline bool strisglob(const char *str)
-{
-	return strpbrk(str, "*?[") != NULL;
-}
-int strtailcmp(const char *s1, const char *s2);
-char *strxfrchar(char *s, char from, char to);
 unsigned long convert_unit(unsigned long value, char *unit);
 ssize_t readn(int fd, void *buf, size_t n);
 ssize_t writen(int fd, void *buf, size_t n);
@@ -121,14 +109,6 @@ void event_attr_init(struct perf_event_attr *attr);
 size_t hex_width(u64 v);
 int hex2u64(const char *ptr, u64 *val);
 
-char *ltrim(char *s);
-char *rtrim(char *s);
-
-static inline char *trim(char *s)
-{
-	return ltrim(rtrim(s));
-}
-
 void dump_stack(void);
 void sighandler_dump_stack(int sig);
 
@@ -175,18 +155,6 @@ int gzip_decompress_to_file(const char *input, int output_fd);
 int lzma_decompress_to_file(const char *input, int output_fd);
 #endif
 
-char *asprintf_expr_inout_ints(const char *var, bool in, size_t nints, int *ints);
-
-static inline char *asprintf_expr_in_ints(const char *var, size_t nints, int *ints)
-{
-	return asprintf_expr_inout_ints(var, true, nints, ints);
-}
-
-static inline char *asprintf_expr_not_in_ints(const char *var, size_t nints, int *ints)
-{
-	return asprintf_expr_inout_ints(var, false, nints, ints);
-}
-
 int get_stack_size(const char *str, unsigned long *_size);
 
 int fetch_kernel_version(unsigned int *puint,
-- 
2.9.3

  parent reply	other threads:[~2017-04-19 16:22 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-19 16:16 [GIT PULL 00/28] perf/core fixes and cleanups Arnaldo Carvalho de Melo
2017-04-19 16:16 ` [PATCH 01/28] perf unwind arm64: Add missing errno.h header Arnaldo Carvalho de Melo
2017-04-19 16:16 ` [PATCH 02/28] perf tools: Remove FLEX_ARRAY definition Arnaldo Carvalho de Melo
2017-04-19 16:16 ` [PATCH 03/28] tools include: Introduce linux/bug.h, from the kernel sources Arnaldo Carvalho de Melo
2017-04-19 16:16 ` [PATCH 04/28] tools include: Adopt __same_type() and __must_be_array() from the kernel Arnaldo Carvalho de Melo
2017-04-19 16:17 ` [PATCH 05/28] tools include: Move ARRAY_SIZE() to linux/kernel.h Arnaldo Carvalho de Melo
2017-04-19 16:17 ` [PATCH 06/28] perf tools: Add include <linux/kernel.h> where ARRAY_SIZE() is used Arnaldo Carvalho de Melo
2017-04-19 16:17 ` [PATCH 07/28] objtool: Drop ARRAY_SIZE() definition, tools/include/linux/kernel.h has it now Arnaldo Carvalho de Melo
2017-04-19 16:17 ` [PATCH 08/28] tools include: Drop ARRAY_SIZE() definition from linux/hashtable.h Arnaldo Carvalho de Melo
2017-04-19 16:17 ` [PATCH 09/28] perf tools: Remove unused macros from util.h Arnaldo Carvalho de Melo
2017-04-19 16:17 ` [PATCH 10/28] perf tools: Including missing inttypes.h header Arnaldo Carvalho de Melo
2017-04-19 16:17 ` [PATCH 11/28] perf tools: Remove PRI[xu] macros from perf.h Arnaldo Carvalho de Melo
2017-04-19 16:17 ` [PATCH 12/28] perf tools: Replace STR() calls with __stringify() Arnaldo Carvalho de Melo
2017-04-19 16:17 ` [PATCH 13/28] perf tools: Ditch unused PATH_SEP, STRIP_EXTENSION Arnaldo Carvalho de Melo
2017-04-19 16:17 ` [PATCH 14/28] perf tools: Move sane ctype stuff from util.h to sane_ctype.h Arnaldo Carvalho de Melo
2017-04-19 16:17 ` [PATCH 15/28] tools include: Include missing headers for fls() and types in linux/log2.h Arnaldo Carvalho de Melo
2017-04-19 16:17 ` [PATCH 16/28] perf tools: Move print_binary definitions to separate files Arnaldo Carvalho de Melo
2017-04-19 16:17 ` [PATCH 17/28] perf tools: Move srcline definitions to separate header Arnaldo Carvalho de Melo
2017-04-19 16:17 ` Arnaldo Carvalho de Melo [this message]
2017-04-19 16:17 ` [PATCH 19/28] perf tools: Include errno.h where needed Arnaldo Carvalho de Melo
2017-04-19 16:17 ` [PATCH 20/28] perf str{filter,list}: Disentangle headers Arnaldo Carvalho de Melo
2017-04-19 16:17 ` [PATCH 21/28] perf tools: Don't include terminal handling headers in util.h Arnaldo Carvalho de Melo
2017-04-19 16:17 ` [PATCH 22/28] perf tools: Move path related functions to util/path.h Arnaldo Carvalho de Melo
2017-04-19 16:17 ` [PATCH 23/28] perf tools: No need to include bitops.h in util.h Arnaldo Carvalho de Melo
2017-04-19 16:17 ` [PATCH 24/28] perf tools: Use api/fs/tracing_path.h where needed Arnaldo Carvalho de Melo
2017-04-19 16:17 ` [PATCH 25/28] perf tools: Remove misplaced __maybe_unused in some functions Arnaldo Carvalho de Melo
2017-04-19 16:17 ` [PATCH 26/28] perf tools: Remove include dirent.h from util.h Arnaldo Carvalho de Melo
2017-04-19 16:17 ` [PATCH 27/28] perf tools: Remove regex.h and fnmatch.h " Arnaldo Carvalho de Melo
2017-04-19 16:17 ` [PATCH 28/28] perf tools: Ditch unused strchrnul() reimplementation Arnaldo Carvalho de Melo
2017-04-20  8:10 ` [GIT PULL 00/28] perf/core fixes and cleanups Ingo Molnar
2017-04-20 11:24   ` Arnaldo Carvalho de Melo
2017-04-20 11:29     ` Ingo Molnar
2017-04-20 17:10       ` Arnaldo Carvalho de Melo
2017-04-20 18:29         ` Arnaldo Carvalho de Melo
2017-04-20 18:51           ` Arnaldo Carvalho de Melo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170419161723.21011-19-acme@kernel.org \
    --to=acme@kernel.org \
    --cc=acme@redhat.com \
    --cc=adrian.hunter@intel.com \
    --cc=dsahern@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    --cc=wangnan0@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).