]> granicus.if.org Git - php/commitdiff
bz2 changes for phpng
authorkrakjoe <joe.watkins@live.co.uk>
Thu, 8 May 2014 12:14:19 +0000 (13:14 +0100)
committerkrakjoe <joe.watkins@live.co.uk>
Thu, 8 May 2014 12:14:19 +0000 (13:14 +0100)
ext/bz2/bz2.c
ext/bz2/bz2_filter.c
ext/bz2/tests/004.phpt

index 1d1c0fb9b31505ee7b4d3840d9f355d0d37faeb6..c5ee3d6ec15c673d51c482964786b9e5469f3a0a 100644 (file)
@@ -227,7 +227,7 @@ PHP_BZ2_API php_stream *_php_stream_bz2open(php_stream_wrapper *wrapper,
        virtual_filepath_ex(path, &path_copy, NULL TSRMLS_CC);
 #else
        path_copy = path;
-#endif  
+#endif
 
        if (php_check_open_basedir(path_copy TSRMLS_CC)) {
                return NULL;
@@ -239,7 +239,8 @@ PHP_BZ2_API php_stream *_php_stream_bz2open(php_stream_wrapper *wrapper,
        if (opened_path && bz_file) {
                *opened_path = estrdup(path_copy);
        }
-       path_copy = NULL;
+       if (path_copy) 
+               efree(path_copy);
        
        if (bz_file == NULL) {
                /* that didn't work, so try and get something from the network/wrapper */
@@ -331,29 +332,31 @@ static PHP_FUNCTION(bzread)
        zval *bz;
        long len = 1024;
        php_stream *stream;
-
+       char *data;
+       size_t dlen;
+       
        if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|l", &bz, &len)) {
                RETURN_FALSE;
        }
        
-       php_stream_from_zval(stream, &bz);
+       php_stream_from_zval(stream, bz);
 
        if ((len + 1) < 1) {
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "length may not be negative");
                RETURN_FALSE;
        }
 
-       Z_STRVAL_P(return_value) = emalloc(len + 1);
-       Z_STRLEN_P(return_value) = php_stream_read(stream, Z_STRVAL_P(return_value), len);
+       data = emalloc(len + 1);
+       dlen = php_stream_read(stream, data, len);
        
-       if (Z_STRLEN_P(return_value) < 0) {
-               efree(Z_STRVAL_P(return_value));
+       if (dlen < 0) {
+               efree(data);
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "could not read valid bz2 data from stream");
                RETURN_FALSE;           
        }
-       
-       Z_STRVAL_P(return_value)[Z_STRLEN_P(return_value)] = 0;
-       Z_TYPE_P(return_value) = IS_STRING;
+
+       ZVAL_NEW_STR(return_value, STR_INIT(data, dlen, 0));
+       efree(data);
 }
 /* }}} */
 
@@ -361,14 +364,14 @@ static PHP_FUNCTION(bzread)
    Opens a new BZip2 stream */
 static PHP_FUNCTION(bzopen)
 {
-       zval    **file;   /* The file to open */
+       zval     *file;   /* The file to open */
        char     *mode;   /* The mode to open the stream with */
        int      mode_len;
 
        BZFILE   *bz;     /* The compressed file stream */
        php_stream *stream = NULL;
        
-       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Zs", &file, &mode, &mode_len) == FAILURE) {
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zs", &file, &mode, &mode_len) == FAILURE) {
                return;
        }
 
@@ -378,22 +381,22 @@ static PHP_FUNCTION(bzopen)
        }
 
        /* If it's not a resource its a string containing the filename to open */
-       if (Z_TYPE_PP(file) == IS_STRING) {
-               if (Z_STRLEN_PP(file) == 0) {
+       if (Z_TYPE_P(file) == IS_STRING) {
+               if (Z_STRLEN_P(file) == 0) {
                        php_error_docref(NULL TSRMLS_CC, E_WARNING, "filename cannot be empty");
                        RETURN_FALSE;
                }
                
-               if (CHECK_ZVAL_NULL_PATH(*file)) {
+               if (CHECK_ZVAL_NULL_PATH(file)) {
                        RETURN_FALSE;
                }
 
                stream = php_stream_bz2open(NULL,
-                                                                       Z_STRVAL_PP(file), 
+                                                                       Z_STRVAL_P(file), 
                                                                        mode, 
                                                                        REPORT_ERRORS, 
                                                                        NULL);
-       } else if (Z_TYPE_PP(file) == IS_RESOURCE) {
+       } else if (Z_TYPE_P(file) == IS_RESOURCE) {
                /* If it is a resource, than its a stream resource */
                php_socket_t fd;
                int stream_mode_len;
@@ -521,9 +524,8 @@ static PHP_FUNCTION(bzcompress)
        } else {
                /* Copy the buffer, we have perhaps allocate a lot more than we need,
                   so we erealloc() the buffer to the proper size */
-               dest = erealloc(dest, dest_len + 1);
-               dest[dest_len] = 0;
-               RETURN_STRINGL(dest, dest_len, 0);
+               RETVAL_STRINGL(dest, dest_len);
+               efree(dest);
        }
 }
 /* }}} */
@@ -572,7 +574,8 @@ static PHP_FUNCTION(bzdecompress)
                size = (bzs.total_out_hi32 * (unsigned int) -1) + bzs.total_out_lo32;
                dest = safe_erealloc(dest, 1, (size_t) size, 1);
                dest[size] = '\0';
-               RETVAL_STRINGL(dest, (int) size, 0);
+               RETVAL_STRINGL(dest, (int) size);
+               efree(dest);
        } else { /* real error */
                efree(dest);
                RETVAL_LONG(error);
@@ -596,7 +599,7 @@ static void php_bz2_error(INTERNAL_FUNCTION_PARAMETERS, int opt)
                return;
        }
 
-       php_stream_from_zval(stream, &bzp);
+       php_stream_from_zval(stream, bzp);
 
        if (!php_stream_is(stream, PHP_STREAM_IS_BZIP2)) {
                RETURN_FALSE;
@@ -613,7 +616,7 @@ static void php_bz2_error(INTERNAL_FUNCTION_PARAMETERS, int opt)
                        RETURN_LONG(errnum);
                        break;
                case PHP_BZ_ERRSTR:
-                       RETURN_STRING((char*)errstr, 1);
+                       RETURN_STRING((char*)errstr);
                        break;
                case PHP_BZ_ERRBOTH:
                        array_init(return_value);
index b6d8787274814c5d2f9b52629eb668b838fa1ed8..53431e04d41e606f918e2ae10ca8289f39ecce89 100644 (file)
@@ -80,12 +80,12 @@ static php_stream_filter_status_t php_bz2_decompress_filter(
        php_stream_filter_status_t exit_status = PSFS_FEED_ME;
        bz_stream *streamp;
 
-       if (!thisfilter || !thisfilter->abstract) {
+       if (!Z_PTR(thisfilter->abstract)) {
                /* Should never happen */
                return PSFS_ERR_FATAL;
        }
 
-       data = (php_bz2_filter_data *)(thisfilter->abstract);
+       data = (php_bz2_filter_data *)Z_PTR(thisfilter->abstract);
        streamp = &(data->strm);
 
        while (buckets_in->head) {
@@ -182,8 +182,8 @@ static php_stream_filter_status_t php_bz2_decompress_filter(
 
 static void php_bz2_decompress_dtor(php_stream_filter *thisfilter TSRMLS_DC)
 {
-       if (thisfilter && thisfilter->abstract) {
-               php_bz2_filter_data *data = thisfilter->abstract;
+       if (thisfilter && Z_PTR(thisfilter->abstract)) {
+               php_bz2_filter_data *data = Z_PTR(thisfilter->abstract);
                if (data->status == PHP_BZ2_RUNNING) {
                        BZ2_bzDecompressEnd(&(data->strm));
                }
@@ -217,12 +217,12 @@ static php_stream_filter_status_t php_bz2_compress_filter(
        int status;
        php_stream_filter_status_t exit_status = PSFS_FEED_ME;
 
-       if (!thisfilter || !thisfilter->abstract) {
+       if (!Z_PTR(thisfilter->abstract)) {
                /* Should never happen */
                return PSFS_ERR_FATAL;
        }
 
-       data = (php_bz2_filter_data *)(thisfilter->abstract);
+       data = (php_bz2_filter_data *)Z_PTR(thisfilter->abstract);
 
        while (buckets_in->head) {
                size_t bin = 0, desired;
@@ -288,8 +288,8 @@ static php_stream_filter_status_t php_bz2_compress_filter(
 
 static void php_bz2_compress_dtor(php_stream_filter *thisfilter TSRMLS_DC)
 {
-       if (thisfilter && thisfilter->abstract) {
-               php_bz2_filter_data *data = thisfilter->abstract;
+       if (Z_PTR(thisfilter->abstract)) {
+               php_bz2_filter_data *data = Z_PTR(thisfilter->abstract);
                BZ2_bzCompressEnd(&(data->strm));
                pefree(data->inbuf, data->persistent);
                pefree(data->outbuf, data->persistent);
@@ -347,34 +347,21 @@ static php_stream_filter *php_bz2_filter_create(const char *filtername, zval *fi
                data->expect_concatenated = 0;
 
                if (filterparams) {
-                       zval **tmpzval = NULL;
+                       zval *tmpzval = NULL;
 
                        if (Z_TYPE_P(filterparams) == IS_ARRAY || Z_TYPE_P(filterparams) == IS_OBJECT) {
-
-                               if (SUCCESS == zend_hash_find(HASH_OF(filterparams), "concatenated", sizeof("concatenated"), (void **) &tmpzval) ) {
-                                       zval tmp, *tmp2;
-
-                                       tmp = **tmpzval;
-                                       zval_copy_ctor(&tmp);
-                                       tmp2 = &tmp;
-                                       convert_to_boolean_ex(&tmp2);
-                                       data->expect_concatenated = Z_TMP(tmp) == IS_TRUE;
+                               if ((tmpzval = zend_hash_str_find(HASH_OF(filterparams), "concatenated", sizeof("concatenated")-1))) {
+                                       data->expect_concatenated = zend_is_true(tmpzval TSRMLS_CC);
                                        tmpzval = NULL;
                                }
 
-                               zend_hash_find(HASH_OF(filterparams), "small", sizeof("small"), (void **) &tmpzval);
+                               tmpzval = zend_hash_str_find(HASH_OF(filterparams), "small", sizeof("small")-1);
                        } else {
-                               tmpzval = &filterparams;
+                               tmpzval = filterparams;
                        }
 
                        if (tmpzval) {
-                               zval tmp, *tmp2;
-
-                               tmp = **tmpzval;
-                               zval_copy_ctor(&tmp);
-                               tmp2 = &tmp;
-                               convert_to_boolean_ex(&tmp2);
-                               data->small_footprint = Z_TYPE(tmp) == IS_TRUE;
+                               data->small_footprint = zend_is_true(tmpzval TSRMLS_CC);
                        }
                }
 
@@ -385,28 +372,28 @@ static php_stream_filter *php_bz2_filter_create(const char *filtername, zval *fi
                int workFactor = PHP_BZ2_FILTER_DEFAULT_WORKFACTOR;
 
                if (filterparams) {
-                       zval **tmpzval;
+                       zval *tmpzval;
 
                        if (Z_TYPE_P(filterparams) == IS_ARRAY || Z_TYPE_P(filterparams) == IS_OBJECT) {
-                               if (zend_hash_find(HASH_OF(filterparams), "blocks", sizeof("blocks"), (void**) &tmpzval) == SUCCESS) {
+                               if ((tmpzval = zend_hash_str_find(HASH_OF(filterparams), "blocks", sizeof("blocks")-1))) {
                                        /* How much memory to allocate (1 - 9) x 100kb */
                                        zval tmp;
        
-                                       tmp = **tmpzval;
+                                       tmp = *tmpzval;
                                        zval_copy_ctor(&tmp);
                                        convert_to_long(&tmp);
                                        if (Z_LVAL(tmp) < 1 || Z_LVAL(tmp) > 9) {
-                                               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid parameter given for number of blocks to allocate. (%ld)", Z_LVAL_PP(tmpzval));
+                                               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid parameter given for number of blocks to allocate. (%ld)", Z_LVAL_P(tmpzval));
                                        } else {
                                                blockSize100k = Z_LVAL(tmp);
                                        }
                                }
 
-                               if (zend_hash_find(HASH_OF(filterparams), "work", sizeof("work"), (void**) &tmpzval) == SUCCESS) {
+                               if ((tmpzval = zend_hash_str_find(HASH_OF(filterparams), "work", sizeof("work")-1))) {
                                        /* Work Factor (0 - 250) */
                                        zval tmp;
        
-                                       tmp = **tmpzval;
+                                       tmp = *tmpzval;
                                        zval_copy_ctor(&tmp);
                                        convert_to_long(&tmp);
 
index a638188bcb47725cda570e8570c4cfe9f7b0d425..7467d84a901af9036882c5c786192aa0ee2b6cf6 100644 (file)
@@ -97,15 +97,15 @@ array(2) {
 string(10) "DATA_ERROR"
 int(-4)
 
-Warning: bzread(): %d is not a valid stream resource in %s on line %d
+Warning: bzread(): supplied resource is not a valid stream resource in %s on line %d
 bool(false)
 
-Warning: bzerror(): %d is not a valid stream resource in %s on line %d
+Warning: bzerror(): supplied resource is not a valid stream resource in %s on line %d
 bool(false)
 
-Warning: bzerrstr(): %d is not a valid stream resource in %s on line %d
+Warning: bzerrstr(): supplied resource is not a valid stream resource in %s on line %d
 bool(false)
 
-Warning: bzerrno(): %d is not a valid stream resource in %s on line %d
+Warning: bzerrno(): supplied resource is not a valid stream resource in %s on line %d
 bool(false)
 Done