[cairo-commit] 3 commits - perf/cairo-perf-trace.c util/cairo-script util/cairo-trace

Chris Wilson ickle at kemper.freedesktop.org
Fri Jun 19 06:44:01 PDT 2009


 perf/cairo-perf-trace.c                      |    8 ++++++--
 util/cairo-script/cairo-script-interpreter.c |    6 ++++++
 util/cairo-script/cairo-script-interpreter.h |    3 +++
 util/cairo-script/cairo-script-private.h     |    2 ++
 util/cairo-script/cairo-script-scanner.c     |   12 +++++++++---
 util/cairo-trace/trace.c                     |    7 +++++++
 6 files changed, 33 insertions(+), 5 deletions(-)

New commits:
commit 84e587bbfad6586e41fac86c4d19005418115ac5
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Fri Jun 19 14:41:39 2009 +0100

    [trace] Prevent a child process from writing to the same file
    
    After opening a specific file or fd for ourselves, reset the
    CAIRO_TRACE_FD to point to an invalid fd in order to prevent any child
    processes (who inherit our environment) from attempting to trace cairo
    calls. If we allow them to continue, then the two traces will intermix
    and be unreplayable.

diff --git a/util/cairo-trace/trace.c b/util/cairo-trace/trace.c
index e3ab7f1..2982c8c 100644
--- a/util/cairo-trace/trace.c
+++ b/util/cairo-trace/trace.c
@@ -709,12 +709,17 @@ _init_logfile (void)
     filename = getenv ("CAIRO_TRACE_FD");
     if (filename != NULL) {
 	int fd = atoi (filename);
+	if (fd == -1)
+	    return false;
+
 	logfile = fdopen (fd, "w");
 	if (logfile == NULL) {
 	    fprintf (stderr, "Failed to open trace file descriptor '%s': %s\n",
 		       filename, strerror (errno));
 	    return false;
 	}
+
+	setenv ("CAIRO_TRACE_FD", "-1", 1);
 	goto done;
     }
 
@@ -734,6 +739,8 @@ _init_logfile (void)
 		filename, name, getpid());
 
 	filename = buf;
+
+	setenv ("CAIRO_TRACE_FD", "-1", 1);
     }
 
     logfile = fopen (filename, "wb");
commit 18edea36ba6604e4cbdbda1ed56e6117b5768d94
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Fri Jun 19 14:14:32 2009 +0100

    [perf] Report line of error during trace
    
    Query the number of new lines processed so far and report that on hitting
    an error.

diff --git a/perf/cairo-perf-trace.c b/perf/cairo-perf-trace.c
index 3ed2bb8..6859a0d 100644
--- a/perf/cairo-perf-trace.c
+++ b/perf/cairo-perf-trace.c
@@ -258,10 +258,14 @@ execute (cairo_perf_t		 *perf,
 	status = cairo_script_interpreter_destroy (csi);
 	if (status) {
 	    if (perf->summary) {
-		fprintf (perf->summary, "Error during replay: %s\n",
+		unsigned int line_no;
+
+		line_no = cairo_script_interpreter_get_line_number (csi);
+		fprintf (perf->summary, "Error during replay, line %d: %s\n",
+			 line_no,
 			 cairo_status_to_string (status));
-		goto out;
 	    }
+	    goto out;
 	}
 
 	if (perf->raw) {
commit 55721d380d5a75a9448f522f9ad48cd18a6c2f65
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Fri Jun 19 14:13:34 2009 +0100

    [script] Report line number
    
    Count the number of newlines processed in the trace and provide an API for
    the user to query.

diff --git a/util/cairo-script/cairo-script-interpreter.c b/util/cairo-script/cairo-script-interpreter.c
index ad4a1a7..db26b00 100644
--- a/util/cairo-script/cairo-script-interpreter.c
+++ b/util/cairo-script/cairo-script-interpreter.c
@@ -567,6 +567,12 @@ cairo_script_interpreter_feed_string (csi_t *ctx, const char *line, int len)
     return ctx->status;
 }
 
+unsigned int
+cairo_script_interpreter_get_line_number (csi_t *ctx)
+{
+    return ctx->scanner.line_number + 1; /* 1 index based */
+}
+
 csi_t *
 cairo_script_interpreter_reference (csi_t *ctx)
 {
diff --git a/util/cairo-script/cairo-script-interpreter.h b/util/cairo-script/cairo-script-interpreter.h
index a9318b0..a500467 100644
--- a/util/cairo-script/cairo-script-interpreter.h
+++ b/util/cairo-script/cairo-script-interpreter.h
@@ -88,6 +88,9 @@ cairo_script_interpreter_feed_string (cairo_script_interpreter_t *ctx,
 				      const char *line,
 				      int len);
 
+cairo_public unsigned int
+cairo_script_interpreter_get_line_number (cairo_script_interpreter_t *ctx);
+
 cairo_public cairo_script_interpreter_t *
 cairo_script_interpreter_reference (cairo_script_interpreter_t *ctx);
 
diff --git a/util/cairo-script/cairo-script-private.h b/util/cairo-script/cairo-script-private.h
index d19737a..96c2044 100644
--- a/util/cairo-script/cairo-script-private.h
+++ b/util/cairo-script/cairo-script-private.h
@@ -441,6 +441,8 @@ struct _csi_scanner {
     int string_p;
     unsigned int accumulator;
     unsigned int accumulator_count;
+
+    unsigned int line_number;
 };
 
 typedef cairo_script_interpreter_hooks_t csi_hooks_t;
diff --git a/util/cairo-script/cairo-script-scanner.c b/util/cairo-script/cairo-script-scanner.c
index 538aad4..6ade97f 100644
--- a/util/cairo-script/cairo-script-scanner.c
+++ b/util/cairo-script/cairo-script-scanner.c
@@ -678,9 +678,10 @@ scan_none (csi_t *ctx,
 	csi_object_t obj = { CSI_OBJECT_TYPE_NULL };
 
 	switch (c) {
+	case 0xa:
+	    scan->line_number++;
 	case 0x0:
 	case 0x9:
-	case 0xa:
 	case 0xc:
 	case 0xd:
 	case 0x20: /* ignore whitespace */
@@ -829,9 +830,10 @@ scan_token (csi_t *ctx, csi_scanner_t *scan, csi_file_t *src)
 
     while ((c = scan_getc (scan, src)) != EOF) {
 	switch (c) {
+	case 0xa:
+	    scan->line_number++;
 	case 0x0:
 	case 0x9:
-	case 0xa:
 	case 0xc:
 	case 0xd:
 	case 0x20:
@@ -901,9 +903,10 @@ scan_hex (csi_t *ctx, csi_scanner_t *scan, csi_file_t *src)
 
     while ((c = scan_getc (scan, src)) != EOF) {
 	switch (c) {
+	case 0xa:
+	    scan->line_number++;
 	case 0x0:
 	case 0x9:
-	case 0xa:
 	case 0xc:
 	case 0xd:
 	case 0x20: /* ignore whitespace */
@@ -1056,6 +1059,7 @@ scan_string (csi_t *ctx, csi_scanner_t *scan, csi_file_t *src)
 		    scan_putc (scan, src, next);
 		    break;
 		}
+		scan->line_number++;
 		break;
 	    case 0xc:
 		break;
@@ -1098,6 +1102,7 @@ scan_comment (csi_t *ctx, csi_scanner_t *scan, csi_file_t *src)
     while ((c = scan_getc (scan, src)) != EOF) {
 	switch (c) {
 	case 0xa:
+	    scan->line_number++;
 	case 0xc:
 	    comment_end (scan);
 	    return 1;
@@ -1119,6 +1124,7 @@ _csi_scan_file (csi_t *ctx, csi_scanner_t *scan, csi_file_t *src)
 	scan_base85,
     };
 
+    scan->line_number = 0;
     while (func[scan->state] (ctx, scan, src))
 	;
 


More information about the cairo-commit mailing list