From: Nikita Popov Date: Sat, 25 Apr 2015 17:00:41 +0000 (+0200) Subject: Tweak new deflate/inflate implementations X-Git-Tag: PRE_PHP7_NSAPI_REMOVAL~155 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=300b1db09fc093c7224bb3e1016534378fcf92bc;p=php Tweak new deflate/inflate implementations Return NULL on zpp. Don't manually cast zvals to long. --- diff --git a/ext/zlib/tests/inflate_init_error.phpt b/ext/zlib/tests/inflate_init_error.phpt index ad1410cab4..0e0e8b33bf 100644 --- a/ext/zlib/tests/inflate_init_error.phpt +++ b/ext/zlib/tests/inflate_init_error.phpt @@ -14,7 +14,7 @@ var_dump(inflate_init(42)); --EXPECTF-- Warning: inflate_init() expects exactly 1 parameter, 0 given in %s on line %d -bool(false) +NULL Warning: inflate_init(): encoding mode must be ZLIB_ENCODING_RAW, ZLIB_ENCODING_GZIP or ZLIB_ENCODING_DEFLATE in %s on line %d bool(false) diff --git a/ext/zlib/zlib.c b/ext/zlib/zlib.c index 957be3417c..7fcb6a1e51 100644 --- a/ext/zlib/zlib.c +++ b/ext/zlib/zlib.c @@ -760,7 +760,7 @@ PHP_FUNCTION(inflate_init) zend_long encoding; if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "l", &encoding)) { - RETURN_FALSE; + return; } switch (encoding) { @@ -801,7 +801,7 @@ PHP_FUNCTION(inflate_add) int status; if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "rs|l", &res, &in_buf, &in_len, &flush_type)) { - RETURN_FALSE; + return; } if (!(ctx = zend_fetch_resource_ex(res, NULL, le_inflate))) { @@ -885,21 +885,14 @@ PHP_FUNCTION(deflate_init) z_stream *ctx; zend_long encoding, level = -1, memory = 8; HashTable *options = 0; - zval *option_buffer, cast_option_buffer; + zval *option_buffer; if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "l|H", &encoding, &options)) { - RETURN_FALSE; + return; } - if (options && (option_buffer = zend_symtable_str_find(options, "level", sizeof("level")-1)) != NULL) { - if (Z_TYPE_P(option_buffer) != IS_LONG) { - ZVAL_DUP(&cast_option_buffer, option_buffer); - convert_to_long(&cast_option_buffer); - level = Z_LVAL(cast_option_buffer); - zval_dtor(&cast_option_buffer); - } else { - level = Z_LVAL_P(option_buffer); - } + if (options && (option_buffer = zend_hash_str_find(options, "level", sizeof("level")-1)) != NULL) { + level = zval_get_long(option_buffer); } if (level < -1 || level > 9) { php_error_docref(NULL, E_WARNING, "compression level (%pd) must be within -1..9", level); @@ -907,14 +900,7 @@ PHP_FUNCTION(deflate_init) } if (options && (option_buffer = zend_symtable_str_find(options, "memory", sizeof("memory")-1)) != NULL) { - if (Z_TYPE_P(option_buffer) != IS_LONG) { - ZVAL_DUP(&cast_option_buffer, option_buffer); - convert_to_long(&cast_option_buffer); - memory = Z_LVAL(cast_option_buffer); - zval_dtor(&cast_option_buffer); - } else { - memory = Z_LVAL_P(option_buffer); - } + memory = zval_get_long(option_buffer); } if (memory < 1 || memory > 9) { php_error_docref(NULL, E_WARNING, "compression memory level (%pd) must be within 1..9", memory);