lkml.org 
[lkml]   [2010]   [Feb]   [12]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Subject[PATCH][trace-cmd] parse-events: Make input buffer const char *
From
Date
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)



\
 
 \ /
  Last update: 2010-02-13 01:55    [W:0.040 / U:1.404 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site