From: Steven Rostedt <rostedt@goodmis.org>
To: "Yordan Karadzhov (VMware)" <y.karadz@gmail.com>
Cc: linux-trace-devel@vger.kernel.org
Subject: Re: [PATCH 1/6] kernel-shark: Add KS_DOUBLE_SIZE macro
Date: Wed, 6 Jan 2021 12:28:34 -0500 [thread overview]
Message-ID: <20210106122834.0c70d68d@gandalf.local.home> (raw)
In-Reply-To: <20210106120208.3e212fbd@gandalf.local.home>
On Wed, 6 Jan 2021 12:02:08 -0500
Steven Rostedt <rostedt@goodmis.org> wrote:
> On Wed, 6 Jan 2021 18:11:15 +0200
> "Yordan Karadzhov (VMware)" <y.karadz@gmail.com> wrote:
>
> > The macro is useful for resizing of dynamic arrays. It is currently
> > used to resize the Data stream descriptor array, owned by the session
> > context. We will later use the macro with the arrays of data fields and
> > plugin contexts.
> >
> > Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
> > ---
> > src/libkshark-plugin.h | 14 ++++++++++++++
> > src/libkshark.c | 15 +++++++--------
> > 2 files changed, 21 insertions(+), 8 deletions(-)
> >
> > diff --git a/src/libkshark-plugin.h b/src/libkshark-plugin.h
> > index 1a642ad..f3c724f 100644
> > --- a/src/libkshark-plugin.h
> > +++ b/src/libkshark-plugin.h
> > @@ -346,6 +346,20 @@ int kshark_handle_dpi(struct kshark_data_stream *stream,
> > int kshark_handle_all_dpis(struct kshark_data_stream *stream,
> > enum kshark_plugin_actions task_id);
> >
> > +/** General purpose macro for resizing dynamic arrays. */
>
> Perhaps make this into a static inline function?
Never mind, I see you need the macro due to the "type" field. But we can
shorten this with:
#define KS_DOUBLE_SIZE(array, size) \
({ \
ssize_t n = size; \
typeof(array) _tmp_ = (typeof(array)) realloc(array, 2 * n * \
sizeof(*_tmp_)); \
if (_tmp_) { \
memset(_tmp_ + n, 0, n * sizeof(*_tmp_)); \
size = 2 * n; \
array = _tmp_; \
true; \
} \
false; \
})
> FYI, as a macro, to return a value you have:
>
> #define foo() ({ return true; })
The above is wrong, it should have been:
#define foo() ({ true; })
-- Steve
next prev parent reply other threads:[~2021-01-06 17:29 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-06 16:11 [PATCH 0/6] kernel-shark: Visualization plugin tools Yordan Karadzhov (VMware)
2021-01-06 16:11 ` [PATCH 1/6] kernel-shark: Add KS_DOUBLE_SIZE macro Yordan Karadzhov (VMware)
2021-01-06 17:02 ` Steven Rostedt
2021-01-06 17:28 ` Steven Rostedt [this message]
2021-01-06 16:11 ` [PATCH 2/6] kernel-shark: Add kshark_data_container to libkshark Yordan Karadzhov (VMware)
2021-01-06 17:38 ` Steven Rostedt
2021-01-06 16:11 ` [PATCH 3/6] kernel-shark: Add KS_DEFINE_PLUGIN_CONTEXT macro Yordan Karadzhov (VMware)
2021-01-06 17:45 ` Steven Rostedt
2021-01-06 16:11 ` [PATCH 4/6] kernel-shark: Start using C++17 Yordan Karadzhov (VMware)
2021-01-06 16:11 ` [PATCH 5/6] kernel-shark: Add plotting methods to KsPlugins Yordan Karadzhov (VMware)
2021-01-06 16:11 ` [PATCH 6/6] kernel-shark: Speed-up the sched_events plugin Yordan Karadzhov (VMware)
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=20210106122834.0c70d68d@gandalf.local.home \
--to=rostedt@goodmis.org \
--cc=linux-trace-devel@vger.kernel.org \
--cc=y.karadz@gmail.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).