summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnatol Belski <ab@php.net>2017-07-10 16:53:56 +0200
committerAnatol Belski <ab@php.net>2017-07-10 16:53:56 +0200
commita797421e9887ace7c1cb9d8c5aa63c21894a8a59 (patch)
tree9a1eedbc83844c77d5869ec7ff0fbae75a12d582
parent2689917b17fd6018950b2af0711cb7fff702135d (diff)
downloadphp-git-a797421e9887ace7c1cb9d8c5aa63c21894a8a59.tar.gz
Revert "Add more constants, improve comments, and add tests"
This reverts commit 0c4f11ecaad213483f98c39128e217f9b389f604.
-rw-r--r--ext/zlib/php_zlib.h1
-rw-r--r--ext/zlib/tests/inflate_get_read_len.phpt29
-rw-r--r--ext/zlib/tests/inflate_get_status.phpt60
-rw-r--r--ext/zlib/zlib.c73
4 files changed, 1 insertions, 162 deletions
diff --git a/ext/zlib/php_zlib.h b/ext/zlib/php_zlib.h
index e7f89055c7..d407455d33 100644
--- a/ext/zlib/php_zlib.h
+++ b/ext/zlib/php_zlib.h
@@ -48,7 +48,6 @@ typedef struct _php_zlib_buffer {
typedef struct _php_zlib_context {
z_stream Z;
char *inflateDict;
- size_t status;
size_t inflateDictlen;
php_zlib_buffer buffer;
} php_zlib_context;
diff --git a/ext/zlib/tests/inflate_get_read_len.phpt b/ext/zlib/tests/inflate_get_read_len.phpt
deleted file mode 100644
index 37c977789f..0000000000
--- a/ext/zlib/tests/inflate_get_read_len.phpt
+++ /dev/null
@@ -1,29 +0,0 @@
---TEST--
-inflate_get_read_len()
---SKIPIF--
-<?php if (!extension_loaded("zlib")) print "skip"; ?>
---FILE--
-<?php
-
-$uncompressed = "Hello world.";
-$random_junk = str_repeat("qebsouesl", 128);;
-
-$compressed = zlib_encode($uncompressed, ZLIB_ENCODING_DEFLATE);
-$compressed_len = strlen($compressed);
-$compressed .= $random_junk;
-
-$ctx = inflate_init(ZLIB_ENCODING_DEFLATE);
-$buf = inflate_add($ctx, $compressed);
-$detected_compressed_len = inflate_get_read_len($ctx);
-
-echo 'Status: ' . inflate_get_status($ctx) . "\n";
-echo 'Original compressed length: ' . $compressed_len . "\n";
-echo 'Detected compressed length: ' . $detected_compressed_len . "\n";
-
-echo ($compressed_len == $detected_compressed_len) ? 'The lengths are equal.' : 'The lengths are unequal.';
-?>
---EXPECT--
-Status: 1
-Original compressed length: 20
-Detected compressed length: 20
-The lengths are equal.
diff --git a/ext/zlib/tests/inflate_get_status.phpt b/ext/zlib/tests/inflate_get_status.phpt
deleted file mode 100644
index d042840515..0000000000
--- a/ext/zlib/tests/inflate_get_status.phpt
+++ /dev/null
@@ -1,60 +0,0 @@
---TEST--
-inflate_get_status()
---SKIPIF--
-<?php if (!extension_loaded("zlib")) print "skip"; ?>
---FILE--
-<?php
-
-$uncompressed = "Hello world.";
-$random_junk = str_repeat("qebsouesl", 128);;
-
-$compressed = zlib_encode($uncompressed, ZLIB_ENCODING_DEFLATE);
-$compressed_len = strlen($compressed);
-$compressed .= $random_junk;
-
-$ctx = inflate_init(ZLIB_ENCODING_DEFLATE);
-$status = inflate_get_status($ctx);
-$buf = '';
-
-for ($i = 0; $status == ZLIB_OK; ++$i)
-{
- $buf .= inflate_add($ctx, substr($compressed, $i, 1));
- echo '$i = ' . $i . ', ';
- $status = inflate_get_status($ctx);
- echo 'Status: ' . $status;
- echo "\n";
-}
-
-echo '$buf = ' . $buf;
-echo "\n\n";
-
-echo "Adding more data should reset the stream and result in a Z_OK (ZLIB_OK) status.\n";
-inflate_add($ctx, substr($compressed, 0, 12));
-echo 'Status: ' . inflate_get_status($ctx);
-
-?>
---EXPECT--
-$i = 0, Status: 0
-$i = 1, Status: 0
-$i = 2, Status: 0
-$i = 3, Status: 0
-$i = 4, Status: 0
-$i = 5, Status: 0
-$i = 6, Status: 0
-$i = 7, Status: 0
-$i = 8, Status: 0
-$i = 9, Status: 0
-$i = 10, Status: 0
-$i = 11, Status: 0
-$i = 12, Status: 0
-$i = 13, Status: 0
-$i = 14, Status: 0
-$i = 15, Status: 0
-$i = 16, Status: 0
-$i = 17, Status: 0
-$i = 18, Status: 0
-$i = 19, Status: 1
-$buf = Hello world.
-
-Adding more data should reset the stream and result in a Z_OK (ZLIB_OK) status.
-Status: 0
diff --git a/ext/zlib/zlib.c b/ext/zlib/zlib.c
index 00a1e678c8..b3c1a88fc5 100644
--- a/ext/zlib/zlib.c
+++ b/ext/zlib/zlib.c
@@ -868,7 +868,6 @@ PHP_FUNCTION(inflate_init)
ctx->zfree = php_zlib_free;
((php_zlib_context *) ctx)->inflateDict = dict;
((php_zlib_context *) ctx)->inflateDictlen = dictlen;
- ((php_zlib_context *) ctx)->status = Z_OK;
if (encoding < 0) {
encoding += 15 - window;
@@ -936,13 +935,6 @@ PHP_FUNCTION(inflate_add)
"flush mode must be ZLIB_NO_FLUSH, ZLIB_PARTIAL_FLUSH, ZLIB_SYNC_FLUSH, ZLIB_FULL_FLUSH, ZLIB_BLOCK or ZLIB_FINISH");
RETURN_FALSE;
}
-
- /* Lazy-resetting the zlib stream so ctx->total_in remains available until the next inflate_add() call. */
- if (((php_zlib_context *) ctx)->status == Z_STREAM_END)
- {
- ((php_zlib_context *) ctx)->status = Z_OK;
- inflateReset(ctx);
- }
if (in_len <= 0 && flush_type != Z_FINISH) {
RETURN_EMPTY_STRING();
@@ -958,8 +950,6 @@ PHP_FUNCTION(inflate_add)
status = inflate(ctx, flush_type);
buffer_used = ZSTR_LEN(out) - ctx->avail_out;
- ((php_zlib_context *) ctx)->status = status; /* Save status for exposing to userspace */
-
switch (status) {
case Z_OK:
if (ctx->avail_out == 0) {
@@ -972,6 +962,7 @@ PHP_FUNCTION(inflate_add)
goto complete;
}
case Z_STREAM_END:
+ inflateReset(ctx);
goto complete;
case Z_BUF_ERROR:
if (flush_type == Z_FINISH && ctx->avail_out == 0) {
@@ -1020,48 +1011,6 @@ PHP_FUNCTION(inflate_add)
}
/* }}} */
-/* {{{ proto bool inflate_get_status(resource context)
- Get decompression status, usually returns either ZLIB_OK or ZLIB_STREAM_END. */
-PHP_FUNCTION(inflate_get_status)
-{
- zval *res;
- z_stream *ctx;
-
- if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "r", &res))
- {
- RETURN_NULL();
- }
-
- if (!(ctx = zend_fetch_resource_ex(res, NULL, le_inflate))) {
- php_error_docref(NULL, E_WARNING, "Invalid zlib.inflate resource");
- RETURN_FALSE;
- }
-
- RETURN_LONG(((php_zlib_context *) ctx)->status);
-}
-/* }}} */
-
-/* {{{ proto bool inflate_get_read_len(resource context)
- Get number of bytes read so far. */
-PHP_FUNCTION(inflate_get_read_len)
-{
- zval *res;
- z_stream *ctx;
-
- if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "r", &res))
- {
- RETURN_NULL();
- }
-
- if (!(ctx = zend_fetch_resource_ex(res, NULL, le_inflate))) {
- php_error_docref(NULL, E_WARNING, "Invalid zlib.inflate resource");
- RETURN_FALSE;
- }
-
- RETURN_LONG(ctx->total_in);
-}
-/* }}} */
-
/* {{{ proto resource deflate_init(int encoding[, array options])
Initialize an incremental deflate context using the specified encoding */
PHP_FUNCTION(deflate_init)
@@ -1373,14 +1322,6 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_inflate_add, 0, 0, 2)
ZEND_ARG_INFO(0, flush_behavior)
ZEND_END_ARG_INFO()
-ZEND_BEGIN_ARG_INFO_EX(arginfo_inflate_get_status, 0, 0, 1)
- ZEND_ARG_INFO(0, resource)
-ZEND_END_ARG_INFO()
-
-ZEND_BEGIN_ARG_INFO_EX(arginfo_inflate_get_read_len, 0, 0, 1)
- ZEND_ARG_INFO(0, resource)
-ZEND_END_ARG_INFO()
-
/* }}} */
/* {{{ php_zlib_functions[] */
@@ -1413,8 +1354,6 @@ static const zend_function_entry php_zlib_functions[] = {
PHP_FE(deflate_add, arginfo_deflate_add)
PHP_FE(inflate_init, arginfo_inflate_init)
PHP_FE(inflate_add, arginfo_inflate_add)
- PHP_FE(inflate_get_status, arginfo_inflate_get_status)
- PHP_FE(inflate_get_read_len, arginfo_inflate_get_read_len)
PHP_FE(ob_gzhandler, arginfo_ob_gzhandler)
PHP_FE_END
};
@@ -1530,16 +1469,6 @@ static PHP_MINIT_FUNCTION(zlib)
REGISTER_STRING_CONSTANT("ZLIB_VERSION", ZLIB_VERSION, CONST_CS|CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("ZLIB_VERNUM", ZLIB_VERNUM, CONST_CS|CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("ZLIB_OK", Z_OK, CONST_CS|CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("ZLIB_STREAM_END", Z_STREAM_END, CONST_CS|CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("ZLIB_NEED_DICT", Z_NEED_DICT, CONST_CS|CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("ZLIB_ERRNO", Z_ERRNO, CONST_CS|CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("ZLIB_STREAM_ERROR", Z_STREAM_ERROR, CONST_CS|CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("ZLIB_DATA_ERROR", Z_DATA_ERROR, CONST_CS|CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("ZLIB_MEM_ERROR", Z_MEM_ERROR, CONST_CS|CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("ZLIB_BUF_ERROR", Z_BUF_ERROR, CONST_CS|CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("ZLIB_VERSION_ERROR", Z_VERSION_ERROR, CONST_CS|CONST_PERSISTENT);
-
REGISTER_INI_ENTRIES();
return SUCCESS;
}