[PATCH] vm: fix trace_flush()

2009-08-05 Thread Tomek Grabiec
We should not call str_len(line) after line has been moved
cause this may give undesired results.

Signed-off-by: Tomek Grabiec 
---
 vm/trace.c |5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/vm/trace.c b/vm/trace.c
index 45174f0..8757070 100644
--- a/vm/trace.c
+++ b/vm/trace.c
@@ -91,8 +91,9 @@ void trace_flush(void) {
}
 
/* Leave the rest of characters, which are not ended by '\n' */
-   memmove(trace_buffer->value, line, strlen(line) + 1);
-   trace_buffer->length = strlen(line);
+   int len = strlen(line);
+   memmove(trace_buffer->value, line, len + 1);
+   trace_buffer->length = len;
 
pthread_mutex_unlock(&trace_mutex);
 
-- 
1.6.0.6


--
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
___
Jatovm-devel mailing list
Jatovm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jatovm-devel


[PATCH] vm: fix trace_flush()

2009-08-03 Thread Tomek Grabiec
We should not use strtok() to split string into lines because it
swollows consequtive '\n' characters.

We also do not flush the buffer tail not ended by new line character
because we would print the thread name marker ([main]) in the middle
of the line next time the buffer is flushed. Tracing buffer behaves
now as if line-buffered.

Signed-off-by: Tomek Grabiec 
---
 vm/trace.c |   18 --
 1 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/vm/trace.c b/vm/trace.c
index e907a92..45174f0 100644
--- a/vm/trace.c
+++ b/vm/trace.c
@@ -66,8 +66,8 @@ int trace_printf(const char *fmt, ...)
 void trace_flush(void) {
struct vm_thread *self;
char *thread_name;
-   char *strtok_ptr;
char *line;
+   char *next;
 
ensure_trace_buffer();
 
@@ -79,17 +79,23 @@ void trace_flush(void) {
 
pthread_mutex_lock(&trace_mutex);
 
-   line = strtok_r(trace_buffer->value, "\n", &strtok_ptr);
-   while (line) {
+   line = trace_buffer->value;
+   next = index(line, '\n');
+   while (next) {
+   *next = 0;
+
fprintf(stderr, "[%s] %s\n", thread_name, line);
 
-   line = strtok_r(NULL, "\n", &strtok_ptr);
+   line = next + 1;
+   next = index(line, '\n');
}
 
+   /* Leave the rest of characters, which are not ended by '\n' */
+   memmove(trace_buffer->value, line, strlen(line) + 1);
+   trace_buffer->length = strlen(line);
+
pthread_mutex_unlock(&trace_mutex);
 
if (self)
free(thread_name);
-
-   trace_buffer->length = 0;
 }
-- 
1.6.0.6


--
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
___
Jatovm-devel mailing list
Jatovm-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jatovm-devel