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

leonardo at ghostscript.com leonardo at ghostscript.com
Mon Nov 13 08:10:42 PST 2006


Author: leonardo
Date: 2006-11-13 08:10:41 -0800 (Mon, 13 Nov 2006)
New Revision: 7193

Modified:
   trunk/gs/src/gxshade1.c
   trunk/gs/src/gxshade4.c
   trunk/gs/src/gxshade4.h
   trunk/gs/src/gxshade6.c
Log:
Fix (shadings) : Remove colors from C stack, part 7.

DETAILS :

This is the 7th step of fixing the bug 688955 
"64K stack overflows with shadings".
This change is algorithmically equivalent.
We hope this is the last step, which closes the bug.

1. Optimize reserve_colors_inline;
2. Remove 'assert'.
3. Disable the consistency check in release_colors_inline for faster sesult and smaller code.
4. Provide a consistency check at end of a shading fill in term_patch_fill_state.

EXPECTED DIFFERENCES :

None.


Modified: trunk/gs/src/gxshade1.c
===================================================================
--- trunk/gs/src/gxshade1.c	2006-11-13 15:34:00 UTC (rev 7192)
+++ trunk/gs/src/gxshade1.c	2006-11-13 16:10:41 UTC (rev 7193)
@@ -100,7 +100,8 @@
     curve[2].vertex.cc[0] = fp->region.q.x;   curve[2].vertex.cc[1] = fp->region.q.y;
     curve[3].vertex.cc[0] = fp->region.p.x;   curve[3].vertex.cc[1] = fp->region.q.y;
     code = patch_fill(&pfs1, curve, NULL, NULL);
-    term_patch_fill_state(&pfs1);
+    if (term_patch_fill_state(&pfs1))
+	return_error(gs_error_unregistered); /* Must not happen. */
     if (VD_TRACE_FUNCTIONAL_PATCH && vd_allowed('s'))
 	vd_release_dc;
     return code;
@@ -254,7 +255,8 @@
 	state.t0 = state.t1 = t1 * dd + d0;
 	code = A_fill_region(&state, &pfs1);
     }
-    term_patch_fill_state(&pfs1);
+    if (term_patch_fill_state(&pfs1))
+	return_error(gs_error_unregistered); /* Must not happen. */
     return code;
 }
 
@@ -704,7 +706,8 @@
     }
     if (code >= 0)
 	code = R_extensions(&pfs1, psh, rect, d0, d1, false, psh->params.Extend[1]);
-    term_patch_fill_state(&pfs1);
+    if (term_patch_fill_state(&pfs1))
+	return_error(gs_error_unregistered); /* Must not happen. */
     return code;
 }
 

Modified: trunk/gs/src/gxshade4.c
===================================================================
--- trunk/gs/src/gxshade4.c	2006-11-13 15:34:00 UTC (rev 7192)
+++ trunk/gs/src/gxshade4.c	2006-11-13 16:10:41 UTC (rev 7193)
@@ -146,7 +146,8 @@
     if (VD_TRACE_TRIANGLE_PATCH && vd_allowed('s'))
 	vd_release_dc;
     release_colors(&pfs, pfs.color_stack, 3);
-    term_patch_fill_state(&pfs);
+    if (term_patch_fill_state(&pfs))
+	return_error(gs_error_unregistered); /* Must not happen. */
     if (!cs.is_eod(&cs))
 	return_error(gs_error_rangecheck);
     return code;
@@ -241,6 +242,7 @@
     gs_free_object(pis->memory, color_buffer, "gs_shading_LfGt_render");
     gs_free_object(pis->memory, color_buffer_ptrs, "gs_shading_LfGt_render");
     release_colors(&pfs, pfs.color_stack, 1);
-    term_patch_fill_state(&pfs);
+    if (term_patch_fill_state(&pfs))
+	return_error(gs_error_unregistered); /* Must not happen. */
     return code;
 }

Modified: trunk/gs/src/gxshade4.h
===================================================================
--- trunk/gs/src/gxshade4.h	2006-11-13 15:34:00 UTC (rev 7192)
+++ trunk/gs/src/gxshade4.h	2006-11-13 16:10:41 UTC (rev 7193)
@@ -161,7 +161,7 @@
 			  gx_device * dev, gs_imager_state * pis);
 
 int init_patch_fill_state(patch_fill_state_t *pfs);
-void term_patch_fill_state(patch_fill_state_t *pfs);
+bool term_patch_fill_state(patch_fill_state_t *pfs);
 
 int mesh_triangle(patch_fill_state_t *pfs, 
     const shading_vertex_t *p0, const shading_vertex_t *p1, const shading_vertex_t *p2);

Modified: trunk/gs/src/gxshade6.c
===================================================================
--- trunk/gs/src/gxshade6.c	2006-11-13 15:34:00 UTC (rev 7192)
+++ trunk/gs/src/gxshade6.c	2006-11-13 16:10:41 UTC (rev 7193)
@@ -33,7 +33,6 @@
 #include "stdint_.h"
 #include "math_.h"
 #include "vdtrace.h"
-#include <assert.h>
 
 #define VD_TRACE_TENSOR_PATCH 1
 
@@ -76,13 +75,13 @@
     int i;
     byte *ptr = pfs->color_stack_ptr;
 
-    if (pfs->color_stack_limit - ptr < pfs->color_stack_step * n) {
+    for (i = 0; i < n; i++, ptr += pfs->color_stack_step)
+	c[i] = (patch_color_t *)ptr;
+    if (ptr > pfs->color_stack_limit) {
 	c[0] = NULL; /* safety. */
 	return NULL;
     }
-    for (i = 0; i < n; i++)
-	c[i] = (patch_color_t *)(ptr + i * pfs->color_stack_step);
-    pfs->color_stack_ptr += pfs->color_stack_step * n;
+    pfs->color_stack_ptr = ptr;
     return ptr;
 }
 
@@ -95,8 +94,12 @@
 private inline void
 release_colors_inline(patch_fill_state_t *pfs, byte *ptr, int n)
 {
-    pfs->color_stack_ptr -= pfs->color_stack_step * n;
+#if 0 /* Saving the invariant for records. */
+    pfs->color_stack_ptr = pfs->color_stack_step * n;
     assert((byte *)pfs->color_stack_ptr == ptr);
+#else
+    pfs->color_stack_ptr = ptr;
+#endif
 }
 void
 release_colors(patch_fill_state_t *pfs, byte *ptr, int n)
@@ -217,15 +220,16 @@
     return allocate_color_stack(pfs, pfs->pis->memory);
 }
 
-void
+bool
 term_patch_fill_state(patch_fill_state_t *pfs)
 {
+    bool b = (pfs->color_stack_ptr != pfs->color_stack);
 #   if LAZY_WEDGES
 	wedge_vertex_list_elem_buffer_free(pfs);
 #   endif
-    assert(pfs->color_stack_ptr == pfs->color_stack);
     if (pfs->color_stack)
 	gs_free_object(pfs->memory, pfs->color_stack, "term_patch_fill_state");
+    return b;
 }
 
 /* Resolve a patch color using the Function if necessary. */
@@ -391,7 +395,8 @@
     }
     if (VD_TRACE_TENSOR_PATCH && vd_allowed('s'))
 	vd_release_dc;
-    term_patch_fill_state(&state);
+    if (term_patch_fill_state(&state))
+	return_error(gs_error_unregistered); /* Must not happen. */
     return min(code, 0);
 }
 
@@ -491,7 +496,8 @@
 	if (code < 0)
 	    break;
     }
-    term_patch_fill_state(&state);
+    if (term_patch_fill_state(&state))
+	return_error(gs_error_unregistered); /* Must not happen. */
     if (VD_TRACE_TENSOR_PATCH && vd_allowed('s'))
 	vd_release_dc;
     return min(code, 0);



More information about the gs-cvs mailing list