kjdev / php-ext-zstd

Zstd Extension for PHP
MIT License
201 stars 27 forks source link

Fix support php 5.2 #3

Closed sergey-dryabzhinsky closed 7 years ago

sergey-dryabzhinsky commented 7 years ago

And adjust some type formats.

kjdev commented 7 years ago

An error occurred in PHP 7.

I tried to change it as follows. Can I check because there is no environment of PHP 5.2?

--- a/zstd.c
+++ b/zstd.c
@@ -74,8 +74,13 @@ ZEND_FUNCTION(zstd_compress)
     zval *data;
     char *output;
     size_t len, size, result;
+#if ZEND_MODULE_API_NO >= 20090626
+    long level = DEFAULT_COMPRESS_LEVEL;
+    long maxLevel = (long)ZSTD_maxCLevel();
+#else
     uint32_t level = DEFAULT_COMPRESS_LEVEL;
     uint16_t maxLevel = (uint16_t)ZSTD_maxCLevel();
+#endif

     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
                               "z|l", &data, &level) == FAILURE) {
@@ -88,7 +93,11 @@ ZEND_FUNCTION(zstd_compress)
     }

     if (level > maxLevel || level < 0) {
+#if ZEND_MODULE_API_NO >= 20090626
+      zend_error(E_WARNING, "zstd_compress: compression level (%ld)"
+#else
       zend_error(E_WARNING, "zstd_compress: compression level (%d)"
+#endif
                  " must be within 1..%d", level, maxLevel);
       RETURN_FALSE;
     } else if (level == 0) {
@@ -127,7 +136,11 @@ ZEND_FUNCTION(zstd_compress)
 ZEND_FUNCTION(zstd_uncompress)
 {
     zval *data;
+#if ZEND_MODULE_API_NO >= 20090626
     uint64_t size;
+#else
+    unsigned long long size;
+#endif
     size_t result;
     void *output;
sergey-dryabzhinsky commented 7 years ago

Can you provide error text? And TravisCI done without errors: https://travis-ci.org/sergey-dryabzhinsky/php-ext-zstd/builds/195746019

kjdev commented 7 years ago

Environment: PHP 7.0.15 on Fedora 25

% phpize && ./configure && make
% make test
=====================================================================
PHP         : /usr/bin/php
PHP_SAPI    : cli
PHP_VERSION : 7.0.15
ZEND_VERSION: 3.0.0
PHP_OS      : Linux - Linux localhost.localdomain 4.9.5-200.fc25.x86_64
INI actual  : /path/to/php-ext-zstd/tmp-php.ini
More .INIs  :
CWD         : /path/to/php-ext-zstd
Extra dirs  :
VALGRIND    : Not used
=====================================================================
TIME START
=====================================================================
FAIL zstd_compress(): basic functionality [tests/001.phpt]
PASS zstd_compress(): error conditions [tests/002.phpt]
FAIL zstd_compress(): variation [tests/003.phpt]
PASS zstd_uncompress(): basic functionality [tests/004.phpt]
PASS zstd_uncompress(): error conditions [tests/005.phpt]
PASS unexpected exiting when uncompress the wrong format data [tests/006.phpt]
FAIL namespace: Zstd\compress()/uncompress() [tests/007.phpt]
FAIL zstd_compress(): compress level [tests/008.phpt]
PASS alias functionality [tests/alias.phpt]
PASS zstd_compress_dict(): basic functionality [tests/dictionary.phpt]
PASS phpinfo() displays zstd info [tests/info.phpt]
=====================================================================
TIME END

=====================================================================
TEST RESULT SUMMARY
---------------------------------------------------------------------
Exts skipped    :    0
Exts tested     :   15
---------------------------------------------------------------------

Number of tests :   11                11
Tests skipped   :    0 (  0.0%) --------
Tests warned    :    0 (  0.0%) (  0.0%)
Tests failed    :    4 ( 36.4%) ( 36.4%)
Expected fail   :    0 (  0.0%) (  0.0%)
Tests passed    :    7 ( 63.6%) ( 63.6%)
---------------------------------------------------------------------
Time taken      :    0 seconds
=====================================================================

=====================================================================
FAILED TEST SUMMARY
---------------------------------------------------------------------
zstd_compress(): basic functionality [tests/001.phpt]
zstd_compress(): variation [tests/003.phpt]
namespace: Zstd\compress()/uncompress() [tests/007.phpt]
zstd_compress(): compress level [tests/008.phpt]
=====================================================================
% cat tests/001.out
*** Compression ***

Termsig=11%  
% php tests/001.php
*** Compression ***
Segmentation fault
% : gdb run
Program received signal SIGSEGV, Segmentation fault.
0x00007fffeca3604a in zif_zstd_compress (execute_data=0x7ffff3813230,
    return_value=0x7ffff3813120) at /home/kjdev/work/php/php-ext-zstd/zstd.c:85
85          if (Z_TYPE_P(data) != IS_STRING) {

Fixed types. (Invalid previous change)

--- a/zstd.c
+++ b/zstd.c
@@ -74,7 +74,7 @@ ZEND_FUNCTION(zstd_compress)
     zval *data;
     char *output;
     size_t size, result;
-    uint32_t level = DEFAULT_COMPRESS_LEVEL;
+    long level = DEFAULT_COMPRESS_LEVEL;
     uint16_t maxLevel = (uint16_t)ZSTD_maxCLevel();

     if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
sergey-dryabzhinsky commented 7 years ago

Uh... Yeah, thats maybe the case. zend_parse_parameters need long type for l. I'll update branch.

kjdev commented 7 years ago

Thanks.