- Fixed zlib.deflate compress filter to actually accpet level parameter.

This commit is contained in:
Jani Taskinen 2009-08-31 21:18:55 +00:00
parent c53880beca
commit eb2f9ad0cc
2 changed files with 28 additions and 17 deletions

View File

@ -0,0 +1,16 @@
--TEST--
zlib.deflate (with level parameter set)
--SKIPIF--
<?php if (!extension_loaded("zlib")) print "skip"; ?>
--FILE--
<?php
$text = 'I am the very model of a modern major general, I\'ve information vegetable, animal, and mineral.';
$fp = fopen('php://stdout', 'w');
stream_filter_append($fp, 'zlib.deflate', STREAM_FILTER_WRITE, array('level' => 9));
fwrite($fp, $text);
fclose($fp);
?>
--EXPECT--
ËA DÑ«ÌÎ<C38C>ñ£†1´MBâíUvñ_(ÆELÆõÌ/<2F>•aP¹=Pi é;Ò6‰fÅCe4·<34>U9;wˆ± m /

View File

@ -370,7 +370,7 @@ static php_stream_filter *php_zlib_filter_create(const char *filtername, zval *f
if (filterparams) { if (filterparams) {
zval **tmpzval; zval **tmpzval, tmp;
/* filterparams can either be a scalar value to indicate compression level (shortcut method) /* filterparams can either be a scalar value to indicate compression level (shortcut method)
Or can be a hash containing one or more of 'window', 'memory', and/or 'level' members. */ Or can be a hash containing one or more of 'window', 'memory', and/or 'level' members. */
@ -379,8 +379,6 @@ static php_stream_filter *php_zlib_filter_create(const char *filtername, zval *f
case IS_ARRAY: case IS_ARRAY:
case IS_OBJECT: case IS_OBJECT:
if (zend_hash_find(HASH_OF(filterparams), "memory", sizeof("memory"), (void**) &tmpzval) == SUCCESS) { if (zend_hash_find(HASH_OF(filterparams), "memory", sizeof("memory"), (void**) &tmpzval) == SUCCESS) {
zval tmp;
tmp = **tmpzval; tmp = **tmpzval;
zval_copy_ctor(&tmp); zval_copy_ctor(&tmp);
convert_to_long(&tmp); convert_to_long(&tmp);
@ -394,8 +392,6 @@ static php_stream_filter *php_zlib_filter_create(const char *filtername, zval *f
} }
if (zend_hash_find(HASH_OF(filterparams), "window", sizeof("window"), (void**) &tmpzval) == SUCCESS) { if (zend_hash_find(HASH_OF(filterparams), "window", sizeof("window"), (void**) &tmpzval) == SUCCESS) {
zval tmp;
tmp = **tmpzval; tmp = **tmpzval;
zval_copy_ctor(&tmp); zval_copy_ctor(&tmp);
convert_to_long(&tmp); convert_to_long(&tmp);
@ -409,6 +405,8 @@ static php_stream_filter *php_zlib_filter_create(const char *filtername, zval *f
} }
if (zend_hash_find(HASH_OF(filterparams), "level", sizeof("level"), (void**) &tmpzval) == SUCCESS) { if (zend_hash_find(HASH_OF(filterparams), "level", sizeof("level"), (void**) &tmpzval) == SUCCESS) {
tmp = **tmpzval;
/* Psuedo pass through to catch level validating code */ /* Psuedo pass through to catch level validating code */
goto factory_setlevel; goto factory_setlevel;
} }
@ -416,19 +414,16 @@ static php_stream_filter *php_zlib_filter_create(const char *filtername, zval *f
case IS_STRING: case IS_STRING:
case IS_DOUBLE: case IS_DOUBLE:
case IS_LONG: case IS_LONG:
{ tmp = *filterparams;
zval tmp;
tmp = *filterparams;
zval_copy_ctor(&tmp);
convert_to_long(&tmp);
factory_setlevel: factory_setlevel:
/* Set compression level within reason (-1 == default, 0 == none, 1-9 == least to most compression */ zval_copy_ctor(&tmp);
if (Z_LVAL(tmp) < -1 || Z_LVAL(tmp) > 9) { convert_to_long(&tmp);
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid compression level specified. (%ld)", Z_LVAL(tmp));
} else { /* Set compression level within reason (-1 == default, 0 == none, 1-9 == least to most compression */
level = Z_LVAL(tmp); if (Z_LVAL(tmp) < -1 || Z_LVAL(tmp) > 9) {
} php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid compression level specified. (%ld)", Z_LVAL(tmp));
} else {
level = Z_LVAL(tmp);
} }
break; break;
default: default: