Skip to content

Commit a330635

Browse files
committed
Removed check on image free, fixed evaluating zval offset, fixed ce flags, tabs
1 parent 449eb47 commit a330635

File tree

2 files changed

+30
-56
lines changed

2 files changed

+30
-56
lines changed

ext/gd/gd.c

Lines changed: 28 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
#include "gd_compat.h"
6060
#include "gd_image_object.h"
6161

62-
static int le_gd, le_gd_font;
62+
static int le_gd_font;
6363

6464
#include <gd.h>
6565
#include <gd_errors.h>
@@ -68,7 +68,6 @@ static int le_gd, le_gd_font;
6868
#include <gdfontmb.h> /* 3 Medium bold font */
6969
#include <gdfontl.h> /* 4 Large font */
7070
#include <gdfontg.h> /* 5 Giant font */
71-
#include <zend.h>
7271

7372
#if defined(HAVE_GD_FREETYPE) && defined(HAVE_GD_BUNDLED)
7473
# include <ft2build.h>
@@ -308,14 +307,6 @@ PHP_INI_BEGIN()
308307
PHP_INI_END()
309308
/* }}} */
310309

311-
/* {{{ php_free_gd_image
312-
*/
313-
static void php_free_gd_image(zend_resource *rsrc)
314-
{
315-
gdImageDestroy((gdImagePtr) rsrc->ptr);
316-
}
317-
/* }}} */
318-
319310
/* {{{ php_free_gd_font
320311
*/
321312
static void php_free_gd_font(zend_resource *rsrc)
@@ -374,13 +365,12 @@ static zend_object* gd_ext_image_object_create(zend_class_entry * class_type) {
374365
return &intern->std;
375366
};
376367

368+
377369
static void gd_ext_image_object_free(zend_object* intern) {
378-
gd_ext_image_object* img_obj_ptr = gd_ext_image_object_from_ptr(intern);
379-
if (img_obj_ptr->image != NULL) {
380-
gdImageDestroy(img_obj_ptr->image);
381-
img_obj_ptr->image = NULL;
382-
}
383-
zend_object_std_dtor(intern);
370+
gd_ext_image_object* img_obj_ptr = gd_ext_image_object_from_ptr(intern);
371+
gdImageDestroy(img_obj_ptr->image);
372+
img_obj_ptr->image = NULL;
373+
zend_object_std_dtor(intern);
384374
};
385375

386376
static zend_object* gd_ext_image_object_init(zval* val, gdImagePtr image) {
@@ -393,28 +383,20 @@ static zend_object* gd_ext_image_object_init(zval* val, gdImagePtr image) {
393383
*/
394384
PHP_MINIT_FUNCTION(gd)
395385
{
396-
le_gd = zend_register_list_destructors_ex(php_free_gd_image, NULL, "gd", module_number);
397386
le_gd_font = zend_register_list_destructors_ex(php_free_gd_font, NULL, "gd font", module_number);
398387

399-
/*
400-
* Class instance that represents a GD image that has been created.
401-
*
402-
* This replaces the use of resources
403-
*/
404-
405-
zend_class_entry ce;
406-
INIT_CLASS_ENTRY(ce, "GdImage", gd_image_methods);
407-
ce.ce_flags |= ZEND_ACC_FINAL;
408-
ce.create_object = gd_ext_image_object_create;
409-
gd_image_ce = zend_register_internal_class(&ce);
388+
zend_class_entry ce;
389+
INIT_CLASS_ENTRY(ce, "GdImage", gd_image_methods);
390+
gd_image_ce = zend_register_internal_class(&ce);
391+
gd_image_ce->ce_flags |= ZEND_ACC_FINAL;
392+
gd_image_ce->create_object = gd_ext_image_object_create;
410393

411394
/* setting up the object handlers for the GdImage class */
412-
memcpy(&gd_ext_image_object_handlers, &std_object_handlers, sizeof(zend_object_handlers));
413-
gd_ext_image_object_handlers.free_obj = gd_ext_image_object_free;
395+
memcpy(&gd_ext_image_object_handlers, &std_object_handlers, sizeof(zend_object_handlers));
396+
gd_ext_image_object_handlers.free_obj = gd_ext_image_object_free;
414397
gd_ext_image_object_handlers.offset = XtOffsetOf(gd_ext_image_object, std);
415398

416399

417-
418400
#if defined(HAVE_GD_FREETYPE) && defined(HAVE_GD_BUNDLED)
419401
gdFontCacheMutexSetup();
420402
#endif
@@ -722,13 +704,6 @@ PHP_FUNCTION(gd_info)
722704
}
723705
/* }}} */
724706

725-
/* Need this for cpdf. See also comment in file.c php3i_get_le_fp() */
726-
PHP_GD_API int phpi_get_le_gd(void)
727-
{
728-
return le_gd;
729-
}
730-
/* }}} */
731-
732707
#define FLIPWORD(a) (((a & 0xff000000) >> 24) | ((a & 0x00ff0000) >> 8) | ((a & 0x0000ff00) << 8) | ((a & 0x000000ff) << 24))
733708

734709
/* {{{ proto int imageloadfont(string filename)
@@ -1495,7 +1470,7 @@ PHP_FUNCTION(imagecreate)
14951470
RETURN_FALSE;
14961471
}
14971472

1498-
RETURN_OBJ(gd_ext_image_object_init(return_value, im));
1473+
RETURN_OBJ(gd_ext_image_object_init(return_value, im));
14991474
}
15001475
/* }}} */
15011476

@@ -1695,7 +1670,7 @@ PHP_FUNCTION(imagecreatefromstring)
16951670
RETURN_FALSE;
16961671
}
16971672

1698-
RETURN_OBJ(gd_ext_image_object_init(return_value, im));
1673+
RETURN_OBJ(gd_ext_image_object_init(return_value, im));
16991674
}
17001675
/* }}} */
17011676

@@ -1812,7 +1787,7 @@ static void _php_image_create_from(INTERNAL_FUNCTION_PARAMETERS, int image_type,
18121787

18131788
/* register_im: */
18141789
if (im) {
1815-
RETVAL_OBJ(gd_ext_image_object_init(return_value, im));
1790+
RETVAL_OBJ(gd_ext_image_object_init(return_value, im));
18161791
php_stream_close(stream);
18171792
return;
18181793
}
@@ -3116,7 +3091,7 @@ PHP_FUNCTION(imagecopyresized)
31163091
dstW = DW;
31173092

31183093
if (dstW <= 0 || dstH <= 0 || srcW <= 0 || srcH <= 0) {
3119-
zend_value_error( "Invalid image dimensions");
3094+
zend_value_error("Invalid image dimensions");
31203095
RETURN_FALSE;
31213096
}
31223097

@@ -3361,7 +3336,7 @@ static void php_image_filter_brightness(INTERNAL_FUNCTION_PARAMETERS)
33613336
return;
33623337
}
33633338

3364-
im_src = GD_IMAGE_PTR_FROM_ZVAL_P(SIM);
3339+
im_src = GD_IMAGE_PTR_FROM_ZVAL_P(SIM);
33653340

33663341
if (gdImageBrightness(im_src, (int)brightness) == 1) {
33673342
RETURN_TRUE;
@@ -3380,7 +3355,7 @@ static void php_image_filter_contrast(INTERNAL_FUNCTION_PARAMETERS)
33803355
return;
33813356
}
33823357

3383-
im_src = GD_IMAGE_PTR_FROM_ZVAL_P(SIM);
3358+
im_src = GD_IMAGE_PTR_FROM_ZVAL_P(SIM);
33843359

33853360
if (gdImageContrast(im_src, (int)contrast) == 1) {
33863361
RETURN_TRUE;
@@ -3400,8 +3375,8 @@ static void php_image_filter_colorize(INTERNAL_FUNCTION_PARAMETERS)
34003375
return;
34013376
}
34023377

3403-
im_src = GD_IMAGE_PTR_FROM_ZVAL_P(SIM);
3404-
3378+
im_src = GD_IMAGE_PTR_FROM_ZVAL_P(SIM);
3379+
34053380
if (gdImageColor(im_src, (int) r, (int) g, (int) b, (int) a) == 1) {
34063381
RETURN_TRUE;
34073382
}
@@ -3475,7 +3450,7 @@ static void php_image_filter_smooth(INTERNAL_FUNCTION_PARAMETERS)
34753450
return;
34763451
}
34773452

3478-
im_src = GD_IMAGE_PTR_FROM_ZVAL_P(SIM);
3453+
im_src = GD_IMAGE_PTR_FROM_ZVAL_P(SIM);
34793454

34803455
if (gdImageSmooth(im_src, (float)weight)==1) {
34813456
RETURN_TRUE;
@@ -3738,7 +3713,7 @@ PHP_FUNCTION(imagecrop)
37383713
RETURN_FALSE;
37393714
}
37403715

3741-
RETURN_OBJ(gd_ext_image_object_init(return_value, im_crop));
3716+
RETURN_OBJ(gd_ext_image_object_init(return_value, im_crop));
37423717
}
37433718
/* }}} */
37443719

@@ -3785,7 +3760,7 @@ PHP_FUNCTION(imagecropauto)
37853760
RETURN_FALSE;
37863761
}
37873762

3788-
RETURN_OBJ(gd_ext_image_object_init(return_value, im_crop));
3763+
RETURN_OBJ(gd_ext_image_object_init(return_value, im_crop));
37893764
}
37903765
/* }}} */
37913766

@@ -3840,7 +3815,7 @@ PHP_FUNCTION(imagescale)
38403815
RETURN_FALSE;
38413816
}
38423817

3843-
RETURN_OBJ(gd_ext_image_object_init(return_value, im_scaled));
3818+
RETURN_OBJ(gd_ext_image_object_init(return_value, im_scaled));
38443819
}
38453820
/* }}} */
38463821

@@ -3864,8 +3839,8 @@ PHP_FUNCTION(imageaffine)
38643839
return;
38653840
}
38663841

3867-
src = GD_IMAGE_PTR_FROM_ZVAL_P(IM);
3868-
3842+
src = GD_IMAGE_PTR_FROM_ZVAL_P(IM);
3843+
38693844
if ((nelems = zend_hash_num_elements(Z_ARRVAL_P(z_affine))) != 6) {
38703845
zend_value_error("Affine array must have six elements");
38713846
return;
@@ -3935,7 +3910,7 @@ PHP_FUNCTION(imageaffine)
39353910
RETURN_FALSE;
39363911
}
39373912

3938-
RETURN_OBJ(gd_ext_image_object_init(return_value, dst));
3913+
RETURN_OBJ(gd_ext_image_object_init(return_value, dst));
39393914
}
39403915
/* }}} */
39413916

ext/gd/gd_image_object.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,13 @@
2424

2525
zend_class_entry *gd_image_ce;
2626

27-
#define GD_IMAGE_PTR_FROM_ZVAL_P(x) (((gd_ext_image_object*)Z_OBJ_P(x))->image)
27+
#define GD_IMAGE_PTR_FROM_ZVAL_P(obj) (((gd_ext_image_object *)((char *)(Z_OBJ_P(obj)) - XtOffsetOf(gd_ext_image_object, std)))->image)
2828

2929
static zend_object* gd_ext_image_object_init(zval* val, gdImagePtr image);
3030

3131
typedef struct _gd_ext_image_object {
32-
zend_object std;
32+
zend_object std;
3333
gdImagePtr image;
3434
} gd_ext_image_object;
3535

36-
3736
#endif //SRC_GD_IMAGE_OBJECT_H

0 commit comments

Comments
 (0)