From: Marcus Boerger Date: Fri, 26 Jan 2007 19:58:22 +0000 (+0000) Subject: - Simplify by providing delref function X-Git-Tag: RELEASE_1_0_0RC1~128 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9cd8d736771ec67d79d6d45a6b50a179a3b7e2e8;p=php - Simplify by providing delref function --- diff --git a/ext/phar/phar.c b/ext/phar/phar.c index 940b88ace9..738596f7f6 100644 --- a/ext/phar/phar.c +++ b/ext/phar/phar.c @@ -106,6 +106,21 @@ void phar_destroy_phar_data(phar_archive_data *data TSRMLS_DC) /* {{{ */ } /* }}}*/ +/** + * Delete refcount and destruct if needed. On destruct return 1 else 0. + */ +int phar_archive_delref(phar_archive_data *phar TSRMLS_DC) /* {{{ */ +{ + if (--phar->refcount < 0) { + if (zend_hash_del(&(PHAR_GLOBALS->phar_fname_map), phar->fname, phar->fname_len) != SUCCESS) { + phar_destroy_phar_data(phar TSRMLS_CC); + } + return 1; + } + return 0; +} +/* }}}*/ + /** * Destroy phar's in shutdown, here we don't care about aliases */ @@ -1433,11 +1448,7 @@ static int phar_stream_close(php_stream *stream, int close_handle TSRMLS_DC) /* /* data->fp is the temporary memory stream containing this file's data */ phar_free_entry_data(data TSRMLS_CC); - if (--phar->refcount < 0) { - if (zend_hash_del(&(PHAR_GLOBALS->phar_fname_map), phar->fname, phar->fname_len) != SUCCESS) { - phar_destroy_phar_data(phar TSRMLS_CC); - } - } + phar_archive_delref(phar TSRMLS_CC); return 0; } diff --git a/ext/phar/phar_internal.h b/ext/phar/phar_internal.h index fcd5a6c3a6..5d7626537c 100755 --- a/ext/phar/phar_internal.h +++ b/ext/phar/phar_internal.h @@ -242,6 +242,7 @@ static int phar_dir_stat( php_stream *stream, php_stream_statbuf *ssb TSRMLS_ #endif +int phar_archive_delref(phar_archive_data *phar TSRMLS_DC); void phar_destroy_phar_data(phar_archive_data *data TSRMLS_DC); phar_entry_info *phar_get_entry_info(phar_archive_data *phar, char *path, int path_len TSRMLS_DC); void phar_free_entry_data(phar_entry_data *idata TSRMLS_DC); diff --git a/ext/phar/phar_object.c b/ext/phar/phar_object.c index a4e3bb529f..422bd1c28e 100755 --- a/ext/phar/phar_object.c +++ b/ext/phar/phar_object.c @@ -87,11 +87,8 @@ PHP_METHOD(Phar, canWrite) */ static void phar_spl_foreign_dtor(spl_filesystem_object *object TSRMLS_DC) /* {{{ */ { - phar_archive_data *phar_data = (phar_archive_data *) object->oth; - - if (--phar_data->refcount < 0) { - phar_destroy_phar_data(phar_data TSRMLS_CC); - } + phar_archive_delref((phar_archive_data *) object->oth TSRMLS_CC); + object->oth = NULL; } /* }}} */