lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <87k3z843i9.fsf@gmail.com>
Date:	Sat, 16 Jun 2012 07:25:02 +0900
From:	Namhyung Kim <namhyung@...nel.org>
To:	Steven Rostedt <rostedt@...dmis.org>
Cc:	Arnaldo Carvalho de Melo <acme@...stprotocols.net>,
	Peter Zijlstra <a.p.zijlstra@...llo.nl>,
	Paul Mackerras <paulus@...ba.org>,
	Ingo Molnar <mingo@...nel.org>,
	LKML <linux-kernel@...r.kernel.org>,
	Frederic Weisbecker <fweisbec@...il.com>,
	Namhyung Kim <namhyung.kim@....com>
Subject: Re: [PATCH 3/3] tools lib traceevent: Introduce pevent_strerror

Steven Rostedt <rostedt@...dmis.org> writes:

> On Tue, 2012-06-12 at 16:42 +0900, Namhyung Kim wrote:
>
>> +/*
>> + * This must have a same ordering as the enum pevent_errno.
>> + */
>> +static const char * const pevent_error_str[] = {
>> +	"failed to allocate memory",
>> +	"failed to parse event",
>> +	"failed to read event id",
>> +	"failed to read event format",
>> +	"failed to read event print fmt",
>> +	"failed to allocate field name for ftrace",
>> +};
>> +
>
> Here's a little macro trick to keep the strings and enums always in
> sync:
>
> #define __PEVENT_ERRNO_CODES \
>  _C(PEVENT_ERRNO__MEM_ALLOC_FAILED,	"failed to allocate memory"),	\
>  _C(PEVENT_ERRNO__PARSE_EVENT_FAILED,	"failed to parse event"),	\
>  _C(PEVENT_ERRNO__READ_ID_FAILED,	"failed to read event id"),	\
>  _C(PEVENT_ERRNO__READ_FORMAT_FAILED,	"failed to read event format"),	\
>  _C(PEVENT_ERRNO__READ_PRINT_FAILED,	"failed to read event print fmt"),\
>  _C(PEVENT_ERRNO__OLD_FTRACE_ARG_FAILED,"failed to allocate field name for ftrace"),
>
> #undef _C
> #define _C(a,b) b
> static const char * const pevent_error_str[] = { __PEVENT_ERROR_CODES };
>

Cool. Maybe even shorter:

#define __PEVENT_ERRNO_CODES \
 _C(MEM_ALLOC_FAILED,	"failed to allocate memory"),	\
 _C(PARSE_EVENT_FAILED,	"failed to parse event"),	\
 _C(READ_ID_FAILED,	"failed to read event id"),	\
 _C(READ_FORMAT_FAILED,	"failed to read event format"),	\
 _C(READ_PRINT_FAILED,	"failed to read event print fmt"), \
 _C(OLD_FTRACE_ARG_FAILED, "failed to allocate field name for ftrace"),

#undef _C
#define _C(a,b) PEVENT_ERRNO__ ## a
static const char * const pevent_error_str[] = { __PEVENT_ERROR_CODES };

But it make them less grep-able?

Thanks,
Namhyung


> #undef _C
> #define _C(a, b) a
>
> enum pevent_errno {
> 	__PEVENT_ERRNO__BEFORE_START		= -100000 - 1,
> 	__PEVENT_ERRNO_CODES
> 	__PEVENT_ERRNO__END,
> };
>
> #define __PEVENT_ERRNO__START (__PEVENT_ERRNO__BEFORE_START + 1)
>
> Just saying ;-)
>
> -- Steve
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ