]> granicus.if.org Git - php/commitdiff
- Simplify by providing delref function
authorMarcus Boerger <helly@php.net>
Fri, 26 Jan 2007 19:58:22 +0000 (19:58 +0000)
committerMarcus Boerger <helly@php.net>
Fri, 26 Jan 2007 19:58:22 +0000 (19:58 +0000)
ext/phar/phar.c
ext/phar/phar_internal.h
ext/phar/phar_object.c

index 940b88ace92b76bdd9a9406b7431410a46d25be9..738596f7f632b1044fd3cf3d30129e198608f635 100644 (file)
@@ -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;
 }
index fcd5a6c3a605463d0fb484927f05f56705ef3ffd..5d7626537c2f6bcef0230305559360362b53aa4c 100755 (executable)
@@ -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);
index a4e3bb529f18eb0d828374ba02d57ff566dbbec4..422bd1c28e1ce6e294824e13148eb3d114b2934e 100755 (executable)
@@ -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;
 }
 /* }}} */