Index: trunk/src/plfill.c
===================================================================
--- trunk/src/plfill.c	(revision 11384)
+++ trunk/src/plfill.c	(working copy)
@@ -4,6 +4,9 @@
 //
 // Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009  Alan W. Irwin
 // Copyright (C) 2005, 2006, 2007, 2008, 2009  Arjen Markus
+// 2010-12-23, José Luis García Pallero, jgpallero@gmail.com
+//             Change static vectors of length PL_MAXPOLY to dynamic via
+//             malloc/free functions
 //
 // This file is part of PLplot.
 //
@@ -122,7 +125,8 @@
 // void plfill()
 //
 // Pattern fills the polygon bounded by the input points.
-// If hardware fill is used, a maximum of PL_MAXPOLY-1 vertices is allowed.
+// For a number of vertices greater than PL_MAXPOLY - 1, memory is managed via
+// malloc/free. Otherwise static arrays of length PL_MAXPOLY are used
 // The final point is explicitly added if it doesn't match up to the first,
 // to prevent clipping problems.
 //--------------------------------------------------------------------------
@@ -130,7 +134,8 @@
 void
 c_plfill( PLINT n, PLFLT *x, PLFLT *y )
 {
-    PLINT xpoly[PL_MAXPOLY], ypoly[PL_MAXPOLY];
+    PLINT _xpoly[PL_MAXPOLY], _ypoly[PL_MAXPOLY];
+    PLINT *xpoly, *ypoly;
     PLINT i;
     PLFLT xt, yt;
 
@@ -144,11 +149,21 @@
         plabort( "plfill: Not enough points in object" );
         return;
     }
+    
     if ( n > PL_MAXPOLY - 1 )
     {
-        plwarn( "plfill: too many points in polygon" );
-        n = PL_MAXPOLY;
+        if ( ( ( xpoly = (PLINT *) malloc( ( n + 1 ) * sizeof( PLINT ) ) ) == NULL ) ||
+             ( ( ypoly = (PLINT *) malloc( ( n + 1 ) * sizeof( PLINT ) ) ) == NULL ) )
+        {
+            plexit ( "plfill: Out of memory!" );
+        }
     }
+    else
+    {
+        xpoly = _xpoly;
+        ypoly = _ypoly;
+    }
+
     for ( i = 0; i < n; i++ )
     {
         TRANSFORM( x[i], y[i], &xt, &yt );
@@ -158,8 +173,7 @@
 
     if ( x[0] != x[n - 1] || y[0] != y[n - 1] )
     {
-        if ( n < PL_MAXPOLY )
-            n++;
+        n++;
         TRANSFORM( x[0], y[0], &xt, &yt );
         xpoly[n - 1] = plP_wcpcx( xt );
         ypoly[n - 1] = plP_wcpcy( yt );
@@ -167,13 +181,20 @@
 
     plP_plfclp( xpoly, ypoly, n, plsc->clpxmi, plsc->clpxma,
         plsc->clpymi, plsc->clpyma, plP_fill );
+
+    if ( n > PL_MAXPOLY - 1 )
+    {
+        free(xpoly);
+        free(ypoly);
+    }
 }
 
 //--------------------------------------------------------------------------
 // void plfill3()
 //
 // Pattern fills the polygon in 3d bounded by the input points.
-// If hardware fill is used, a maximum of PL_MAXPOLY-1 vertices is allowed.
+// For a number of vertices greater than PL_MAXPOLY - 1, memory is managed via
+// malloc/free. Otherwise static arrays of length PL_MAXPOLY are used
 // The final point is explicitly added if it doesn't match up to the first,
 // to prevent clipping problems.
 //--------------------------------------------------------------------------
@@ -181,9 +202,11 @@
 void
 c_plfill3( PLINT n, PLFLT *x, PLFLT *y, PLFLT *z )
 {
-    PLFLT tx[PL_MAXPOLY], ty[PL_MAXPOLY], tz[PL_MAXPOLY];
+    PLFLT _tx[PL_MAXPOLY], _ty[PL_MAXPOLY], _tz[PL_MAXPOLY];
+    PLFLT *tx, *ty, *tz;
     PLFLT *V[3];
-    PLINT xpoly[PL_MAXPOLY], ypoly[PL_MAXPOLY];
+    PLINT _xpoly[PL_MAXPOLY], _ypoly[PL_MAXPOLY];
+    PLINT *xpoly, *ypoly;
     PLINT i;
     PLFLT xmin, xmax, ymin, ymax, zmin, zmax, zscale;
 
@@ -197,11 +220,26 @@
         plabort( "plfill3: Not enough points in object" );
         return;
     }
+    
     if ( n > PL_MAXPOLY - 1 )
     {
-        plwarn( "plfill3: too many points in polygon" );
-        n = PL_MAXPOLY;
+        if ( ( ( tx = (PLFLT *) malloc( ( n + 1 ) * sizeof( PLFLT ) ) ) == NULL ) ||
+             ( ( ty = (PLFLT *) malloc( ( n + 1 ) * sizeof( PLFLT ) ) ) == NULL ) ||
+             ( ( ty = (PLFLT *) malloc( ( n + 1 ) * sizeof( PLFLT ) ) ) == NULL ) ||
+             ( ( xpoly = (PLINT *) malloc( ( n + 1 ) * sizeof( PLINT ) ) ) == NULL ) ||
+             ( ( ypoly = (PLINT *) malloc( ( n + 1 ) * sizeof( PLINT ) ) ) == NULL ) )
+        {
+            plexit ( "plfill3: Out of memory!" );
+        }
     }
+    else
+    {
+        tx = _tx;
+        ty = _ty;
+        tz = _tz;
+        xpoly = _xpoly;
+        ypoly = _ypoly;
+    }
 
     plP_gdom( &xmin, &xmax, &ymin, &ymax );
     plP_grange( &zscale, &zmin, &zmax );
@@ -213,8 +251,7 @@
     }
     if ( tx[0] != tx[n - 1] || ty[0] != ty[n - 1] || tz[0] != tz[n - 1] )
     {
-        if ( n < PL_MAXPOLY )
-            n++;
+        n++;
         tx[n - 1] = tx[0]; ty[n - 1] = ty[0]; tz[n - 1] = tz[0];
     }
     V[0] = tx; V[1] = ty; V[2] = tz;
@@ -244,6 +281,15 @@
 //
     plP_plfclp( xpoly, ypoly, n, plsc->clpxmi, plsc->clpxma,
         plsc->clpymi, plsc->clpyma, plP_fill );
+
+    if ( n > PL_MAXPOLY - 1 )
+    {
+        free(tx);
+        free(ty);
+        free(tz);
+        free(xpoly);
+        free(ypoly);
+    }
 }
 
 //--------------------------------------------------------------------------
