Skip to content

Commit 76a5804

Browse files
committed
ext/zip: Convert progress_callback to FCC
1 parent 08784ed commit 76a5804

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

ext/zip/php_zip.c

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,13 +1019,12 @@ static HashTable *php_zip_get_properties(zend_object *object)/* {{{ */
10191019
/* }}} */
10201020

10211021
#ifdef HAVE_PROGRESS_CALLBACK
1022-
static void _php_zip_progress_callback_free(void *ptr)
1022+
static void php_zip_progress_callback_free(void *ptr)
10231023
{
10241024
ze_zip_object *obj = ptr;
10251025

1026-
if (!Z_ISUNDEF(obj->progress_callback)) {
1027-
zval_ptr_dtor(&obj->progress_callback);
1028-
ZVAL_UNDEF(&obj->progress_callback);
1026+
if (ZEND_FCC_INITIALIZED(obj->progress_callback)) {
1027+
zend_fcc_dtor(&obj->progress_callback);
10291028
}
10301029
}
10311030
#endif
@@ -1066,7 +1065,7 @@ static void php_zip_object_free_storage(zend_object *object) /* {{{ */
10661065

10671066
#ifdef HAVE_PROGRESS_CALLBACK
10681067
/* if not properly called by libzip */
1069-
_php_zip_progress_callback_free(intern);
1068+
php_zip_progress_callback_free(intern);
10701069
#endif
10711070

10721071
#ifdef HAVE_CANCEL_CALLBACK
@@ -3019,42 +3018,43 @@ PHP_METHOD(ZipArchive, getStream)
30193018
}
30203019

30213020
#ifdef HAVE_PROGRESS_CALLBACK
3022-
static void _php_zip_progress_callback(zip_t *arch, double state, void *ptr)
3021+
static void php_zip_progress_callback(zip_t *arch, double state, void *ptr)
30233022
{
30243023
zval cb_args[1];
3025-
zval cb_retval;
30263024
ze_zip_object *obj = ptr;
30273025

30283026
ZVAL_DOUBLE(&cb_args[0], state);
3029-
if (call_user_function(EG(function_table), NULL, &obj->progress_callback, &cb_retval, 1, cb_args) == SUCCESS && !Z_ISUNDEF(cb_retval)) {
3030-
zval_ptr_dtor(&cb_retval);
3031-
}
3027+
zend_call_known_fcc(&obj->progress_callback, NULL, 1, cb_args, NULL);
30323028
}
30333029

30343030
/* {{{ register a progression callback: void callback(double state); */
30353031
PHP_METHOD(ZipArchive, registerProgressCallback)
30363032
{
30373033
struct zip *intern;
3038-
zval *self = ZEND_THIS;
30393034
double rate;
3040-
zend_fcall_info fci;
3035+
zend_fcall_info dummy_fci;
30413036
zend_fcall_info_cache fcc;
30423037
ze_zip_object *obj;
30433038

3044-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "df", &rate, &fci, &fcc) == FAILURE) {
3039+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "dF", &rate, &dummy_fci, &fcc) == FAILURE) {
30453040
RETURN_THROWS();
30463041
}
30473042

3048-
ZIP_FROM_OBJECT(intern, self);
3049-
3050-
obj = Z_ZIP_P(self);
3043+
/* Inline ZIP_FROM_OBJECT(intern, self); */
3044+
obj = Z_ZIP_P(ZEND_THIS);
3045+
intern = obj->za;
3046+
if (!intern) { \
3047+
zend_value_error("Invalid or uninitialized Zip object");
3048+
zend_release_fcall_info_cache(&fcc);
3049+
RETURN_THROWS();
3050+
}
30513051

30523052
/* free if called twice */
3053-
_php_zip_progress_callback_free(obj);
3053+
php_zip_progress_callback_free(obj);
30543054

30553055
/* register */
3056-
ZVAL_COPY(&obj->progress_callback, &fci.function_name);
3057-
if (zip_register_progress_callback_with_state(intern, rate, _php_zip_progress_callback, _php_zip_progress_callback_free, obj)) {
3056+
zend_fcc_dup(&obj->progress_callback, &fcc);
3057+
if (zip_register_progress_callback_with_state(intern, rate, php_zip_progress_callback, php_zip_progress_callback_free, obj)) {
30583058
RETURN_FALSE;
30593059
}
30603060

ext/zip/php_zip.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ typedef struct _ze_zip_object {
7777
int err_zip;
7878
int err_sys;
7979
#ifdef HAVE_PROGRESS_CALLBACK
80-
zval progress_callback;
80+
zend_fcall_info_cache progress_callback;
8181
#endif
8282
#ifdef HAVE_CANCEL_CALLBACK
8383
zval cancel_callback;

0 commit comments

Comments
 (0)