From: Steven Rostedt <rostedt@goodmis.org>
To: Johannes Berg <johannes@sipsolutions.net>
Cc: LKML <linux-kernel@vger.kernel.org>
Subject: [PATCH][trace-cmd] parse-events: Make input buffer const char *
Date: Fri, 12 Feb 2010 19:53:04 -0500 [thread overview]
Message-ID: <1266022384.24271.106.camel@gandalf.stny.rr.com> (raw)
Johill,
I just wanted you to see a recent change I made. It touches your work
around you added for the older kernels that did not convert your macro
to a string. I'm sending this to you to make sure that it still works
for your liking.
Also, I think I see a bug in the original code (and I kept) where you
added a \ to %s. Perhaps its not a bug, but is it really needed? We
don't process this code through any printf formatting.
-- Steve
commit 4314457fc4de51b5ef5cc2df35f4d669299ae2b8
Author: Steven Rostedt <srostedt@redhat.com>
Date: Fri Feb 12 19:45:22 2010 -0500
parse-events: Make input buffer const char *
Make the input buffer that the parse events reads into a const char *.
This will be needed by later patches to make sure the input buffer
does not get modified.
In doing this change, the work around by Johannes Berg needed to
be rewritten, since the push_str modified the input buffer.
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
diff --git a/parse-events.c b/parse-events.c
index 7b3b440..c5e8080 100644
--- a/parse-events.c
+++ b/parse-events.c
@@ -30,11 +30,11 @@
#include "parse-events.h"
-static char *input_buf;
+static const char *input_buf;
static unsigned long long input_buf_ptr;
static unsigned long long input_buf_siz;
-static void init_input_buf(char *buf, unsigned long long size)
+static void init_input_buf(const char *buf, unsigned long long size)
{
input_buf = buf;
input_buf_siz = size;
@@ -657,26 +657,6 @@ static enum event_type get_type(int ch)
return EVENT_OP;
}
-static void __push_char(char c)
-{
- if (input_buf_ptr <= 0)
- die("too much pushback");
- input_buf[--input_buf_ptr] = c;
-}
-
-static void __push_str(char *s)
-{
- char *e = s;
-
- while (*e++)
- /* nothing */;
- e--;
- while (s != e) {
- e--;
- __push_char(*e);
- }
-}
-
static int __read_char(void)
{
if (input_buf_ptr >= input_buf_siz)
@@ -693,6 +673,8 @@ static int __peek_char(void)
return input_buf[input_buf_ptr];
}
+static enum event_type force_token(const char *str, char **tok);
+
static enum event_type __read_token(char **tok)
{
char buf[BUFSIZ];
@@ -848,24 +830,45 @@ static enum event_type __read_token(char **tok)
if (strcmp(*tok, "LOCAL_PR_FMT") == 0) {
free(*tok);
*tok = NULL;
- __push_str("\"\%s\" ");
- return __read_token(tok);
+ return force_token("\"\%s\" ", tok);
} else if (strcmp(*tok, "STA_PR_FMT") == 0) {
free(*tok);
*tok = NULL;
- __push_str("\" sta:%pM\" ");
- return __read_token(tok);
+ return force_token("\" sta:%pM\" ", tok);
} else if (strcmp(*tok, "VIF_PR_FMT") == 0) {
free(*tok);
*tok = NULL;
- __push_str("\" vif:%p(%d)\" ");
- return __read_token(tok);
+ return force_token("\" vif:%p(%d)\" ", tok);
}
}
return type;
}
+static enum event_type force_token(const char *str, char **tok)
+{
+ const char *save_input_buf;
+ unsigned long long save_input_buf_ptr;
+ unsigned long long save_input_buf_siz;
+ enum event_type type;
+
+ /* save off the current input pointers */
+ save_input_buf = input_buf;
+ save_input_buf_ptr = input_buf_ptr;
+ save_input_buf_siz = input_buf_siz;
+
+ init_input_buf(str, strlen(str));
+
+ type = __read_token(tok);
+
+ /* reset back to original token */
+ input_buf = save_input_buf;
+ input_buf_ptr = save_input_buf_ptr;
+ input_buf_siz = save_input_buf_siz;
+
+ return type;
+}
+
static void free_token(char *tok)
{
if (tok)
next reply other threads:[~2010-02-13 0:53 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-02-13 0:53 Steven Rostedt [this message]
2010-02-13 11:22 ` Johannes Berg
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=1266022384.24271.106.camel@gandalf.stny.rr.com \
--to=rostedt@goodmis.org \
--cc=johannes@sipsolutions.net \
--cc=linux-kernel@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®