Skip to content

Commit 38b3d43

Browse files
committed
Fix zpp for GdFont|int
Use Z_PARAM_OBJ_OF_TYPE_OR_LONG to get standard behavior.
1 parent 66757b5 commit 38b3d43

File tree

1 file changed

+22
-20
lines changed

1 file changed

+22
-20
lines changed

ext/gd/gd.c

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2743,26 +2743,21 @@ PHP_FUNCTION(imagefilledpolygon)
27432743
/* }}} */
27442744

27452745
/* {{{ php_find_gd_font */
2746-
static gdFontPtr php_find_gd_font(zval *zfont)
2746+
static gdFontPtr php_find_gd_font(zend_object *font_obj, zend_long font_int)
27472747
{
2748-
if ((Z_TYPE_P(zfont) == IS_OBJECT) && instanceof_function(Z_OBJCE_P(zfont), gd_font_ce)) {
2749-
return php_gd_font_object_from_zend_object(Z_OBJ_P(zfont))->font;
2748+
if (font_obj) {
2749+
return php_gd_font_object_from_zend_object(font_obj)->font;
27502750
}
27512751

2752-
if (Z_TYPE_P(zfont) != IS_LONG) {
2753-
/* In practice, type checks should prevent us from reaching here. */
2754-
return gdFontTiny;
2755-
}
2756-
2757-
switch (Z_LVAL_P(zfont)) {
2752+
switch (font_int) {
27582753
case 1: return gdFontTiny;
27592754
case 2: return gdFontSmall;
27602755
case 3: return gdFontMediumBold;
27612756
case 4: return gdFontLarge;
27622757
case 5: return gdFontGiant;
27632758
}
27642759

2765-
return (Z_LVAL_P(zfont) < 1) ? gdFontTiny : gdFontGiant;
2760+
return font_int < 1 ? gdFontTiny : gdFontGiant;
27662761
}
27672762
/* }}} */
27682763

@@ -2772,14 +2767,15 @@ static gdFontPtr php_find_gd_font(zval *zfont)
27722767
*/
27732768
static void php_imagefontsize(INTERNAL_FUNCTION_PARAMETERS, int arg)
27742769
{
2775-
zval *zfont;
2770+
zend_object *font_obj;
2771+
zend_long font_int;
27762772
gdFontPtr font;
27772773

2778-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &zfont) == FAILURE) {
2779-
RETURN_THROWS();
2780-
}
2774+
ZEND_PARSE_PARAMETERS_START(1, 1)
2775+
Z_PARAM_OBJ_OF_CLASS_OR_LONG(font_obj, gd_font_ce, font_int)
2776+
ZEND_PARSE_PARAMETERS_END();
27812777

2782-
font = php_find_gd_font(zfont);
2778+
font = php_find_gd_font(font_obj, font_int);
27832779
RETURN_LONG(arg ? font->h : font->w);
27842780
}
27852781
/* }}} */
@@ -2839,12 +2835,18 @@ static void php_imagechar(INTERNAL_FUNCTION_PARAMETERS, int mode)
28392835
gdImagePtr im;
28402836
int ch = 0, col, x, y, i, l = 0;
28412837
unsigned char *str = NULL;
2842-
zval *zfont;
2838+
zend_object *font_obj;
2839+
zend_long font_int;
28432840
gdFontPtr font;
28442841

2845-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "Ozllsl", &IM, gd_image_ce, &zfont, &X, &Y, &C, &C_len, &COL) == FAILURE) {
2846-
RETURN_THROWS();
2847-
}
2842+
ZEND_PARSE_PARAMETERS_START(6, 6)
2843+
Z_PARAM_OBJECT_OF_CLASS(IM, gd_image_ce)
2844+
Z_PARAM_OBJ_OF_CLASS_OR_LONG(font_obj, gd_font_ce, font_int)
2845+
Z_PARAM_LONG(X)
2846+
Z_PARAM_LONG(Y)
2847+
Z_PARAM_STRING(C, C_len)
2848+
Z_PARAM_LONG(COL)
2849+
ZEND_PARSE_PARAMETERS_END();
28482850

28492851
im = php_gd_libgdimageptr_from_zval_p(IM);
28502852

@@ -2860,7 +2862,7 @@ static void php_imagechar(INTERNAL_FUNCTION_PARAMETERS, int mode)
28602862
y = Y;
28612863
x = X;
28622864

2863-
font = php_find_gd_font(zfont);
2865+
font = php_find_gd_font(font_obj, font_int);
28642866

28652867
switch (mode) {
28662868
case 0:

0 commit comments

Comments
 (0)