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