From 76a5804560b7500c0d7ad5eae575d05ce2a7035d Mon Sep 17 00:00:00 2001 From: Gina Peter Banyard Date: Fri, 10 Jan 2025 12:56:36 +0000 Subject: [PATCH] ext/zip: Convert progress_callback to FCC --- ext/zip/php_zip.c | 38 +++++++++++++++++++------------------- ext/zip/php_zip.h | 2 +- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/ext/zip/php_zip.c b/ext/zip/php_zip.c index e9b560ab1df..db711078f59 100644 --- a/ext/zip/php_zip.c +++ b/ext/zip/php_zip.c @@ -1019,13 +1019,12 @@ static HashTable *php_zip_get_properties(zend_object *object)/* {{{ */ /* }}} */ #ifdef HAVE_PROGRESS_CALLBACK -static void _php_zip_progress_callback_free(void *ptr) +static void php_zip_progress_callback_free(void *ptr) { ze_zip_object *obj = ptr; - if (!Z_ISUNDEF(obj->progress_callback)) { - zval_ptr_dtor(&obj->progress_callback); - ZVAL_UNDEF(&obj->progress_callback); + if (ZEND_FCC_INITIALIZED(obj->progress_callback)) { + zend_fcc_dtor(&obj->progress_callback); } } #endif @@ -1066,7 +1065,7 @@ static void php_zip_object_free_storage(zend_object *object) /* {{{ */ #ifdef HAVE_PROGRESS_CALLBACK /* if not properly called by libzip */ - _php_zip_progress_callback_free(intern); + php_zip_progress_callback_free(intern); #endif #ifdef HAVE_CANCEL_CALLBACK @@ -3019,42 +3018,43 @@ PHP_METHOD(ZipArchive, getStream) } #ifdef HAVE_PROGRESS_CALLBACK -static void _php_zip_progress_callback(zip_t *arch, double state, void *ptr) +static void php_zip_progress_callback(zip_t *arch, double state, void *ptr) { zval cb_args[1]; - zval cb_retval; ze_zip_object *obj = ptr; ZVAL_DOUBLE(&cb_args[0], state); - if (call_user_function(EG(function_table), NULL, &obj->progress_callback, &cb_retval, 1, cb_args) == SUCCESS && !Z_ISUNDEF(cb_retval)) { - zval_ptr_dtor(&cb_retval); - } + zend_call_known_fcc(&obj->progress_callback, NULL, 1, cb_args, NULL); } /* {{{ register a progression callback: void callback(double state); */ PHP_METHOD(ZipArchive, registerProgressCallback) { struct zip *intern; - zval *self = ZEND_THIS; double rate; - zend_fcall_info fci; + zend_fcall_info dummy_fci; zend_fcall_info_cache fcc; ze_zip_object *obj; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "df", &rate, &fci, &fcc) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "dF", &rate, &dummy_fci, &fcc) == FAILURE) { RETURN_THROWS(); } - ZIP_FROM_OBJECT(intern, self); - - obj = Z_ZIP_P(self); + /* Inline ZIP_FROM_OBJECT(intern, self); */ + obj = Z_ZIP_P(ZEND_THIS); + intern = obj->za; + if (!intern) { \ + zend_value_error("Invalid or uninitialized Zip object"); + zend_release_fcall_info_cache(&fcc); + RETURN_THROWS(); + } /* free if called twice */ - _php_zip_progress_callback_free(obj); + php_zip_progress_callback_free(obj); /* register */ - ZVAL_COPY(&obj->progress_callback, &fci.function_name); - if (zip_register_progress_callback_with_state(intern, rate, _php_zip_progress_callback, _php_zip_progress_callback_free, obj)) { + zend_fcc_dup(&obj->progress_callback, &fcc); + if (zip_register_progress_callback_with_state(intern, rate, php_zip_progress_callback, php_zip_progress_callback_free, obj)) { RETURN_FALSE; } diff --git a/ext/zip/php_zip.h b/ext/zip/php_zip.h index 4f4750993f9..750417b2378 100644 --- a/ext/zip/php_zip.h +++ b/ext/zip/php_zip.h @@ -77,7 +77,7 @@ typedef struct _ze_zip_object { int err_zip; int err_sys; #ifdef HAVE_PROGRESS_CALLBACK - zval progress_callback; + zend_fcall_info_cache progress_callback; #endif #ifdef HAVE_CANCEL_CALLBACK zval cancel_callback;