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

leonardo at ghostscript.com leonardo at ghostscript.com
Tue Jun 26 09:25:43 PDT 2007


Author: leonardo
Date: 2007-06-26 09:25:42 -0700 (Tue, 26 Jun 2007)
New Revision: 8078

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 1.

DETAILS :

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

This first step removes simple macros and optimized macro duplicates.
Removing others to be done in the next step.

Some compilers may claim unreferenced label error_in_rect.
To be fixed in the next step.

EXPECTED DIFFERENCES :

None.


Modified: trunk/gs/src/gxcldev.h
===================================================================
--- trunk/gs/src/gxcldev.h	2007-06-26 15:58:26 UTC (rev 8077)
+++ trunk/gs/src/gxcldev.h	2007-06-26 16:25:42 UTC (rev 8078)
@@ -562,29 +562,12 @@
  * stupid compilers from giving "statement not reached" warnings.
  */
 
-#define FOR_RECTS_NO_ERROR\
-    BEGIN\
-	int yend = y + height;\
-	int band_height = cdev->page_band_height;\
-	/* no band_code */\
-\
-	if (cdev->permanent_error < 0)\
-	  return (cdev->permanent_error);\
-	do {\
-	    int band = y / band_height;\
-	    gx_clist_state *pcls = cdev->states + band;\
-	    int band_end = (band + 1) * band_height;\
-\
-	    height = min(band_end, yend) - y;\
-/* no retry_rect: */
 #define FOR_RECTS\
     BEGIN\
 	int yend = y + height;\
 	int band_height = cdev->page_band_height;\
 	int band_code;\
 \
-	if (cdev->permanent_error < 0)\
-	  return (cdev->permanent_error);\
 	do {\
 	    int band = y / band_height;\
 	    gx_clist_state *pcls = cdev->states + band;\
@@ -593,25 +576,17 @@
 	    height = min(band_end, yend) - y;\
 retry_rect:\
 	    ;
-#define NEST_RECT    ++cdev->driver_call_nesting;
-#define UNNEST_RECT  --cdev->driver_call_nesting
-#define ERROR_RECT(code_value)\
-		BEGIN\
-		    band_code = (code_value);\
-		    if (1) goto error_in_rect;\
-		END
 #define TRY_RECT\
-		BEGIN\
 		    do
 #define HANDLE_RECT_UNLESS(codevar, unless_clause)\
 		    while (codevar < 0 &&\
 			   (codevar = clist_VMerror_recover(cdev, codevar)) >= 0\
 			   );\
 		    if (codevar < 0 && !(unless_clause))\
-			ERROR_RECT(codevar);\
-		END
-#define HANDLE_RECT(codevar)\
-		HANDLE_RECT_UNLESS(codevar, 0)
+			BEGIN\
+			    band_code = (codevar);\
+			    goto error_in_rect;\
+			END;
 #define END_RECTS_ON_ERROR(retry_cleanup, is_error, after_recovering)\
 	    continue;\
 error_in_rect:\
@@ -625,13 +600,10 @@
 			)\
 			goto retry_rect;\
 		}\
-		if (1) return band_code;\
+		return band_code;\
 	} while ((y += height) < yend);\
     END
 #define END_RECTS END_RECTS_ON_ERROR(DO_NOTHING, 1, 1)
-#define END_RECTS_NO_ERROR\
-	} while ((y += height) < yend);\
-    END
 
 /* ------ Exported by gxclrect.c ------ */
 

Modified: trunk/gs/src/gxclimag.c
===================================================================
--- trunk/gs/src/gxclimag.c	2007-06-26 15:58:26 UTC (rev 8077)
+++ trunk/gs/src/gxclimag.c	2007-06-26 16:25:42 UTC (rev 8078)
@@ -102,32 +102,34 @@
     if (cmd_check_clip_path(cdev, pcpath))
 	cmd_clear_known(cdev, clip_path_known);
     data_x_bit = data_x << log2_depth;
+    if (cdev->permanent_error < 0)
+      return (cdev->permanent_error);
     FOR_RECTS {
 	int code;
         ulong offset_temp;
 
 	TRY_RECT {
 	    code = cmd_update_lop(cdev, pcls, lop);
-	} HANDLE_RECT(code);
+	} HANDLE_RECT_UNLESS(code, 0);
 	if (depth > 1 && !pcls->color_is_alpha) {
 	    byte *dp;
 
 	    TRY_RECT {
 		code =
 		    set_cmd_put_op(dp, cdev, pcls, cmd_opv_set_copy_alpha, 1);
-	    } HANDLE_RECT(code);
+	    } HANDLE_RECT_UNLESS(code, 0);
 	    pcls->color_is_alpha = 1;
 	}
 	TRY_RECT {
 	    code = cmd_do_write_unknown(cdev, pcls, clip_path_known);
 	    if (code >= 0)
 		code = cmd_do_enable_clip(cdev, pcls, pcpath != NULL);
-	} HANDLE_RECT(code);
+	} HANDLE_RECT_UNLESS(code, 0);
 	TRY_RECT {
 	    code = cmd_put_drawing_color(cdev, pcls, pdcolor);
 	    if (depth > 1 && code >= 0)
 		code = cmd_set_color1(cdev, pcls, pdcolor->colors.pure);
-	} HANDLE_RECT(code);
+	} HANDLE_RECT_UNLESS(code, 0);
 	pcls->colors_used.slow_rop |= slow_rop;
 	pcls->band_complexity.nontrivial_rops |= slow_rop;
 	pcls->band_complexity.uses_color |= (pdcolor->colors.pure != 0 && pdcolor->colors.pure != 0xffffff);
@@ -180,7 +182,7 @@
 		        cmd_putxy(rect, dp);
 		    }
 		}
-	    } HANDLE_RECT(code);
+	    } HANDLE_RECT_UNLESS(code, 0);
 	    pcls->rect = rect;
 	    goto end;
 	}
@@ -520,6 +522,26 @@
 					pdcolor, pcpath, mem, pinfo);
 }
 
+/* Error cleanup for clist_image_plane_data. */
+private inline int
+clist_image_plane_data_retry_cleanup(gx_device *dev, clist_image_enum *pie, int yh_used, int code)
+{
+    gx_device_clist_writer * const cdev =
+	&((gx_device_clist *)dev)->writer;
+
+    ++cdev->ignore_lo_mem_warnings;
+    ++cdev->driver_call_nesting; /* NEST_RECT */ 
+    {
+	code = write_image_end_all(dev, pie);
+    } 
+    --cdev->driver_call_nesting; /* UNNEST_RECT */
+    --cdev->ignore_lo_mem_warnings;
+    /* Update sub-rect */
+    if (!pie->image.Interpolate)
+        pie->rect.p.y += yh_used;  /* interpolate & mem recovery currently incompat */
+    return code;
+}
+
 /* Process the next piece of an image. */
 private int
 clist_image_plane_data(gx_image_enum_common_t * info,
@@ -593,6 +615,8 @@
 	height = min(ROUND_UP(ry1, band_height), dev->height) - y;
     }
 
+    if (cdev->permanent_error < 0)
+      return (cdev->permanent_error);
     FOR_RECTS {
 	/*
 	 * Just transmit the subset of the data that intersects this band.
@@ -649,11 +673,11 @@
 		    code = cmd_do_enable_clip(cdev, pcls, pie->pcpath != NULL);
 		if (code >= 0)
 		    code = cmd_update_lop(cdev, pcls, lop);
-	    } HANDLE_RECT(code);
+	    } HANDLE_RECT_UNLESS(code, 0);
 	    if (pie->uses_color) {
  	        TRY_RECT {
 		    code = cmd_put_drawing_color(cdev, pcls, &pie->dcolor);
-		} HANDLE_RECT(code);
+		} HANDLE_RECT_UNLESS(code, 0);
 	    }
 	    if (entire_box.p.x != 0 || entire_box.p.y != 0 ||
 		entire_box.q.x != pie->image.Width ||
@@ -668,7 +692,7 @@
 	    TRY_RECT {
 		code =
 		    set_cmd_put_op(dp, cdev, pcls, image_op, 1 + len);
-	    } HANDLE_RECT(code);
+	    } HANDLE_RECT_UNLESS(code, 0);
 	    memcpy(dp + 1, pie->begin_image_command, len);
  
 	    /* Mark band's begin_image as known */
@@ -723,22 +747,13 @@
 		    code = cmd_image_plane_data(cdev, pcls, planes, info,
 						bytes_per_plane, offsets,
 						xoff - xskip, nrows);
-		} HANDLE_RECT(code);
+		} HANDLE_RECT_UNLESS(code, 0);
 		for (i = 0; i < num_planes; ++i)
 		    offsets[i] += planes[i].raster * nrows;
 	    }
 	}
     } END_RECTS_ON_ERROR(
-	BEGIN
-	    ++cdev->ignore_lo_mem_warnings;
-	    NEST_RECT {
-		code = write_image_end_all(dev, pie);
-	    } UNNEST_RECT;
-	    --cdev->ignore_lo_mem_warnings;
-	    /* Update sub-rect */
-	    if (!pie->image.Interpolate)
-	        pie->rect.p.y += yh_used;  /* interpolate & mem recovery currently incompat */
-	END,
+	code = clist_image_plane_data_retry_cleanup(dev, pie, yh_used, code),
 	(code < 0 ? (band_code = code) : code) >= 0,
 	(cmd_clear_known(cdev,
 			 clist_image_unknowns(dev, pie) | begin_image_known),
@@ -767,7 +782,8 @@
 	return_error(gs_error_Fatal);
     }
 #endif
-    NEST_RECT {
+    ++cdev->driver_call_nesting; /* NEST_RECT */ 
+    {
 	do {
 	    code = write_image_end_all(dev, pie);
 	} while (code < 0 && cdev->error_is_retryable &&
@@ -782,7 +798,8 @@
 	    if (retry_code >= 0 && cdev->driver_call_nesting == 0)
 		code = clist_VMerror_recover_flush(cdev, code);
 	}
-    } UNNEST_RECT;
+    } 
+    --cdev->driver_call_nesting; /* UNNEST_RECT */
     cdev->image_enum_id = gs_no_id;
     gs_free_object(pie->memory, pie, "clist_image_end_image");
     return code;
@@ -1414,6 +1431,8 @@
      */
     if (height <= 0)
 	return 0;
+    if (cdev->permanent_error < 0)
+      return (cdev->permanent_error);
     FOR_RECTS {
 	byte *dp;
 
@@ -1422,7 +1441,7 @@
 	TRY_RECT {
 	    if_debug1('L', "[L]image_end for band %d\n", band);
 	    code = set_cmd_put_op(dp, cdev, pcls, cmd_opv_image_data, 2);
-	} HANDLE_RECT(code);
+	} HANDLE_RECT_UNLESS(code, 0);
 	dp[1] = 0;	    /* EOD */
 	pcls->known ^= begin_image_known;
     } END_RECTS;

Modified: trunk/gs/src/gxclpath.c
===================================================================
--- trunk/gs/src/gxclpath.c	2007-06-26 15:58:26 UTC (rev 8077)
+++ trunk/gs/src/gxclpath.c	2007-06-26 16:25:42 UTC (rev 8078)
@@ -602,7 +602,9 @@
 			 &unknown);
     if (unknown)
 	cmd_clear_known(cdev, unknown);
-    FOR_RECTS_NO_ERROR {
+    if (cdev->permanent_error < 0)
+      return (cdev->permanent_error);
+    FOR_RECTS {
 	int code = cmd_do_write_unknown(cdev, pcls, FILL_KNOWN);
 
 	if (code < 0)
@@ -625,7 +627,7 @@
 			    true, sn_none /* fill doesn't need the notes */ );
 	if (code < 0)
 	    return code;
-    } END_RECTS_NO_ERROR;
+    } END_RECTS;
     return 0;
 }
 
@@ -733,7 +735,9 @@
     }
     if (unknown)
 	cmd_clear_known(cdev, unknown);
-    FOR_RECTS_NO_ERROR {
+    if (cdev->permanent_error < 0)
+      return (cdev->permanent_error);
+    FOR_RECTS {
 	int code;
 
 	if ((code = cmd_do_write_unknown(cdev, pcls, stroke_all_known)) < 0 ||
@@ -771,7 +775,7 @@
 	    if (code < 0)
 		return code;
 	}
-    } END_RECTS_NO_ERROR;
+    } END_RECTS;
     return 0;
 }
 
@@ -812,7 +816,9 @@
 	return 0;
     y0 = y;
     y1 = y + height;
-    FOR_RECTS_NO_ERROR {
+    if (cdev->permanent_error < 0)
+      return (cdev->permanent_error);
+    FOR_RECTS {
 	if ((code = cmd_update_lop(cdev, pcls, lop)) < 0 ||
 	    (code = cmd_put_drawing_color(cdev, pcls, pdcolor)) < 0)
 	    goto out;
@@ -824,7 +830,7 @@
 			    true, sn_none /* fill doesn't need the notes */ );
 	if (code < 0)
 	    goto out;
-    } END_RECTS_NO_ERROR;
+    } END_RECTS;
 out:
     gx_path_free(&path, "clist_put_polyfill");
     return code;

Modified: trunk/gs/src/gxclrect.c
===================================================================
--- trunk/gs/src/gxclrect.c	2007-06-26 15:58:26 UTC (rev 8077)
+++ trunk/gs/src/gxclrect.c	2007-06-26 16:25:42 UTC (rev 8078)
@@ -143,6 +143,8 @@
     int code;
 
     fit_fill(dev, x, y, width, height);
+    if (cdev->permanent_error < 0)
+      return (cdev->permanent_error);
     FOR_RECTS {
 	pcls->colors_used.or |= color;
 	pcls->band_complexity.uses_color |= ((color != 0xffffff) && (color != 0)); 
@@ -154,7 +156,7 @@
 	    if (code >= 0)
 		code = cmd_write_rect_cmd(cdev, pcls, cmd_op_fill_rect, x, y,
 					  width, height);
-	} HANDLE_RECT(code);
+	} HANDLE_RECT_UNLESS(code, 0);
     } END_RECTS;
     return 0;
 }
@@ -178,6 +180,8 @@
     int code;
 
     fit_fill(dev, x, y, width, height);
+    if (cdev->permanent_error < 0)
+      return (cdev->permanent_error);
     FOR_RECTS {
 	ulong offset_temp;
 
@@ -188,7 +192,7 @@
 
 	TRY_RECT {
 	    code = cmd_disable_lop(cdev, pcls);
-	} HANDLE_RECT(code);
+	} HANDLE_RECT_UNLESS(code, 0);
 	if (!cls_has_tile_id(cdev, pcls, tile->id, offset_temp)) {
 	    code = 0;
 	    if (tile->id != gx_no_bitmap_id) {
@@ -204,8 +208,10 @@
 						       x, y, width, height,
 						       color0, color1,
 						       px, py);
-		if (code < 0)
-		    ERROR_RECT(code);
+		if (code < 0) {
+		    band_code = code;
+		    goto error_in_rect; /* ERROR_RECT(code); */
+		}
 		goto endr;
 	    }
 	}
@@ -220,7 +226,7 @@
 	    if (code >= 0)
 		code = cmd_write_rect_cmd(cdev, pcls, cmd_op_tile_rect, x, y,
 					  width, height);
-	} HANDLE_RECT(code);
+	} HANDLE_RECT_UNLESS(code, 0);
 endr:;
     } END_RECTS;
     return 0;
@@ -246,6 +252,8 @@
 
     fit_copy(dev, data, data_x, raster, id, x, y, width, height);
     y0 = y;
+    if (cdev->permanent_error < 0)
+      return (cdev->permanent_error);
     FOR_RECTS {
 	int dx = data_x & 7;
 	int w1 = dx + width;
@@ -263,7 +271,7 @@
 		code = cmd_set_color0(cdev, pcls, color0);
 	    if (color1 != pcls->colors[1] && code >= 0)
 		code = cmd_set_color1(cdev, pcls, color1);
-	} HANDLE_RECT(code);
+	} HANDLE_RECT_UNLESS(code, 0);
 	/* Don't bother to check for a possible cache hit: */
 	/* tile_rectangle and fill_mask handle those cases. */
 copy:{
@@ -299,7 +307,8 @@
 		/* Split a single (very long) row. */
 		int w2 = w1 >> 1;
 
-		NEST_RECT {
+		++cdev->driver_call_nesting; /* NEST_RECT */ 
+		{
 		    code = clist_copy_mono(dev, row, dx,
 					   raster, gx_no_bitmap_id, x, y,
 					   w2, 1, color0, color1);
@@ -308,9 +317,12 @@
 					       raster, gx_no_bitmap_id,
 					       x + w2, y,
 					       w1 - w2, 1, color0, color1);
-		} UNNEST_RECT;
-		if (code < 0)
-		    ERROR_RECT(code);
+		} 
+		--cdev->driver_call_nesting; /* UNNEST_RECT */
+		if (code < 0) {
+		    band_code = code;
+		    goto error_in_rect; /* ERROR_RECT(code); */
+		}
 		continue;
 	    }
 	}
@@ -344,6 +356,8 @@
     fit_copy(dev, data, data_x, raster, id, x, y, width, height);
     y0 = y;
     data_x_bit = data_x * depth;
+    if (cdev->permanent_error < 0)
+      return (cdev->permanent_error);
     FOR_RECTS {
 	int dx = (data_x_bit & 7) / depth;
 	int w1 = dx + width;
@@ -357,14 +371,14 @@
 	    code = cmd_disable_lop(cdev, pcls);
 	    if (code >= 0)
 		code = cmd_disable_clip(cdev, pcls);
-	} HANDLE_RECT(code);
+	} HANDLE_RECT_UNLESS(code, 0);
 	if (pcls->color_is_alpha) {
 	    byte *dp;
 
 	    TRY_RECT {
 		code =
 		    set_cmd_put_op(dp, cdev, pcls, cmd_opv_set_copy_color, 1);
-	    } HANDLE_RECT(code);
+	    } HANDLE_RECT_UNLESS(code, 0);
 	    pcls->color_is_alpha = 0;
 	}
 copy:{
@@ -396,7 +410,8 @@
 		    /* Split a single (very long) row. */
 		    int w2 = w1 >> 1;
 
-		    NEST_RECT {
+		    ++cdev->driver_call_nesting; /* NEST_RECT */ 
+		    {
 			code = clist_copy_color(dev, row, dx,
 						raster, gx_no_bitmap_id,
 						x, y, w2, 1);
@@ -404,9 +419,12 @@
 			    code = clist_copy_color(dev, row, dx + w2,
 						    raster, gx_no_bitmap_id,
 						    x + w2, y, w1 - w2, 1);
-		    } UNNEST_RECT;
-		    if (code < 0)
-			ERROR_RECT(code);
+		    } 
+		    --cdev->driver_call_nesting; /* UNNEST_RECT */
+		    if (code < 0) {
+			band_code = code;
+			goto error_in_rect; /* ERROR_RECT(code); */
+		    }
 		    continue;
 		}
 	    }
@@ -446,6 +464,8 @@
     fit_copy(dev, data, data_x, raster, id, x, y, width, height);
     y0 = y;
     data_x_bit = data_x << log2_depth;
+    if (cdev->permanent_error < 0)
+      return (cdev->permanent_error);
     FOR_RECTS {
 	int dx = (data_x_bit & 7) >> log2_depth;
 	int w1 = dx + width;
@@ -457,20 +477,20 @@
 	    code = cmd_disable_lop(cdev, pcls);
 	    if (code >= 0)
 		code = cmd_disable_clip(cdev, pcls);
-	} HANDLE_RECT(code);
+	} HANDLE_RECT_UNLESS(code, 0);
 	if (!pcls->color_is_alpha) {
 	    byte *dp;
 
 	    TRY_RECT {
 		code =
 		    set_cmd_put_op(dp, cdev, pcls, cmd_opv_set_copy_alpha, 1);
-	    } HANDLE_RECT(code);
+	    } HANDLE_RECT_UNLESS(code, 0);
 	    pcls->color_is_alpha = 1;
 	}
 	if (color != pcls->colors[1]) {
 	    TRY_RECT {
 		code = cmd_set_color1(cdev, pcls, color);
-	    } HANDLE_RECT(code);
+	    } HANDLE_RECT_UNLESS(code, 0);
 	}
 copy:{
 	    gx_cmd_rect rect;
@@ -501,7 +521,8 @@
 		    /* Split a single (very long) row. */
 		    int w2 = w1 >> 1;
 
-		    NEST_RECT {
+		    ++cdev->driver_call_nesting; /* NEST_RECT */ 
+		    {
 			code = clist_copy_alpha(dev, row, dx,
 						raster, gx_no_bitmap_id, x, y,
 						w2, 1, color, depth);
@@ -510,9 +531,12 @@
 						    raster, gx_no_bitmap_id,
 						    x + w2, y, w1 - w2, 1,
 						    color, depth);
-		    } UNNEST_RECT;
-		    if (code < 0)
-			ERROR_RECT(code);
+		    } 
+		    --cdev->driver_call_nesting; /* UNNEST_RECT */
+		    if (code < 0) {
+			band_code = code;
+			goto error_in_rect; /* ERROR_RECT(code); */
+		    }
 		    continue;
 		}
 	    }
@@ -588,6 +612,8 @@
      * We shouldn't need to put the logic below inside FOR/END_RECTS,
      * but the lop_enabled flags are per-band.
      */
+    if (cdev->permanent_error < 0)
+      return (cdev->permanent_error);
     FOR_RECTS {
 	const byte *row = sdata + (y - y0) * sraster;
 	gx_color_index D = pcls->colors_used.or;
@@ -652,7 +678,8 @@
 			     * we may as well use the current tile phase
 			     * so we don't have to write extra commands.
 			     */
-			    NEST_RECT {
+			    ++cdev->driver_call_nesting; /* NEST_RECT */ 
+			    {
 				code = clist_strip_copy_rop(dev,
 					(sdata == 0 ? 0 : row + iy * sraster),
 					sourcex, sraster,
@@ -660,9 +687,12 @@
 					&line_tile, tcolors,
 					x, y + iy, width, 1,
 					phase_x, pcls->tile_phase.y, lop);
-			    } UNNEST_RECT;
-			    if (code < 0)
-				ERROR_RECT(code);
+			    } 
+			    --cdev->driver_call_nesting; /* UNNEST_RECT */
+			    if (code < 0) {
+				band_code = code;
+				goto error_in_rect; /* ERROR_RECT(code); */
+			    }
 			}
 			continue;
 		    }
@@ -672,7 +702,7 @@
 			TRY_RECT {
 			    code = cmd_set_tile_phase(cdev, pcls, phase_x,
 						      phase_y);
-			} HANDLE_RECT(code);
+			} HANDLE_RECT_UNLESS(code, 0);
 		    }
 		}
 	    }
@@ -683,7 +713,7 @@
 		     cmd_set_tile_colors(cdev, pcls, tcolors[0], tcolors[1]) :
 		     cmd_set_tile_colors(cdev, pcls, gx_no_color_index,
 					 gx_no_color_index));
-	    } HANDLE_RECT(code);
+	    } HANDLE_RECT_UNLESS(code, 0);
 	}
 	TRY_RECT {
 	    code = 0;
@@ -691,12 +721,13 @@
 		code = cmd_set_lop(cdev, pcls, lop);
 	    if (code >= 0)
 		code = cmd_enable_lop(cdev, pcls);
-	} HANDLE_RECT(code);
+	} HANDLE_RECT_UNLESS(code, 0);
 
 	/* Set lop_enabled to -1 so that fill_rectangle / copy_* */
 	/* won't attempt to set it to 0. */
 	pcls->lop_enabled = -1;
-	NEST_RECT {
+	++cdev->driver_call_nesting; /* NEST_RECT */ 
+	{
 	    if (scolors != 0) {
 		if (scolors[0] == scolors[1])
 		    code = clist_fill_rectangle(dev, x, y, width, height,
@@ -708,10 +739,13 @@
 	    } else
 		code = clist_copy_color(dev, row, sourcex, sraster, id,
 					x, y, width, height);
-	} UNNEST_RECT;
+	} 
+	--cdev->driver_call_nesting; /* UNNEST_RECT */
 	pcls->lop_enabled = 1;
-	if (code < 0)
-	    ERROR_RECT(code);
+	if (code < 0) {
+	    band_code = code;
+	    goto error_in_rect; /* ERROR_RECT(code); */
+	}
     } END_RECTS;
     return 0;
 }



More information about the gs-cvs mailing list