]> granicus.if.org Git - php/commitdiff
Tweak new deflate/inflate implementations
authorNikita Popov <nikic@php.net>
Sat, 25 Apr 2015 17:00:41 +0000 (19:00 +0200)
committerNikita Popov <nikic@php.net>
Sat, 25 Apr 2015 17:00:41 +0000 (19:00 +0200)
Return NULL on zpp.
Don't manually cast zvals to long.

ext/zlib/tests/inflate_init_error.phpt
ext/zlib/zlib.c

index ad1410cab4b8c3b18a49a71c1d3d25f0bbbd0eb7..0e0e8b33bf3d1fa1f79f62e02fbed5d44314357d 100644 (file)
@@ -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)
index 957be3417ce21d80c51fbffb04dbc29fece6deb8..7fcb6a1e517d36e74b010ee11fddddd5d4b3c7b9 100644 (file)
@@ -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);