[gs-cvs] rev 8090 - trunk/gs/src

leonardo at ghostscript.com leonardo at ghostscript.com
Fri Jun 29 23:41:56 PDT 2007


Author: leonardo
Date: 2007-06-29 23:41:55 -0700 (Fri, 29 Jun 2007)
New Revision: 8090

Modified:
   trunk/gs/src/gxcldev.h
   trunk/gs/src/gxclimag.c
   trunk/gs/src/gxclpath.c
   trunk/gs/src/gxclrect.c
Log:
Fix : Expanding gxcldev.h macros, part 6.

DETAILS :

This change is algorithmically equivalent.
The purpose is to eliminate gxcldev.h macros
to simplify the debugging of the clist writer methods.

This 6th step simplifies the flow control
with removing unuseful goto and labels.
Also it updates the documentation
in gxcldev.h .


EXPECTED DIFFERENCES :

None.


Modified: trunk/gs/src/gxcldev.h
===================================================================
--- trunk/gs/src/gxcldev.h	2007-06-29 20:44:57 UTC (rev 8089)
+++ trunk/gs/src/gxcldev.h	2007-06-30 06:41:55 UTC (rev 8090)
@@ -505,52 +505,66 @@
 		   gs_logical_operation_t);
 
 /*
- * Define macros for dividing up an operation into bands, per the
- * template
-
-    FOR_RECTS[_NO_ERROR] {
-	... process rectangle x, y, width, height in band pcls ...
-    } END_RECTS[_NO_ERROR];
-
- * Note that FOR_RECTS resets y and height.  It is OK for the code that
+ * For dividing up an operation into bands, use the control pattern :
+ * 
+ *   cmd_rects_enum_t re;
+ *   RECT_ENUM_INIT(re, ry, rheight);
+ *   do {
+ *	RECT_STEP_INIT(re);
+ *	... process rectangle x, y, width, height in band pcls ...
+ *
+ *	........
+ *	continue;
+ * error_in_rect:
+ *	if (!(cdev->error_is_retryable && cdev->driver_call_nesting == 0 &&
+ *		SET_BAND_CODE(clist_VMerror_recover_flush(cdev, re.band_code)) >= 0))
+ *	    return re.band_code;
+ *	re.y -= re.height;
+ *   } while ((re.y += re.height) < re.yend);
+ *
+ * Note that RECT_STEP_INIT(re) sets re.height.  It is OK for the code that
  * processes each band to reset height to a smaller (positive) value; the
  * vertical subdivision code in copy_mono, copy_color, and copy_alpha makes
  * use of this.  The band processing code may `continue' (to reduce nesting
  * of conditionals).
  *
- * If the processing code detects an error that may be a recoverable
- * VMerror, the code may call ERROR_RECT(), which will attempt to fix the
+ * The error_in_rect code detects an error that may be a recoverable
+ * VMerror, with calling clist_VMerror_recover_flush. It will attempt to fix the
  * VMerror by flushing and closing the band and resetting the imager state,
- * and then restart emitting the entire band. Before flushing the file, the
- * 'on_error' clause of END_RECTS_ON_ERROR (defaults to the constant 1 if
- * END_RECT is used) is evaluated and tested.  The 'on_error' clause enables
- * mop-up actions to be executed before flushing, and/or selectively
- * inhibits the flush, close, reset and restart process.  Similarly, the
- * 'after_recovering' clause of END_RECTS_ON_ERROR allows an action to get
- * performed after successfully recovering.
+ * and then restart emitting the entire band.
+ * Note that re.y must not change when restarting the band.
  *
- * The band processing code may wrap an operation with TRY_RECT { ...  }
- * HANDLE_RECT_UNLESS(code, unless_action) (or HANDLE_RECT(code)). This will
+ * The band processing code may wrap a writing operation with a pattern like this : 
+ *
+ * 	do {
+ *	    code = operation(...);
+ *	} while (RECT_RECOVER(code));
+ *	if (code < 0 && SET_BAND_CODE(code))
+ *	    goto error_in_rect;
+ *
+ *
+ * This will 
  * perform local first-stage VMerror recovery, by waiting for some memory to
  * become free and then retrying the failed operation starting at the
  * TRY_RECT. If local recovery is unsuccessful, the local recovery code
- * calls ERROR_RECT.
+ * should pass control to error_in_rect.
  *
- * The band processing loop should use the _NO_ERROR macros iff it doesn't
- * call ERROR_RECT anywhere.
- *
  * In a few cases, the band processing code calls other driver procedures
  * (e.g., clist_copy_mono calls itself recursively if it must split up the
  * operation into smaller pieces) or other procedures that may attempt
  * VMerror recovery.  In such cases, the recursive call must not attempt
  * second-stage VMerror recovery, since the caller would have no way of
  * knowing that the writer state had been reset.  Such recursive calls
- * should be wrapped in NEST_RECT { ... } UNNEST_RECT, which causes
- * ERROR_RECT simply to return the error code rather than attempting
- * recovery.  (TRY/HANDLE_RECT will still attempt local recovery, as
- * described above, but this is harmless since it is transparent.) By
+ * should be wrapped in 
+ *
+ *  ++cdev->driver_call_nesting;  { ... } --cdev->driver_call_nesting;
+ *
+ * , which causes error_in_rect
+ * simply to return the error code rather than attempting
+ * recovery.  (The local recovery with do { ... } while (RECT_RECOVER(code));
+ * is still allowed since it is transparent.) By
  * convention, calls to cmd_put_xxx or cmd_set_xxx never attempt recovery
- * and so never require NEST_RECTs.
+ * and so never require  a nesting.
  *
  * If a put_params call fails, the device will be left in a closed state,
  * but higher-level code won't notice this fact.  We flag this by setting

Modified: trunk/gs/src/gxclimag.c
===================================================================
--- trunk/gs/src/gxclimag.c	2007-06-29 20:44:57 UTC (rev 8089)
+++ trunk/gs/src/gxclimag.c	2007-06-30 06:41:55 UTC (rev 8090)
@@ -111,7 +111,6 @@
 	ulong offset_temp;
 
 	RECT_STEP_INIT(re);
-retry_rect:
 	do {
 	    code = cmd_update_lop(cdev, re.pcls, lop);
 	} while (RECT_RECOVER(code));
@@ -208,13 +207,13 @@
 	    goto end;
 	}
 end:
+	re.y += re.height;
 	continue;
 error_in_rect:
-	if (cdev->error_is_retryable && cdev->driver_call_nesting == 0 &&
-		SET_BAND_CODE(clist_VMerror_recover_flush(cdev, re.band_code)) >= 0)
-	    goto retry_rect;
+	if (!(cdev->error_is_retryable && cdev->driver_call_nesting == 0 &&
+		SET_BAND_CODE(clist_VMerror_recover_flush(cdev, re.band_code)) >= 0))
 	return re.band_code;
-    } while ((re.y += re.height) < re.yend);
+    } while (re.y < re.yend);
     return 0;
 }
 
@@ -1490,27 +1489,26 @@
     RECT_ENUM_INIT(re, ry, rheight);
     do {
 	byte *dp;
-	RECT_STEP_INIT(re);
 
-retry_rect:
-	if (!(re.pcls->known & begin_image_known))
-	    continue;
-	do {
-	    if_debug1('L', "[L]image_end for band %d\n", re.band);
-	    code = set_cmd_put_op(dp, cdev, re.pcls, cmd_opv_image_data, 2);
-	} while (RECT_RECOVER(code));
-	/* HANDLE_RECT_UNLESS(code, 0); */
-	if (code < 0 && SET_BAND_CODE(code))
-	    goto error_in_rect;
-	dp[1] = 0;	    /* EOD */
-	re.pcls->known ^= begin_image_known;
+	RECT_STEP_INIT(re);
+	if (re.pcls->known & begin_image_known) {
+	    do {
+		if_debug1('L', "[L]image_end for band %d\n", re.band);
+		code = set_cmd_put_op(dp, cdev, re.pcls, cmd_opv_image_data, 2);
+	    } while (RECT_RECOVER(code));
+	    /* HANDLE_RECT_UNLESS(code, 0); */
+	    if (code < 0 && SET_BAND_CODE(code))
+		goto error_in_rect;
+	    dp[1] = 0;	    /* EOD */
+	    re.pcls->known ^= begin_image_known;
+	}
+	re.y += re.height;
 	continue;
 error_in_rect:
-	if (cdev->error_is_retryable && cdev->driver_call_nesting == 0 &&
-		SET_BAND_CODE(clist_VMerror_recover_flush(cdev, re.band_code)) >= 0)
-	    goto retry_rect;
-	return re.band_code;
-    } while ((re.y += re.height) < re.yend);
+	if (!(cdev->error_is_retryable && cdev->driver_call_nesting == 0 &&
+		SET_BAND_CODE(clist_VMerror_recover_flush(cdev, re.band_code)) >= 0))
+	   return re.band_code;
+    } while (re.y < re.yend);
     return 0;
 }
 

Modified: trunk/gs/src/gxclpath.c
===================================================================
--- trunk/gs/src/gxclpath.c	2007-06-29 20:44:57 UTC (rev 8089)
+++ trunk/gs/src/gxclpath.c	2007-06-30 06:41:55 UTC (rev 8090)
@@ -608,8 +608,8 @@
     RECT_ENUM_INIT(re, ry, rheight);
     do {
 	int code;
+
 	RECT_STEP_INIT(re);
-retry_rect:
 	code = cmd_do_write_unknown(cdev, re.pcls, FILL_KNOWN);
 	if (code < 0)
 	    return code;
@@ -631,13 +631,8 @@
 			    true, sn_none /* fill doesn't need the notes */ );
 	if (code < 0)
 	    return code;
-	continue;
-error_in_rect:
-	if (cdev->error_is_retryable && cdev->driver_call_nesting == 0 &&
-		SET_BAND_CODE(clist_VMerror_recover_flush(cdev, re.band_code)) >= 0)
-	    goto retry_rect;
-	return re.band_code;
-    } while ((re.y += re.height) < re.yend);
+	re.y += re.height;
+    } while (re.y < re.yend);
     return 0;
 }
 
@@ -751,9 +746,8 @@
     RECT_ENUM_INIT(re, ry, rheight);
     do {
 	int code;
-	RECT_STEP_INIT(re);
-retry_rect:
 
+	RECT_STEP_INIT(re);
 	if ((code = cmd_do_write_unknown(cdev, re.pcls, stroke_all_known)) < 0 ||
 	    (code = cmd_do_enable_clip(cdev, re.pcls, pcpath != NULL)) < 0 ||
 	    (code = cmd_update_lop(cdev, re.pcls, lop)) < 0
@@ -789,13 +783,8 @@
 	    if (code < 0)
 		return code;
 	}
-	continue;
-error_in_rect:
-	if (cdev->error_is_retryable && cdev->driver_call_nesting == 0 &&
-		SET_BAND_CODE(clist_VMerror_recover_flush(cdev, re.band_code)) >= 0)
-	    goto retry_rect;
-	return re.band_code;
-    } while ((re.y += re.height) < re.yend);
+	re.y += re.height;
+    } while (re.y < re.yend);
     return 0;
 }
 
@@ -842,7 +831,6 @@
     RECT_ENUM_INIT(re, ry, rheight);
     do {
 	RECT_STEP_INIT(re);
-retry_rect:
 	if ((code = cmd_update_lop(cdev, re.pcls, lop)) < 0 ||
 	    (code = cmd_put_drawing_color(cdev, re.pcls, pdcolor)) < 0)
 	    goto out;
@@ -854,13 +842,8 @@
 			    true, sn_none /* fill doesn't need the notes */ );
 	if (code < 0)
 	    goto out;
-	continue;
-error_in_rect:
-	if (cdev->error_is_retryable && cdev->driver_call_nesting == 0 &&
-		SET_BAND_CODE(clist_VMerror_recover_flush(cdev, re.band_code)) >= 0)
-	    goto retry_rect;
-	return re.band_code;
-    } while ((re.y += re.height) < re.yend);
+	re.y += re.height;
+    } while (re.y < re.yend);
 out:
     gx_path_free(&path, "clist_put_polyfill");
     return code;

Modified: trunk/gs/src/gxclrect.c
===================================================================
--- trunk/gs/src/gxclrect.c	2007-06-29 20:44:57 UTC (rev 8089)
+++ trunk/gs/src/gxclrect.c	2007-06-30 06:41:55 UTC (rev 8090)
@@ -149,7 +149,6 @@
     RECT_ENUM_INIT(re, ry, rheight);
     do {
 	RECT_STEP_INIT(re);
-retry_rect:
 	re.pcls->colors_used.or |= color;
 	re.pcls->band_complexity.uses_color |= ((color != 0xffffff) && (color != 0)); 
 	do {
@@ -164,13 +163,13 @@
 	/* HANDLE_RECT_UNLESS(code, 0); */
 	if (code < 0 && SET_BAND_CODE(code))
 	    goto error_in_rect;
+	re.y += re.height;
 	continue;
 error_in_rect:
-	if (cdev->error_is_retryable && cdev->driver_call_nesting == 0 &&
-		SET_BAND_CODE(clist_VMerror_recover_flush(cdev, re.band_code)) >= 0)
-	    goto retry_rect;
-	return re.band_code;
-    } while ((re.y += re.height) < re.yend);
+	if (!(cdev->error_is_retryable && cdev->driver_call_nesting == 0 &&
+		SET_BAND_CODE(clist_VMerror_recover_flush(cdev, re.band_code)) >= 0))
+	    return re.band_code;
+    } while (re.y < re.yend);
     return 0;
 }
 
@@ -201,7 +200,6 @@
 	ulong offset_temp;
 
 	RECT_STEP_INIT(re);
-retry_rect:
 	re.pcls->colors_used.or |= colors_used;	
 	re.pcls->band_complexity.uses_color |= 
 	    ((color0 != gx_no_color_index) && (color0 != 0xffffff) && (color0 != 0)) ||
@@ -251,13 +249,13 @@
 	if (code < 0 && SET_BAND_CODE(code))
 	    goto error_in_rect;
 endr:;
+	re.y += re.height;
 	continue;
 error_in_rect:
-	if (cdev->error_is_retryable && cdev->driver_call_nesting == 0 &&
-		SET_BAND_CODE(clist_VMerror_recover_flush(cdev, re.band_code)) >= 0)
-	    goto retry_rect;
-	return re.band_code;
-    } while ((re.y += re.height) < re.yend);
+	if (!(cdev->error_is_retryable && cdev->driver_call_nesting == 0 &&
+		SET_BAND_CODE(clist_VMerror_recover_flush(cdev, re.band_code)) >= 0))
+	    return re.band_code;
+    } while (re.y < re.yend);
     return 0;
 }
 
@@ -292,7 +290,6 @@
 	int code;
 
 	RECT_STEP_INIT(re);
-retry_rect:
 	re.pcls->colors_used.or |= colors_used;
 	re.pcls->band_complexity.uses_color |= uses_color;
 	do {
@@ -374,10 +371,10 @@
 	}
 	continue;
 error_in_rect:
-	if (cdev->error_is_retryable && cdev->driver_call_nesting == 0 &&
-		SET_BAND_CODE(clist_VMerror_recover_flush(cdev, re.band_code)) >= 0)
-	    goto retry_rect;
-	return re.band_code;
+	if (!(cdev->error_is_retryable && cdev->driver_call_nesting == 0 &&
+		SET_BAND_CODE(clist_VMerror_recover_flush(cdev, re.band_code)) >= 0))
+	    return re.band_code;
+	re.y -= re.height;
     } while ((re.y += re.height) < re.yend);
     return 0;
 }
@@ -409,7 +406,6 @@
 	int code;
 
 	RECT_STEP_INIT(re);
-retry_rect:
 	re.pcls->colors_used.or |= colors_used;
 	re.pcls->band_complexity.uses_color = 1;
 
@@ -493,10 +489,10 @@
 	}
 	continue;
 error_in_rect:
-	if (cdev->error_is_retryable && cdev->driver_call_nesting == 0 &&
-		SET_BAND_CODE(clist_VMerror_recover_flush(cdev, re.band_code)) >= 0)
-	    goto retry_rect;
-	return re.band_code;
+	if (!(cdev->error_is_retryable && cdev->driver_call_nesting == 0 &&
+		SET_BAND_CODE(clist_VMerror_recover_flush(cdev, re.band_code)) >= 0))
+	    return re.band_code;
+	re.y -= re.height;
     } while ((re.y += re.height) < re.yend);
     return 0;
 }
@@ -534,7 +530,6 @@
 	int code;
 
 	RECT_STEP_INIT(re);
-retry_rect:
 	re.pcls->colors_used.or |= color;
 	do {
 	    code = cmd_disable_lop(cdev, re.pcls);
@@ -626,10 +621,10 @@
 	}
 	continue;
 error_in_rect:
-	if (cdev->error_is_retryable && cdev->driver_call_nesting == 0 &&
-		SET_BAND_CODE(clist_VMerror_recover_flush(cdev, re.band_code)) >= 0)
-	    goto retry_rect;
-	return re.band_code;
+	if (!(cdev->error_is_retryable && cdev->driver_call_nesting == 0 &&
+		SET_BAND_CODE(clist_VMerror_recover_flush(cdev, re.band_code)) >= 0))
+	    return re.band_code;
+	re.y -= re.height;
     } while ((re.y += re.height) < re.yend);
     return 0;
 }
@@ -698,7 +693,6 @@
 
 	RECT_STEP_INIT(re);
 	D = re.pcls->colors_used.or;
-retry_rect:
 	/* Reducing D, S, T to rop_operand (which apparently is 32 bit) appears safe
 	   due to 'all' a has smaller snumber of significant bits. */
 	re.pcls->colors_used.or =
@@ -835,10 +829,10 @@
 	    goto error_in_rect;
 	continue;
 error_in_rect:
-	if (cdev->error_is_retryable && cdev->driver_call_nesting == 0 &&
-		SET_BAND_CODE(clist_VMerror_recover_flush(cdev, re.band_code)) >= 0)
-	    goto retry_rect;
-	return re.band_code;
+	if (!(cdev->error_is_retryable && cdev->driver_call_nesting == 0 &&
+		SET_BAND_CODE(clist_VMerror_recover_flush(cdev, re.band_code)) >= 0))
+	    return re.band_code;
+	re.y -= re.height;
     } while ((re.y += re.height) < re.yend);
     return 0;
 }



More information about the gs-cvs mailing list