upgrade the rest of the functions to Unicode (except ob_gzhandler, that I leave for Mike).

also update tests to force binary data to be passed
This commit is contained in:
Nuno Lopes 2006-07-27 16:31:07 +00:00
parent ae95b257f8
commit 0e29c9a870
9 changed files with 51 additions and 51 deletions

View File

@ -54,9 +54,6 @@ PHP_FUNCTION(gzencode);
PHP_FUNCTION(ob_gzhandler);
PHP_FUNCTION(zlib_get_coding_type);
int php_enable_output_compression(int buffer_size TSRMLS_DC);
int php_ob_gzhandler_check(zval *handler_name TSRMLS_DC);
php_stream *php_stream_gzopen(php_stream_wrapper *wrapper, char *path, char *mode, int options, char **opened_path, php_stream_context *context STREAMS_DC TSRMLS_DC);
extern php_stream_ops php_stream_gzio_ops;
extern php_stream_wrapper php_stream_gzip_wrapper;

View File

@ -5,19 +5,19 @@ gzdeflate()/gzinflate()
--FILE--
<?php /* $Id$ */
$original = str_repeat("hallo php",4096);
$packed=gzdeflate($original);
$packed=gzdeflate((binary)$original);
echo strlen($packed)." ".strlen($original)."\n";
$unpacked=gzinflate($packed);
if (strcmp($original,$unpacked)==0) echo "Strings are equal\n";
/* with explicit compression level, length */
$original = str_repeat("hallo php",4096);
$packed=gzdeflate($original, 9);
$packed=gzdeflate((binary)$original, 9);
echo strlen($packed)." ".strlen($original)."\n";
$unpacked=gzinflate($packed, 40000);
if (strcmp($original,$unpacked)==0) echo "Strings are equal\n";
$original = 'aaaaaaaaaaaaaaa';
$original = b'aaaaaaaaaaaaaaa';
$packed=gzdeflate($original);
echo strlen($packed)." ".strlen($original)."\n";
$unpacked=gzinflate($packed);

View File

@ -5,14 +5,14 @@ gzcompress()/gzuncompress()
--FILE--
<?php /* $Id$ */
$original = str_repeat("hallo php",4096);
$packed=gzcompress($original);
$packed=gzcompress((binary)$original);
echo strlen($packed)." ".strlen($original)."\n";
$unpacked=gzuncompress($packed);
if (strcmp($original,$unpacked)==0) echo "Strings are equal\n";
/* with explicit compression level, length */
$original = str_repeat("hallo php",4096);
$packed=gzcompress($original, 9);
$packed=gzcompress((binary)$original, 9);
echo strlen($packed)." ".strlen($original)."\n";
$unpacked=gzuncompress($packed, 40000);
if (strcmp($original,$unpacked)==0) echo "Strings are equal\n";

View File

@ -4,7 +4,7 @@ gzencode()/base64_encode()
<?php if (!extension_loaded("zlib")) print "skip"; ?>
--FILE--
<?php
$original = str_repeat("hallo php",4096);
$original = (binary)str_repeat("hallo php",4096);
$packed=gzencode($original);
echo strlen($packed)." ".strlen($original)."\n";
if (strcmp(base64_encode($packed),"H4sIAAAAAAAAA+3GoQ0AQAgEsFV+NdwJEthf/R6kVU11z9tsRERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERERETu5gPlQAe9AJAAAA==")==0) echo "Strings are equal";

View File

@ -6,13 +6,13 @@ gzcompress()/gzuncompress() and invalid params
<?php
var_dump(gzcompress());
var_dump(gzcompress("", 1000));
var_dump(gzcompress("", -1));
var_dump(gzcompress(b"", 1000));
var_dump(gzcompress(b"", -1));
var_dump(gzcompress(""));
var_dump(gzcompress("", 9));
var_dump(gzcompress(b""));
var_dump(gzcompress(b"", 9));
$string = "Answer me, it can't be so hard
$string = b"Answer me, it can't be so hard
Cry to relieve what's in your heart
Desolation, grief and agony";
@ -20,16 +20,16 @@ var_dump($data1 = gzcompress($string));
var_dump($data2 = gzcompress($string, 9));
var_dump(gzuncompress());
var_dump(gzuncompress("", 1000));
var_dump(gzuncompress("", -1));
var_dump(gzuncompress(b"", 1000));
var_dump(gzuncompress(b"", -1));
var_dump(gzuncompress(""));
var_dump(gzuncompress("", 9));
var_dump(gzuncompress(b""));
var_dump(gzuncompress(b"", 9));
var_dump(gzuncompress($data1));
var_dump(gzuncompress($data2));
$data2{4} = 0;
var_dump(gzuncompress($data2));
var_dump(gzuncompress((binary)$data2));
echo "Done\n";
?>

View File

@ -6,13 +6,13 @@ gzdeflate()/gzinflate() and invalid params
<?php
var_dump(gzdeflate());
var_dump(gzdeflate("", 1000));
var_dump(gzdeflate("", -1));
var_dump(gzdeflate(b"", 1000));
var_dump(gzdeflate(b"", -1));
var_dump(gzdeflate(""));
var_dump(gzdeflate("", 9));
var_dump(gzdeflate(b""));
var_dump(gzdeflate(b"", 9));
$string = "Answer me, it can't be so hard
$string = b"Answer me, it can't be so hard
Cry to relieve what's in your heart
Desolation, grief and agony";
@ -20,17 +20,17 @@ var_dump($data1 = gzdeflate($string));
var_dump($data2 = gzdeflate($string, 9));
var_dump(gzinflate());
var_dump(gzinflate(""));
var_dump(gzinflate("asfwe", 1000));
var_dump(gzinflate("asdf", -1));
var_dump(gzinflate(b""));
var_dump(gzinflate(b"asfwe", 1000));
var_dump(gzinflate(b"asdf", -1));
var_dump(gzinflate("asdf"));
var_dump(gzinflate("asdf", 9));
var_dump(gzinflate(b"asdf"));
var_dump(gzinflate(b"asdf", 9));
var_dump(gzinflate($data1));
var_dump(gzinflate($data2));
$data2{4} = 0;
var_dump(gzinflate($data2));
var_dump(gzinflate((binary)$data2));
echo "Done\n";
?>

View File

@ -7,14 +7,14 @@ gzencode() and invalid params
var_dump(gzencode());
var_dump(gzencode(1,1,1,1));
var_dump(gzencode("", -10));
var_dump(gzencode("", 100));
var_dump(gzencode("", 1, 100));
var_dump(gzencode(b"", -10));
var_dump(gzencode(b"", 100));
var_dump(gzencode(b"", 1, 100));
var_dump(gzencode("", -1, 1));
var_dump(gzencode("", 9, 2));
var_dump(gzencode(b"", -1, 1));
var_dump(gzencode(b"", 9, 2));
$string = "Light of my sun
$string = b"Light of my sun
Light in this temple
Light in my truth
Lies in the darkness";

View File

@ -21,9 +21,9 @@ foreach ($b as $size) {
for ($i = 0; $i <= $size; ++$i) {
$s .= chr(rand(0,255));
}
var_dump($s == gzinflate(gzdeflate($s)));
var_dump($s == gzuncompress(gzcompress($s)));
var_dump($s == gzinflate(substr(gzencode($s), 10, -8)));
var_dump($s == gzinflate(gzdeflate((binary)$s)));
var_dump($s == gzuncompress(gzcompress((binary)$s)));
var_dump($s == gzinflate(substr(gzencode((binary)$s), 10, -8)));
}
?>
--EXPECT--

View File

@ -83,6 +83,9 @@
/* True globals, no need for thread safety */
static int gz_magic[2] = {0x1f, 0x8b}; /* gzip magic header */
static int php_enable_output_compression(int buffer_size TSRMLS_DC);
static int php_ob_gzhandler_check(zval *handler_name TSRMLS_DC);
/* {{{ php_zlib_functions[]
*/
zend_function_entry php_zlib_functions[] = {
@ -395,7 +398,7 @@ PHP_FUNCTION(readgzfile)
}
/* }}} */
/* {{{ proto string gzcompress(string data [, int level])
/* {{{ proto string gzcompress(string data [, int level]) U
Gzip-compress a string */
PHP_FUNCTION(gzcompress)
{
@ -404,7 +407,7 @@ PHP_FUNCTION(gzcompress)
unsigned long l2;
char *data, *s2;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &data, &data_len, &level) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S|l", &data, &data_len, &level) == FAILURE) {
return;
}
@ -437,7 +440,7 @@ PHP_FUNCTION(gzcompress)
}
/* }}} */
/* {{{ proto string gzuncompress(string data [, int length])
/* {{{ proto string gzuncompress(string data [, int length]) U
Unzip a gzip-compressed string */
PHP_FUNCTION(gzuncompress)
{
@ -447,7 +450,7 @@ PHP_FUNCTION(gzuncompress)
unsigned long plength=0, length;
char *data, *s1=NULL, *s2=NULL;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &data, &data_len, &limit) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S|l", &data, &data_len, &limit) == FAILURE) {
return;
}
@ -483,7 +486,7 @@ PHP_FUNCTION(gzuncompress)
}
/* }}} */
/* {{{ proto string gzdeflate(string data [, int level])
/* {{{ proto string gzdeflate(string data [, int level]) U
Gzip-compress a string */
PHP_FUNCTION(gzdeflate)
{
@ -492,7 +495,7 @@ PHP_FUNCTION(gzdeflate)
z_stream stream;
char *data, *s2;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &data, &data_len, &level) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S|l", &data, &data_len, &level) == FAILURE) {
return;
}
@ -544,7 +547,7 @@ PHP_FUNCTION(gzdeflate)
}
/* }}} */
/* {{{ proto string gzinflate(string data [, int length])
/* {{{ proto string gzinflate(string data [, int length]) U
Unzip a gzip-compressed string */
PHP_FUNCTION(gzinflate)
{
@ -555,7 +558,7 @@ PHP_FUNCTION(gzinflate)
char *data, *s1=NULL, *s2=NULL;
z_stream stream;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &data, &data_len, &limit) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S|l", &data, &data_len, &limit) == FAILURE) {
return;
}
@ -758,7 +761,7 @@ static int php_deflate_string(const char *str, uint str_length, char **newstr, u
}
/* }}} */
/* {{{ proto string gzencode(string data [, int level [, int encoding_mode]])
/* {{{ proto string gzencode(string data [, int level [, int encoding_mode]]) U
GZ encode a string */
PHP_FUNCTION(gzencode)
{
@ -768,7 +771,7 @@ PHP_FUNCTION(gzencode)
int status;
z_stream stream;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|ll", &data, &data_len, &level, &coding) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "S|ll", &data, &data_len, &level, &coding) == FAILURE) {
return;
}
@ -862,7 +865,7 @@ PHP_FUNCTION(gzencode)
/* {{{ php_ob_gzhandler_check
*/
int php_ob_gzhandler_check(zval *handler_name TSRMLS_DC)
static int php_ob_gzhandler_check(zval *handler_name TSRMLS_DC)
{
/* check for wrong usages */
if (php_output_get_level(TSRMLS_C) > 0) {
@ -1012,7 +1015,7 @@ static void php_gzip_output_handler(char *output, uint output_len, char **handle
/* {{{ php_enable_output_compression
*/
int php_enable_output_compression(int buffer_size TSRMLS_DC)
static int php_enable_output_compression(int buffer_size TSRMLS_DC)
{
zval **a_encoding, *output_handler;