From 641c9e223d326fb3cfc78c4f81ba35dc31362760 Mon Sep 17 00:00:00 2001 From: Andreas Treichel Date: Fri, 6 Jan 2023 15:38:34 +0100 Subject: [PATCH 1/6] Allow cloning of GdImage from gd 2.2.0 --- ext/gd/gd.c | 19 ++++++++++++++++- ext/gd/tests/gdimage_cloning.phpt | 26 +++++++++++++++++++++++ ext/gd/tests/gdimage_prevent_cloning.phpt | 2 ++ 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 ext/gd/tests/gdimage_cloning.phpt diff --git a/ext/gd/gd.c b/ext/gd/gd.c index cdfaaeedaeb7..c14f2a4d6dfb 100644 --- a/ext/gd/gd.c +++ b/ext/gd/gd.c @@ -203,6 +203,19 @@ void php_gd_assign_libgdimageptr_as_extgdimage(zval *val, gdImagePtr image) php_gd_exgdimage_from_zobj_p(Z_OBJ_P(val))->image = image; } +#if GD_MAJOR_VERSION >= 2 && GD_MINOR_VERSION >= 2 +static zend_object *php_gd_clone(zend_object *zobj) +{ + gdImagePtr oldim = php_gd_exgdimage_from_zobj_p(zobj)->image; + gdImagePtr newim = gdImageClone(oldim); + zval znew; + + php_gd_assign_libgdimageptr_as_extgdimage(&znew, newim); + + return Z_OBJ(znew); +} +#endif + static void php_gd_object_minit_helper(void) { gd_image_ce = register_class_GdImage(); @@ -210,7 +223,11 @@ static void php_gd_object_minit_helper(void) /* setting up the object handlers for the GdImage class */ memcpy(&php_gd_image_object_handlers, &std_object_handlers, sizeof(zend_object_handlers)); - php_gd_image_object_handlers.clone_obj = NULL; +#if GD_MAJOR_VERSION >= 2 && GD_MINOR_VERSION >= 2 + php_gd_image_object_handlers.clone_obj = php_gd_clone; +#else + php_gd_image_object_handlers.clone_obj = NULL; +#endif php_gd_image_object_handlers.free_obj = php_gd_image_object_free; php_gd_image_object_handlers.get_constructor = php_gd_image_object_get_constructor; php_gd_image_object_handlers.compare = zend_objects_not_comparable; diff --git a/ext/gd/tests/gdimage_cloning.phpt b/ext/gd/tests/gdimage_cloning.phpt new file mode 100644 index 000000000000..88a7ffdb3c50 --- /dev/null +++ b/ext/gd/tests/gdimage_cloning.phpt @@ -0,0 +1,26 @@ +--TEST-- +Checks that GdImage instances can be cloned from gd > 2.2.0 +--SKIPIF-- + +--EXTENSIONS-- +gd +--FILE-- + +--EXPECTF-- +bool(true) +bool(true) diff --git a/ext/gd/tests/gdimage_prevent_cloning.phpt b/ext/gd/tests/gdimage_prevent_cloning.phpt index 426f7d9c48f6..6fe3e48817dd 100644 --- a/ext/gd/tests/gdimage_prevent_cloning.phpt +++ b/ext/gd/tests/gdimage_prevent_cloning.phpt @@ -1,5 +1,7 @@ --TEST-- Checks that GdImage instances cannot be cloned +--SKIPIF-- +=')) { die("Skipped: GdImage is clonable from gd 2.2.0"); } ?> --EXTENSIONS-- gd --FILE-- From e5183faac7b7ac6a72cf574924dca50df8408312 Mon Sep 17 00:00:00 2001 From: Andreas Treichel Date: Fri, 6 Jan 2023 17:01:48 +0100 Subject: [PATCH 2/6] Allow cloning of GdImage from gd 2.3.0 --- ext/gd/gd.c | 7 +++---- ext/gd/tests/gdimage_cloning.phpt | 18 +++++++++--------- ext/gd/tests/gdimage_prevent_cloning.phpt | 2 +- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/ext/gd/gd.c b/ext/gd/gd.c index c14f2a4d6dfb..c4fd3dec14a1 100644 --- a/ext/gd/gd.c +++ b/ext/gd/gd.c @@ -203,9 +203,8 @@ void php_gd_assign_libgdimageptr_as_extgdimage(zval *val, gdImagePtr image) php_gd_exgdimage_from_zobj_p(Z_OBJ_P(val))->image = image; } -#if GD_MAJOR_VERSION >= 2 && GD_MINOR_VERSION >= 2 -static zend_object *php_gd_clone(zend_object *zobj) -{ +#if GD_MAJOR_VERSION >= 2 && GD_MINOR_VERSION > 2 || (GD_MINOR_VERSION == 2 && GD_RELEASE_VERSION >= 3) +static zend_object *php_gd_clone(zend_object *zobj) { gdImagePtr oldim = php_gd_exgdimage_from_zobj_p(zobj)->image; gdImagePtr newim = gdImageClone(oldim); zval znew; @@ -223,7 +222,7 @@ static void php_gd_object_minit_helper(void) /* setting up the object handlers for the GdImage class */ memcpy(&php_gd_image_object_handlers, &std_object_handlers, sizeof(zend_object_handlers)); -#if GD_MAJOR_VERSION >= 2 && GD_MINOR_VERSION >= 2 +#if GD_MAJOR_VERSION >= 2 && GD_MINOR_VERSION > 2 || (GD_MINOR_VERSION == 2 && GD_RELEASE_VERSION >= 3) php_gd_image_object_handlers.clone_obj = php_gd_clone; #else php_gd_image_object_handlers.clone_obj = NULL; diff --git a/ext/gd/tests/gdimage_cloning.phpt b/ext/gd/tests/gdimage_cloning.phpt index 88a7ffdb3c50..ca4f8a24830d 100644 --- a/ext/gd/tests/gdimage_cloning.phpt +++ b/ext/gd/tests/gdimage_cloning.phpt @@ -1,23 +1,23 @@ --TEST-- -Checks that GdImage instances can be cloned from gd > 2.2.0 +Checks that GdImage instances can be cloned from gd > 2.2.3 --SKIPIF-- - + --EXTENSIONS-- gd --FILE-- diff --git a/ext/gd/tests/gdimage_prevent_cloning.phpt b/ext/gd/tests/gdimage_prevent_cloning.phpt index 6fe3e48817dd..98297dec17d8 100644 --- a/ext/gd/tests/gdimage_prevent_cloning.phpt +++ b/ext/gd/tests/gdimage_prevent_cloning.phpt @@ -1,7 +1,7 @@ --TEST-- Checks that GdImage instances cannot be cloned --SKIPIF-- -=')) { die("Skipped: GdImage is clonable from gd 2.2.0"); } ?> +=')) { die("Skipped: GdImage is clonable from gd 2.2.3"); } ?> --EXTENSIONS-- gd --FILE-- From b6976b9076ff614f79daa6e74e1730df20177026 Mon Sep 17 00:00:00 2001 From: Andreas Treichel Date: Fri, 6 Jan 2023 17:04:57 +0100 Subject: [PATCH 3/6] Allow cloning of GdImage from gd 2.3.0 --- ext/gd/tests/gdimage_cloning.phpt | 4 ++-- ext/gd/tests/gdimage_prevent_cloning.phpt | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ext/gd/tests/gdimage_cloning.phpt b/ext/gd/tests/gdimage_cloning.phpt index ca4f8a24830d..88bfedcacd9b 100644 --- a/ext/gd/tests/gdimage_cloning.phpt +++ b/ext/gd/tests/gdimage_cloning.phpt @@ -1,9 +1,9 @@ --TEST-- Checks that GdImage instances can be cloned from gd > 2.2.3 ---SKIPIF-- - --EXTENSIONS-- gd +--SKIPIF-- + --FILE-- =')) { die("Skipped: GdImage is clonable from gd 2.2.3"); } ?> --EXTENSIONS-- gd +--SKIPIF-- +=')) die("Skipped: GdImage is clonable from gd 2.2.3"); ?> --FILE-- Date: Sat, 14 Jan 2023 16:44:48 +0100 Subject: [PATCH 4/6] Fix version compare --- ext/gd/gd.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ext/gd/gd.c b/ext/gd/gd.c index c4fd3dec14a1..d777e6d6d023 100644 --- a/ext/gd/gd.c +++ b/ext/gd/gd.c @@ -203,8 +203,9 @@ void php_gd_assign_libgdimageptr_as_extgdimage(zval *val, gdImagePtr image) php_gd_exgdimage_from_zobj_p(Z_OBJ_P(val))->image = image; } -#if GD_MAJOR_VERSION >= 2 && GD_MINOR_VERSION > 2 || (GD_MINOR_VERSION == 2 && GD_RELEASE_VERSION >= 3) -static zend_object *php_gd_clone(zend_object *zobj) { +#if GD_MAJOR_VERSION > 2 || (GD_MAJOR_VERSION == 2 && (GD_MINOR_VERSION > 2 || (GD_MINOR_VERSION == 2 && GD_RELEASE_VERSION >= 3)) +static zend_object *php_gd_clone(zend_object *zobj) +{ gdImagePtr oldim = php_gd_exgdimage_from_zobj_p(zobj)->image; gdImagePtr newim = gdImageClone(oldim); zval znew; @@ -222,7 +223,7 @@ static void php_gd_object_minit_helper(void) /* setting up the object handlers for the GdImage class */ memcpy(&php_gd_image_object_handlers, &std_object_handlers, sizeof(zend_object_handlers)); -#if GD_MAJOR_VERSION >= 2 && GD_MINOR_VERSION > 2 || (GD_MINOR_VERSION == 2 && GD_RELEASE_VERSION >= 3) +#if GD_MAJOR_VERSION > 2 || (GD_MAJOR_VERSION == 2 && (GD_MINOR_VERSION > 2 || (GD_MINOR_VERSION == 2 && GD_RELEASE_VERSION >= 3)) php_gd_image_object_handlers.clone_obj = php_gd_clone; #else php_gd_image_object_handlers.clone_obj = NULL; From 84bfc14c27963c07eaf1d82985dbe8041a133ad9 Mon Sep 17 00:00:00 2001 From: Andreas Treichel Date: Sat, 14 Jan 2023 16:55:14 +0100 Subject: [PATCH 5/6] Fix version compare --- ext/gd/gd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ext/gd/gd.c b/ext/gd/gd.c index d777e6d6d023..4908ff8c0160 100644 --- a/ext/gd/gd.c +++ b/ext/gd/gd.c @@ -203,7 +203,7 @@ void php_gd_assign_libgdimageptr_as_extgdimage(zval *val, gdImagePtr image) php_gd_exgdimage_from_zobj_p(Z_OBJ_P(val))->image = image; } -#if GD_MAJOR_VERSION > 2 || (GD_MAJOR_VERSION == 2 && (GD_MINOR_VERSION > 2 || (GD_MINOR_VERSION == 2 && GD_RELEASE_VERSION >= 3)) +#if GD_MAJOR_VERSION > 2 || (GD_MAJOR_VERSION == 2 && (GD_MINOR_VERSION > 2 || (GD_MINOR_VERSION == 2 && GD_RELEASE_VERSION >= 3))) static zend_object *php_gd_clone(zend_object *zobj) { gdImagePtr oldim = php_gd_exgdimage_from_zobj_p(zobj)->image; @@ -223,7 +223,7 @@ static void php_gd_object_minit_helper(void) /* setting up the object handlers for the GdImage class */ memcpy(&php_gd_image_object_handlers, &std_object_handlers, sizeof(zend_object_handlers)); -#if GD_MAJOR_VERSION > 2 || (GD_MAJOR_VERSION == 2 && (GD_MINOR_VERSION > 2 || (GD_MINOR_VERSION == 2 && GD_RELEASE_VERSION >= 3)) +#if GD_MAJOR_VERSION > 2 || (GD_MAJOR_VERSION == 2 && (GD_MINOR_VERSION > 2 || (GD_MINOR_VERSION == 2 && GD_RELEASE_VERSION >= 3))) php_gd_image_object_handlers.clone_obj = php_gd_clone; #else php_gd_image_object_handlers.clone_obj = NULL; From f67ba91c3ff50fb53e4d3cf0ec9161525a4636b6 Mon Sep 17 00:00:00 2001 From: Andreas Treichel Date: Fri, 3 Feb 2023 21:06:42 +0100 Subject: [PATCH 6/6] indent and sections --- ext/gd/tests/gdimage_cloning.phpt | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/ext/gd/tests/gdimage_cloning.phpt b/ext/gd/tests/gdimage_cloning.phpt index 88bfedcacd9b..ed8b2021b478 100644 --- a/ext/gd/tests/gdimage_cloning.phpt +++ b/ext/gd/tests/gdimage_cloning.phpt @@ -7,17 +7,17 @@ gd --FILE--