From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
linux-kernel@vger.kernel.org, Jiri Olsa <jolsa@redhat.com>,
Namhyung Kim <namhyung@kernel.org>
Subject: Re: [PATCH v4 7/9] perf: Finalize subcmd independence
Date: Wed, 16 Dec 2015 21:57:41 -0300 [thread overview]
Message-ID: <20151217005741.GF19926@kernel.org> (raw)
In-Reply-To: <6e12946f0f26ce4d543d34db68d9dae3c8551cb9.1450193761.git.jpoimboe@redhat.com>
Em Tue, Dec 15, 2015 at 09:39:38AM -0600, Josh Poimboeuf escreveu:
> For the files that will be moved to the subcmd library, remove all their
> perf-specific includes and duplicate any needed functionality.
Breaks rhel6.7 building:
> #include "run-command.h"
> #include "sigchain.h"
> #include "subcmd-config.h"
> diff --git a/tools/perf/util/parse-options.c b/tools/perf/util/parse-options.c
> index c1da2a5..f424027 100644
> --- a/tools/perf/util/parse-options.c
> +++ b/tools/perf/util/parse-options.c
> @@ -1,33 +1,47 @@
> -#include "util.h"
> +#include <linux/compiler.h>
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <stdint.h>
> +#include <string.h>
> +#include <ctype.h>
> #include "subcmd-util.h"
> #include "parse-options.h"
> -#include "cache.h"
> -#include "header.h"
> #include "subcmd-config.h"
> -#include <linux/string.h>
> +#include "pager.h"
>
> #define OPT_SHORT 1
> #define OPT_UNSET 2
>
> +typedef uint64_t u64;
> +
[acme@sandy linux]$ cat /etc/redhat-release
Red Hat Enterprise Linux Server release 6.7 (Santiago)
CC /tmp/build/perf/parse-options.o
parse-options.c:15: error: redefinition of typedef ‘u64’
/home/acme/git/linux/tools/include/linux/types.h:28: note: previous
declaration of ‘u64’ was here
mv: cannot stat `/tmp/build/perf/.parse-options.o.tmp': No such file or
directory
make[3]: *** [/tmp/build/perf/parse-options.o] Error 1
make[2]: *** [/tmp/build/perf/libsubcmd-in.o] Error 2
make[1]: *** [/tmp/build/perf/libsubcmd.a] Error 2
make[1]: *** Waiting for unfinished jobs....
MKDIR /tmp/build/perf/util/
> char *error_buf;
>
> static int opterror(const struct option *opt, const char *reason, int flags)
> {
> if (flags & OPT_SHORT)
> - return error("switch `%c' %s", opt->short_name, reason);
> - if (flags & OPT_UNSET)
> - return error("option `no-%s' %s", opt->long_name, reason);
> - return error("option `%s' %s", opt->long_name, reason);
> + fprintf(stderr, " Error: switch `%c' %s", opt->short_name, reason);
> + else if (flags & OPT_UNSET)
> + fprintf(stderr, " Error: option `no-%s' %s", opt->long_name, reason);
> + else
> + fprintf(stderr, " Error: option `%s' %s", opt->long_name, reason);
> +
> + return -1;
> +}
> +
> +static const char *skip_prefix(const char *str, const char *prefix)
> +{
> + size_t len = strlen(prefix);
> + return strncmp(str, prefix, len) ? NULL : str + len;
> }
>
> static void optwarning(const struct option *opt, const char *reason, int flags)
> {
> if (flags & OPT_SHORT)
> - warning("switch `%c' %s", opt->short_name, reason);
> + fprintf(stderr, " Warning: switch `%c' %s", opt->short_name, reason);
> else if (flags & OPT_UNSET)
> - warning("option `no-%s' %s", opt->long_name, reason);
> + fprintf(stderr, " Warning: option `no-%s' %s", opt->long_name, reason);
> else
> - warning("option `%s' %s", opt->long_name, reason);
> + fprintf(stderr, " Warning: option `%s' %s", opt->long_name, reason);
> }
>
> static int get_arg(struct parse_opt_ctx_t *p, const struct option *opt,
> @@ -71,11 +85,11 @@ static int get_value(struct parse_opt_ctx_t *p,
>
> if (((flags & OPT_SHORT) && p->excl_opt->short_name) ||
> p->excl_opt->long_name == NULL) {
> - scnprintf(msg, sizeof(msg), "cannot be used with switch `%c'",
> - p->excl_opt->short_name);
> + snprintf(msg, sizeof(msg), "cannot be used with switch `%c'",
> + p->excl_opt->short_name);
> } else {
> - scnprintf(msg, sizeof(msg), "cannot be used with %s",
> - p->excl_opt->long_name);
> + snprintf(msg, sizeof(msg), "cannot be used with %s",
> + p->excl_opt->long_name);
> }
> opterror(opt, msg, flags);
> return -3;
> @@ -401,14 +415,16 @@ match:
> return get_value(p, options, flags);
> }
>
> - if (ambiguous_option)
> - return error("Ambiguous option: %s "
> - "(could be --%s%s or --%s%s)",
> - arg,
> - (ambiguous_flags & OPT_UNSET) ? "no-" : "",
> - ambiguous_option->long_name,
> - (abbrev_flags & OPT_UNSET) ? "no-" : "",
> - abbrev_option->long_name);
> + if (ambiguous_option) {
> + fprintf(stderr,
> + " Error: Ambiguous option: %s (could be --%s%s or --%s%s)",
> + arg,
> + (ambiguous_flags & OPT_UNSET) ? "no-" : "",
> + ambiguous_option->long_name,
> + (abbrev_flags & OPT_UNSET) ? "no-" : "",
> + abbrev_option->long_name);
> + return -1;
> + }
> if (abbrev_option)
> return get_value(p, abbrev_option, abbrev_flags);
> return -2;
> @@ -420,7 +436,7 @@ static void check_typos(const char *arg, const struct option *options)
> return;
>
> if (!prefixcmp(arg, "no-")) {
> - error ("did you mean `--%s` (with two dashes ?)", arg);
> + fprintf(stderr, " Error: did you mean `--%s` (with two dashes ?)", arg);
> exit(129);
> }
>
> @@ -428,7 +444,7 @@ static void check_typos(const char *arg, const struct option *options)
> if (!options->long_name)
> continue;
> if (!prefixcmp(options->long_name, arg)) {
> - error ("did you mean `--%s` (with two dashes ?)", arg);
> + fprintf(stderr, " Error: did you mean `--%s` (with two dashes ?)", arg);
> exit(129);
> }
> }
> @@ -746,16 +762,18 @@ static int option__cmp(const void *va, const void *vb)
>
> static struct option *options__order(const struct option *opts)
> {
> - int nr_opts = 0;
> + int nr_opts = 0, len;
> const struct option *o = opts;
> struct option *ordered;
>
> for (o = opts; o->type != OPTION_END; o++)
> ++nr_opts;
>
> - ordered = memdup(opts, sizeof(*o) * (nr_opts + 1));
> - if (ordered == NULL)
> + len = sizeof(*o) * (nr_opts + 1);
> + ordered = malloc(len);
> + if (!ordered)
> goto out;
> + memcpy(ordered, opts, len);
>
> qsort(ordered, nr_opts, sizeof(*o), option__cmp);
> out:
> diff --git a/tools/perf/util/parse-options.h b/tools/perf/util/parse-options.h
> index d1544069..dec893f 100644
> --- a/tools/perf/util/parse-options.h
> +++ b/tools/perf/util/parse-options.h
> @@ -1,8 +1,8 @@
> #ifndef __PERF_PARSE_OPTIONS_H
> #define __PERF_PARSE_OPTIONS_H
>
> -#include <linux/kernel.h>
> #include <stdbool.h>
> +#include <stdint.h>
>
> enum parse_opt_type {
> /* special types */
> diff --git a/tools/perf/util/run-command.c b/tools/perf/util/run-command.c
> index 910c0f6..fed37d6 100644
> --- a/tools/perf/util/run-command.c
> +++ b/tools/perf/util/run-command.c
> @@ -1,7 +1,15 @@
> -#include "cache.h"
> +#include <unistd.h>
> +#include <sys/types.h>
> +#include <sys/stat.h>
> +#include <fcntl.h>
> +#include <string.h>
> +#include <errno.h>
> +#include <sys/wait.h>
> +#include "subcmd-util.h"
> #include "run-command.h"
> #include "exec_cmd.h"
> -#include "debug.h"
> +
> +#define STRERR_BUFSIZE 128
>
> static inline void close_pair(int fd[2])
> {
> @@ -164,8 +172,8 @@ static int wait_or_whine(pid_t pid)
> if (waiting < 0) {
> if (errno == EINTR)
> continue;
> - error("waitpid failed (%s)",
> - strerror_r(errno, sbuf, sizeof(sbuf)));
> + fprintf(stderr, " Error: waitpid failed (%s)",
> + strerror_r(errno, sbuf, sizeof(sbuf)));
> return -ERR_RUN_COMMAND_WAITPID;
> }
> if (waiting != pid)
> diff --git a/tools/perf/util/run-command.h b/tools/perf/util/run-command.h
> index cf7d655..4a55393 100644
> --- a/tools/perf/util/run-command.h
> +++ b/tools/perf/util/run-command.h
> @@ -1,6 +1,8 @@
> #ifndef __PERF_RUN_COMMAND_H
> #define __PERF_RUN_COMMAND_H
>
> +#include <unistd.h>
> +
> enum {
> ERR_RUN_COMMAND_FORK = 10000,
> ERR_RUN_COMMAND_EXEC,
> diff --git a/tools/perf/util/sigchain.c b/tools/perf/util/sigchain.c
> index ba785e9..3537c34 100644
> --- a/tools/perf/util/sigchain.c
> +++ b/tools/perf/util/sigchain.c
> @@ -1,5 +1,6 @@
> +#include <signal.h>
> +#include "subcmd-util.h"
> #include "sigchain.h"
> -#include "cache.h"
>
> #define SIGCHAIN_MAX_SIGNALS 32
>
> diff --git a/tools/perf/util/subcmd-util.h b/tools/perf/util/subcmd-util.h
> index 98fb9f9..321aeb1 100644
> --- a/tools/perf/util/subcmd-util.h
> +++ b/tools/perf/util/subcmd-util.h
> @@ -1,8 +1,66 @@
> #ifndef __PERF_SUBCMD_UTIL_H
> #define __PERF_SUBCMD_UTIL_H
>
> +#include <stdarg.h>
> +#include <stdlib.h>
> #include <stdio.h>
>
> +#define NORETURN __attribute__((__noreturn__))
> +
> +static inline void report(const char *prefix, const char *err, va_list params)
> +{
> + char msg[1024];
> + vsnprintf(msg, sizeof(msg), err, params);
> + fprintf(stderr, " %s%s\n", prefix, msg);
> +}
> +
> +static NORETURN inline void die(const char *err, ...)
> +{
> + va_list params;
> +
> + va_start(params, err);
> + report(" Fatal: ", err, params);
> + exit(128);
> + va_end(params);
> +}
> +
> +#define zfree(ptr) ({ free(*ptr); *ptr = NULL; })
> +
> +#define alloc_nr(x) (((x)+16)*3/2)
> +
> +/*
> + * Realloc the buffer pointed at by variable 'x' so that it can hold
> + * at least 'nr' entries; the number of entries currently allocated
> + * is 'alloc', using the standard growing factor alloc_nr() macro.
> + *
> + * DO NOT USE any expression with side-effect for 'x' or 'alloc'.
> + */
> +#define ALLOC_GROW(x, nr, alloc) \
> + do { \
> + if ((nr) > alloc) { \
> + if (alloc_nr(alloc) < (nr)) \
> + alloc = (nr); \
> + else \
> + alloc = alloc_nr(alloc); \
> + x = xrealloc((x), alloc * sizeof(*(x))); \
> + } \
> + } while(0)
> +
> +static inline void *xrealloc(void *ptr, size_t size)
> +{
> + void *ret = realloc(ptr, size);
> + if (!ret && !size)
> + ret = realloc(ptr, 1);
> + if (!ret) {
> + ret = realloc(ptr, size);
> + if (!ret && !size)
> + ret = realloc(ptr, 1);
> + if (!ret)
> + die("Out of memory, realloc failed");
> + }
> + return ret;
> +}
> +
> #define astrcatf(out, fmt, ...) \
> ({ \
> char *tmp = *(out); \
> @@ -21,4 +79,13 @@ static inline void astrcat(char **out, const char *add)
> free(tmp);
> }
>
> +static inline int prefixcmp(const char *str, const char *prefix)
> +{
> + for (; ; str++, prefix++)
> + if (!*prefix)
> + return 0;
> + else if (*str != *prefix)
> + return (unsigned char)*prefix - (unsigned char)*str;
> +}
> +
> #endif /* __PERF_SUBCMD_UTIL_H */
> diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h
> index 150858f..4b519c5 100644
> --- a/tools/perf/util/util.h
> +++ b/tools/perf/util/util.h
> @@ -151,12 +151,6 @@ extern void set_warning_routine(void (*routine)(const char *err, va_list params)
> extern int prefixcmp(const char *str, const char *prefix);
> extern void set_buildid_dir(const char *dir);
>
> -static inline const char *skip_prefix(const char *str, const char *prefix)
> -{
> - size_t len = strlen(prefix);
> - return strncmp(str, prefix, len) ? NULL : str + len;
> -}
> -
> #ifdef __GLIBC_PREREQ
> #if __GLIBC_PREREQ(2, 1)
> #define HAVE_STRCHRNUL
> @@ -187,14 +181,6 @@ static inline void *zalloc(size_t size)
>
> #define zfree(ptr) ({ free(*ptr); *ptr = NULL; })
>
> -static inline int has_extension(const char *filename, const char *ext)
> -{
> - size_t len = strlen(filename);
> - size_t extlen = strlen(ext);
> -
> - return len > extlen && !memcmp(filename + len - extlen, ext, extlen);
> -}
> -
> /* Sane ctype - no locale, and works with signed chars */
> #undef isascii
> #undef isspace
> --
> 2.4.3
next prev parent reply other threads:[~2015-12-17 0:57 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-12-15 15:39 [PATCH v4 0/9] perf tools: Move perf subcommand framework to a library Josh Poimboeuf
2015-12-15 15:39 ` [PATCH v4 1/9] tools build: Fix feature Makefile issues with 'O=' Josh Poimboeuf
2015-12-18 8:51 ` [tip:perf/core] tools build: Fix feature Makefile issues with 'O= ' tip-bot for Josh Poimboeuf
2015-12-15 15:39 ` [PATCH v4 2/9] perf tools: Move strlcpy() from perf to tools/lib/string.c Josh Poimboeuf
2015-12-18 8:52 ` [tip:perf/core] perf tools: Move strlcpy() from perf to tools/lib /string.c tip-bot for Josh Poimboeuf
2015-12-15 15:39 ` [PATCH v4 3/9] perf: Document the fact that parse_options*() may exit Josh Poimboeuf
2015-12-18 8:52 ` [tip:perf/core] perf tools: Document the fact that parse_options* () " tip-bot for Josh Poimboeuf
2015-12-15 15:39 ` [PATCH v4 4/9] perf: Provide subcmd configuration at runtime Josh Poimboeuf
2015-12-18 8:53 ` [tip:perf/core] perf tools: " tip-bot for Josh Poimboeuf
2015-12-15 15:39 ` [PATCH v4 5/9] perf: Remove subcmd dependencies on strbuf Josh Poimboeuf
2015-12-18 8:53 ` [tip:perf/core] perf tools: " tip-bot for Josh Poimboeuf
2015-12-15 15:39 ` [PATCH v4 6/9] perf: Remove 'perf' from subcmd function and variable names Josh Poimboeuf
2015-12-18 8:53 ` [tip:perf/core] perf tools: " tip-bot for Josh Poimboeuf
2015-12-15 15:39 ` [PATCH v4 7/9] perf: Finalize subcmd independence Josh Poimboeuf
2015-12-17 0:57 ` Arnaldo Carvalho de Melo [this message]
2015-12-17 1:09 ` Josh Poimboeuf
2015-12-17 1:27 ` Arnaldo Carvalho de Melo
2015-12-17 4:12 ` Josh Poimboeuf
2015-12-18 8:54 ` [tip:perf/core] perf tools: " tip-bot for Josh Poimboeuf
2015-12-15 15:39 ` [PATCH v4 8/9] perf subcmd: Create subcmd library Josh Poimboeuf
2015-12-18 8:54 ` [tip:perf/core] " tip-bot for Josh Poimboeuf
2015-12-15 15:39 ` [PATCH v4 9/9] tools subcmd: Rename subcmd header include guards Josh Poimboeuf
2015-12-18 8:54 ` [tip:perf/core] " tip-bot for Josh Poimboeuf
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=20151217005741.GF19926@kernel.org \
--to=acme@kernel.org \
--cc=jolsa@redhat.com \
--cc=jpoimboe@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.