dynamic allocation in ImagePolygon
| From: | Marc Pohl | Date: | Mon, 01 May 2000 19:36:33 +0000 |
| Subject: | dynamic allocation in ImagePolygon | ||
| Groups: | php.version4 | ||
| Request: | Send a blank email to php-version4+get-14284@lists.php.net to get a copy of this message | ||
Hi!
While testing PHP-4.0RC1 i discovered that there is a fixed upper limit of 256 poly vertices in
ImagePolygon. I changed this to a dynamic allocation with no upper limit. This consumes less memory
in most cases, but you are also able to draw a circle with 360 polygon vertices ;-). (The patch is
attached)
Marc
--- gd.c.orig Sun Apr 30 23:58:27 2000
+++ gd.c Mon May 1 13:17:59 2000
@@ -173,8 +173,6 @@
#endif
-#define PolyMaxPoints 256
-
static void php_free_gd_font(gdFontPtr fp)
{
if (fp->data) {
@@ -1395,7 +1393,7 @@
zval **IM, **POINTS, **NPOINTS, **COL;
pval **var = NULL;
gdImagePtr im;
- gdPoint points[PolyMaxPoints];
+ gdPointPtr points;
int npoints, col, nelem, i;
GDLS_FETCH();
@@ -1441,8 +1439,9 @@
RETURN_FALSE;
}
- if (npoints > PolyMaxPoints) {
- php_error(E_WARNING, "maximum %d points", PolyMaxPoints);
+ points = (gdPointPtr) emalloc(npoints * sizeof(gdPoint));
+ if (points == NULL) {
+ php_error(E_WARNING, "ImagePolygon: Memory allocation fault");
RETURN_FALSE;
}
@@ -1465,6 +1464,8 @@
else {
gdImagePolygon(im, points, npoints, col);
}
+
+ efree(points);
RETURN_TRUE;
}
------------------------------------------------------------------------------
Marc Pohl, Service-Center-Infrastruktur, Westdeutscher Rundfunk, D-50600 Koeln
marc.pohl@wdr.de, +49 221 220 8618, http://www.wdr.de/
------------------------------------------------------------------------------