svn: /pecl/lzf/trunk/ filter.c lzf.c php_lzf.h tests/004.phpt tests/005.phpt
| From: | Remi Collet | Date: | Sat, 04 Apr 2015 08:08:12 +0000 |
| Subject: | svn: /pecl/lzf/trunk/ filter.c lzf.c php_lzf.h tests/004.phpt tests/005.phpt | ||
| Groups: | php.pecl.cvs | ||
| Request: | Send a blank email to pecl-cvs+get-22015@lists.php.net to get a copy of this message | ||
remi Sat, 04 Apr 2015 08:08:12 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=336357
Log:
Fix PHP 7 compatibility
- add test for lzf.compress filter
- add test for lzf.decompress filter
Notice: decompress filter doesn't work, but seems already broken in 5.4
Changed paths:
U pecl/lzf/trunk/filter.c
U pecl/lzf/trunk/lzf.c
U pecl/lzf/trunk/php_lzf.h
A pecl/lzf/trunk/tests/004.phpt
A pecl/lzf/trunk/tests/005.phpt
Modified: pecl/lzf/trunk/filter.c
===================================================================
--- pecl/lzf/trunk/filter.c 2015-04-04 06:53:08 UTC (rev 336356)
+++ pecl/lzf/trunk/filter.c 2015-04-04 08:08:12 UTC (rev 336357)
@@ -1,5 +1,6 @@
#include "php.h"
#include "lzf.h"
+#include "php_lzf.h"
#define LZF_BLOCKSIZE (1024 * 64 - 1)
@@ -160,7 +161,7 @@
int flags TSRMLS_DC)
{
size_t consumed = 0;
- php_lzf_filter_state *inst = (php_lzf_filter_state *) thisfilter->abstract;
+ php_lzf_filter_state *inst = (php_lzf_filter_state *) Z_PTR(thisfilter->abstract);
php_stream_filter_status_t exit_status = PSFS_FEED_ME;
php_stream_bucket *bucket = NULL;
@@ -208,8 +209,8 @@
{
assert(thisfilter->abstract != NULL);
- php_lzf_filter_state_dtor((php_lzf_filter_state *) thisfilter->abstract TSRMLS_CC);
- pefree(thisfilter->abstract, ((php_lzf_filter_state *)
thisfilter->abstract)->persistent);
+ php_lzf_filter_state_dtor((php_lzf_filter_state *) Z_PTR(thisfilter->abstract) TSRMLS_CC);
+ pefree(Z_PTR(thisfilter->abstract), ((php_lzf_filter_state *)
Z_PTR(thisfilter->abstract))->persistent);
}
static php_stream_filter_ops lzf_compress_ops = {
Modified: pecl/lzf/trunk/lzf.c
===================================================================
--- pecl/lzf/trunk/lzf.c 2015-04-04 06:53:08 UTC (rev 336356)
+++ pecl/lzf/trunk/lzf.c 2015-04-04 08:08:12 UTC (rev 336357)
@@ -41,7 +41,11 @@
PHP_FE(lzf_compress, NULL)
PHP_FE(lzf_decompress, NULL)
PHP_FE(lzf_optimized_for, NULL)
+#ifdef PHP_FE_END
+ PHP_FE_END
+#else
{NULL, NULL, NULL} /* Must be the last line in lzf_functions[] */
+#endif
};
/* }}} */
@@ -75,6 +79,8 @@
{
php_stream_filter_register_factory("lzf.compress", &php_lzf_compress_filter_factory
TSRMLS_CC);
php_stream_filter_register_factory("lzf.decompress",
&php_lzf_decompress_filter_factory TSRMLS_CC);
+
+ return SUCCESS;
}
/* }}} */
@@ -84,6 +90,8 @@
{
php_stream_filter_unregister_factory("lzf.compress" TSRMLS_CC);
php_stream_filter_unregister_factory("lzf.decompress" TSRMLS_CC);
+
+ return SUCCESS;
}
/* }}} */
@@ -110,7 +118,7 @@
PHP_FUNCTION(lzf_compress)
{
char *retval, *arg = NULL;
- int arg_len, result;
+ strsize_t arg_len, result;
if (ZEND_NUM_ARGS() != 1 || zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s",
&arg, &arg_len) == FAILURE) {
WRONG_PARAM_COUNT;
@@ -127,10 +135,10 @@
RETURN_FALSE;
}
- retval = erealloc(retval, result + 1);
retval[result] = 0;
- RETURN_STRINGL(retval, result, 0);
+ _RETVAL_STRINGL(retval, result);
+ efree(retval);
}
/* }}} */
@@ -139,7 +147,7 @@
PHP_FUNCTION(lzf_decompress)
{
char *arg = NULL;
- int arg_len, result, i = 1;
+ strsize_t arg_len, result, i = 1;
char *buffer;
size_t buffer_size = 1024;
@@ -168,10 +176,10 @@
RETURN_FALSE;
}
- buffer = erealloc(buffer, result + 1);
buffer[result] = 0;
- RETURN_STRINGL(buffer, result, 0);
+ _RETVAL_STRINGL(buffer, result);
+ efree(buffer);
}
/* }}} */
Modified: pecl/lzf/trunk/php_lzf.h
===================================================================
--- pecl/lzf/trunk/php_lzf.h 2015-04-04 06:53:08 UTC (rev 336356)
+++ pecl/lzf/trunk/php_lzf.h 2015-04-04 08:08:12 UTC (rev 336357)
@@ -49,6 +49,19 @@
PHP_FUNCTION(lzf_decompress);
PHP_FUNCTION(lzf_optimized_for);
+#if PHP_MAJOR_VERSION < 7
+typedef long zend_long;
+typedef int strsize_t;
+#define _RETVAL_STRINGL(a,l) RETVAL_STRINGL(a,l,1)
+#define Z_PTR(p) (p)
+#else
+typedef size_t strsize_t;
+#define TSRMLS_C
+#define TSRMLS_CC
+#define TSRMLS_DC
+#define _RETVAL_STRINGL(a,l) RETVAL_STRINGL(a,l)
+#endif
+
#endif /* PHP_LZF_H */
Added: pecl/lzf/trunk/tests/004.phpt
===================================================================
--- pecl/lzf/trunk/tests/004.phpt (rev 0)
+++ pecl/lzf/trunk/tests/004.phpt 2015-04-04 08:08:12 UTC (rev 336357)
@@ -0,0 +1,19 @@
+--TEST--
+filter lzf.compress
+--SKIPIF--
+<?php if (!extension_loaded("lzf")) print "skip"; ?>
+<?php if (!function_exists("base64_encode")) print "skip"; ?>
+--POST--
+--GET--
+--INI--
+--FILE--
+<?php
+$text = "This is test of LZF extension";
+$fp = fopen('php://stdout', 'w');
+stream_filter_append($fp, 'lzf.compress', STREAM_FILTER_WRITE);
+stream_filter_append($fp, 'convert.base64-encode', STREAM_FILTER_WRITE);
+fwrite($fp, $text);
+fclose($fp);
+?>
+--EXPECT--
+WlYAAB1UaGlzIGlzIHRlc3Qgb2YgTFpGIGV4dGVuc2lvbg==
Added: pecl/lzf/trunk/tests/005.phpt
===================================================================
--- pecl/lzf/trunk/tests/005.phpt (rev 0)
+++ pecl/lzf/trunk/tests/005.phpt 2015-04-04 08:08:12 UTC (rev 336357)
@@ -0,0 +1,19 @@
+--TEST--
+filter lzf.decompress
+--SKIPIF--
+<?php if (!extension_loaded("lzf")) print "skip"; ?>
+<?php if (!function_exists("base64_encode")) print "skip"; ?>
+--POST--
+--GET--
+--INI--
+--FILE--
+<?php
+$text = "WlYAAB1UaGlzIGlzIHRlc3Qgb2YgTFpGIGV4dGVuc2lvbg==";
+$fp = fopen('php://stdout', 'w');
+stream_filter_append($fp, 'convert.base64-decode', STREAM_FILTER_WRITE);
+stream_filter_append($fp, 'lzf.decompress', STREAM_FILTER_WRITE);
+fwrite($fp, $text);
+fclose($fp);
+?>
+--EXPECT--
+This is test of LZF extension