From: Greg Beaver Date: Thu, 17 Jan 2008 03:48:29 +0000 (+0000) Subject: no need to use conditional defines for bz2, we don't call it except indirectly throug... X-Git-Tag: RELEASE_2_0_0a1~869 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a3718dcfa3e10ac58bf2ff0ab278148f936db59d;p=php no need to use conditional defines for bz2, we don't call it except indirectly through stream wrappers. After removing HAVE_BZ2 conditionals, phar works even if bz2 is not present on installation through pecl --- diff --git a/ext/phar/config.m4 b/ext/phar/config.m4 index a4ab9f2cb5..0db01c3337 100644 --- a/ext/phar/config.m4 +++ b/ext/phar/config.m4 @@ -5,8 +5,25 @@ PHP_ARG_ENABLE(phar, for phar support/phar zlib support, [ --enable-phar Enable phar support]) if test "$PHP_PHAR" != "no"; then + AC_MSG_CHECKING([for ZIP includes]) + if test -f $abs_srcdir/include/php/ext/zip/lib/zip.h; then + zip_inc_path=$abs_srcdir/ext + AC_DEFINE(HAVE_PHAR_ZIP,1,[ ]) + AC_MSG_RESULT($zip_inc_path) + elif test -f $abs_srcdir/ext/zip/lib/zip.h; then + zip_inc_path=$abs_srcdir/ext + AC_DEFINE(HAVE_PHAR_ZIP,1,[ ]) + AC_MSG_RESULT($zip_inc_path) + elif test -f $prefix/include/php/ext/zip/lib/zip.h; then + zip_inc_path=$prefix/include/php/ext + AC_DEFINE(HAVE_PHAR_ZIP,1,[ ]) + AC_MSG_RESULT($zip_inc_path) + else + zip_inc_path=/dev/null + AC_DEFINE(HAVE_PHAR_ZIP,0,[ ]) + AC_MSG_RESULT([not found, disabling ZIP-based phar support]) + fi PHP_NEW_EXTENSION(phar, tar.c zip.c stream.c func_interceptors.c dirstream.c phar.c phar_object.c phar_path_check.c, $ext_shared) - AC_DEFINE(HAVE_PHAR_ZIP,1,[ ]) PHP_ADD_BUILD_DIR($ext_builddir/lib, 1) PHP_SUBST(PHAR_SHARED_LIBADD) PHP_ADD_EXTENSION_DEP(phar, zip, true) diff --git a/ext/phar/phar.c b/ext/phar/phar.c index 77c254e57e..a6899b09b9 100644 --- a/ext/phar/phar.c +++ b/ext/phar/phar.c @@ -1380,13 +1380,6 @@ int phar_open_file(php_stream *fp, char *fname, int fname_len, char *alias, int #endif break; case PHAR_ENT_COMPRESSED_BZ2: -#if !HAVE_BZ2 - if (entry.metadata) { - zval_ptr_dtor(&entry.metadata); - } - efree(entry.filename); - MAPPHAR_FAIL("bz2 extension is required for bzip2 compressed .phar file \"%s\""); -#else if (!phar_has_bz2) { if (entry.metadata) { zval_ptr_dtor(&entry.metadata); @@ -1394,7 +1387,6 @@ int phar_open_file(php_stream *fp, char *fname, int fname_len, char *alias, int efree(entry.filename); MAPPHAR_FAIL("bz2 extension is required for bzip2 compressed .phar file \"%s\""); } -#endif break; default: if (entry.uncompressed_filesize != entry.compressed_filesize) { @@ -1714,14 +1706,11 @@ static int phar_open_fp(php_stream* fp, char *fname, int fname_len, char *alias, #endif continue; } else if (!memcmp(pos, bz_magic, 3)) { -#if !HAVE_BZ2 - MAPPHAR_ALLOC_FAIL("unable to decompress bzipped phar archive \"%s\" to temporary file, bzip2 disabled in phar compilation") -#else php_stream_filter *filter; php_stream *temp; if (!phar_has_bz2) { - MAPPHAR_ALLOC_FAIL("unable to decompress bzipped phar archive \"%s\" to temporary file, enable bzip2 extension in php.ini") + MAPPHAR_ALLOC_FAIL("unable to decompress bzipped phar archive \"%s\" to temporary file, enable bz2 extension in php.ini") } /* entire file is bzip-compressed, uncompress to temporary file */ if (!(temp = php_stream_fopen_tmpfile())) { @@ -1747,7 +1736,6 @@ static int phar_open_fp(php_stream* fp, char *fname, int fname_len, char *alias, /* now, start over */ test = '\0'; -#endif continue; } if (!memcmp(pos, zip_magic, 4)) { @@ -2165,7 +2153,6 @@ phar_entry_info * phar_open_jit(phar_archive_data *phar, phar_entry_info *entry, } if (!entry->zip) { if (entry->flags & PHAR_ENT_COMPRESSED_BZ2) { -# if HAVE_BZ2 char *filter_name; php_stream_filter *filter; /* we have to decompress this by hand */ @@ -2230,12 +2217,6 @@ phar_entry_info * phar_open_jit(phar_archive_data *phar, phar_entry_info *entry, php_stream_filter_remove(filter, 1 TSRMLS_CC); php_stream_close(fp); return entry; -# else /* #if HAVE_BZ2 */ - if (error) { - spprintf(error, 4096, "phar error, cannot decompress bzip2-compressed entry"); - } - return NULL; -# endif /* #if HAVE_BZ2 */ } else { /* uncompressed or zlib-compressed */ entry->zip = zip_fopen_index(phar->zip, entry->index, 0); @@ -3325,15 +3306,11 @@ PHP_MINFO_FUNCTION(phar) /* {{{ */ #else php_info_print_table_row(2, "gzip compression", "unavailable"); #endif -#if HAVE_BZ2 if (phar_has_bz2) { php_info_print_table_row(2, "bzip2 compression", "enabled"); } else { php_info_print_table_row(2, "bzip2 compression", "disabled (install pecl/bz2)"); } -#else - php_info_print_table_row(2, "bzip2 compression", "unavailable (install pecl/bz2)"); -#endif php_info_print_table_end(); php_info_print_box_start(0); @@ -3357,9 +3334,7 @@ static zend_module_dep phar_deps[] = { #if HAVE_ZLIB ZEND_MOD_OPTIONAL("zlib") #endif -#if HAVE_BZ2 ZEND_MOD_OPTIONAL("bz2") -#endif #if HAVE_SPL ZEND_MOD_REQUIRED("spl") #endif diff --git a/ext/phar/phar_object.c b/ext/phar/phar_object.c index c7cfe38f87..4e331fd8ce 100755 --- a/ext/phar/phar_object.c +++ b/ext/phar/phar_object.c @@ -824,26 +824,18 @@ PHP_METHOD(Phar, canCompress) #endif case PHAR_ENT_COMPRESSED_BZ2: -#if HAVE_BZ2 if (phar_has_bz2) { RETURN_TRUE; } else { RETURN_FALSE; } -#else - RETURN_FALSE; -#endif default: -#if HAVE_ZLIB || HAVE_BZ2 - if (phar_has_zlib || phar_has_bz2) { - RETURN_TRUE; - } else { - RETURN_FALSE; - } -#else - RETURN_FALSE; -#endif + if (phar_has_zlib || phar_has_bz2) { + RETURN_TRUE; + } else { + RETURN_FALSE; + } } } /* }}} */ @@ -994,11 +986,9 @@ PHP_METHOD(Phar, getSupportedCompression) add_next_index_stringl(return_value, "GZ", 2, 1); } #endif -#if HAVE_BZ2 if (phar_has_bz2) { add_next_index_stringl(return_value, "BZIP2", 5, 1); } -#endif } /* }}} */ @@ -1717,7 +1707,6 @@ PHP_METHOD(Phar, convertToTar) #endif case PHAR_ENT_COMPRESSED_BZ2: -#if HAVE_BZ2 if (!phar_has_bz2) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "Cannot compress entire archive with bz2, enable ext/bz2 in php.ini"); @@ -1725,10 +1714,6 @@ PHP_METHOD(Phar, convertToTar) } flags = PHAR_FILE_COMPRESSED_BZ2; break; -#else - zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, - "Cannot compress entire archive with bz2, bz2 support unavailable"); -#endif default: zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "Unknown compression specified, please pass one of Phar::GZ or Phar::BZ2"); @@ -1788,11 +1773,6 @@ PHP_METHOD(Phar, convertToZip) "Cannot convert phar archive to zip format, zip-based phar archives are disabled (enable ext/zip in php.ini)"); return; } -#else - zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, - "Cannot convert phar archive to zip format, zip-based phar archives are unavailable"); - return; -#endif if (!zend_hash_num_elements(&phar_obj->arc.archive->manifest)) { int ziperror; @@ -1839,6 +1819,11 @@ PHP_METHOD(Phar, convertToZip) } phar_convert_to_other(phar_obj->arc.archive, 2, 0 TSRMLS_CC); RETURN_TRUE; +#else + zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, + "Cannot convert phar archive to zip format, zip-based phar archives are unavailable"); + return; +#endif } /* }}} */ @@ -1881,7 +1866,6 @@ PHP_METHOD(Phar, convertToPhar) #endif case PHAR_ENT_COMPRESSED_BZ2: -#if HAVE_BZ2 if (!phar_has_bz2) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "Cannot compress entire archive with bz2, enable ext/bz2 in php.ini"); @@ -1889,10 +1873,6 @@ PHP_METHOD(Phar, convertToPhar) } flags = PHAR_FILE_COMPRESSED_BZ2; break; -#else - zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, - "Cannot compress entire archive with bz2, bz2 support unavailable"); -#endif default: zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "Unknown compression specified, please pass one of Phar::GZ or Phar::BZ2"); @@ -2289,17 +2269,11 @@ static int phar_test_compression(void *pDest, void *argument TSRMLS_DC) /* {{{ * if (entry->is_deleted) { return ZEND_HASH_APPLY_KEEP; } -#if !HAVE_BZ2 - if (entry->flags & PHAR_ENT_COMPRESSED_BZ2) { - *(int *) argument = 0; - } -#else if (!phar_has_bz2) { if (entry->flags & PHAR_ENT_COMPRESSED_BZ2) { *(int *) argument = 0; } } -#endif #if !HAVE_ZLIB if (entry->flags & PHAR_ENT_COMPRESSED_GZ) { *(int *) argument = 0; @@ -2381,9 +2355,7 @@ PHP_METHOD(Phar, compressAllFilesGZ) */ PHP_METHOD(Phar, compressAllFilesBZIP2) { -#if HAVE_BZ2 char *error; -#endif PHAR_ARCHIVE_OBJECT(); if (phar_obj->arc.archive->is_zip) { @@ -2397,7 +2369,6 @@ PHP_METHOD(Phar, compressAllFilesBZIP2) "Phar is readonly, cannot change compression"); return; } -#if HAVE_BZ2 if (!phar_has_bz2) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "Cannot compress with Bzip2 compression, bz2 extension is not enabled"); @@ -2421,10 +2392,6 @@ PHP_METHOD(Phar, compressAllFilesBZIP2) zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, error); efree(error); } -#else - zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, - "Cannot compress with Bzip2 compression, bz2 extension is not enabled"); -#endif } /* }}} */ @@ -3312,7 +3279,6 @@ PHP_METHOD(PharFileInfo, setCompressedGZ) */ PHP_METHOD(PharFileInfo, setCompressedBZIP2) { -#if HAVE_BZ2 char *error; PHAR_ENTRY_OBJECT(); @@ -3361,10 +3327,6 @@ PHP_METHOD(PharFileInfo, setCompressedBZIP2) efree(error); } RETURN_TRUE; -#else - zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, - "Cannot compress with Bzip2 compression, bzip2 extension is not enabled"); -#endif } /* }}} */ @@ -3409,19 +3371,11 @@ PHP_METHOD(PharFileInfo, setUncompressed) return; } #endif -#if !HAVE_BZ2 - if (entry_obj->ent.entry->flags & PHAR_ENT_COMPRESSED_BZ2) { - zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, - "Cannot uncompress Bzip2-compressed file, bzip2 extension is not enabled"); - return; - } -#else if (!phar_has_bz2) { zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, - "Cannot uncompress Bzip2-compressed file, bzip2 extension is not enabled"); + "Cannot uncompress Bzip2-compressed file, bz2 extension is not enabled"); return; } -#endif if (!entry_obj->ent.entry->fp) { fname_len = spprintf(&fname, 0, "phar://%s/%s", entry_obj->ent.entry->phar->fname, entry_obj->ent.entry->filename); entry_obj->ent.entry->fp = php_stream_open_wrapper_ex(fname, "rb", 0, 0, 0); diff --git a/ext/phar/zip.c b/ext/phar/zip.c index d6dc7815a9..0f7881c6ae 100644 --- a/ext/phar/zip.c +++ b/ext/phar/zip.c @@ -156,23 +156,6 @@ int phar_open_zipfile(char *fname, int fname_len, char *alias, int alias_len, ph entry.flags |= PHAR_ENT_COMPRESSED_GZ; break; case ZIP_CM_BZIP2 : -#if !HAVE_BZ2 - if (mydata->metadata) { - zval_dtor(mydata->metadata); - } - efree(mydata->fname); - if (mydata->alias) { - efree(mydata->alias); - } - zip_close(zip); - zend_hash_destroy(&(mydata->manifest)); - mydata->manifest.arBuckets = NULL; - efree(mydata); - if (error) { - spprintf(error, 0, "bz2 extension is required for Bzip2 compressed zip-based .phar file \"%s\"", fname); - } - return FAILURE; -#else if (!phar_has_bz2) { if (mydata->metadata) { zval_dtor(mydata->metadata); @@ -190,7 +173,6 @@ int phar_open_zipfile(char *fname, int fname_len, char *alias, int alias_len, ph } return FAILURE; } -#endif entry.flags |= PHAR_ENT_COMPRESSED_BZ2; break; }