indeyets Sun Jun 22 12:03:30 2008 UTC Modified files: (Branch: PHP_5_3) /php-src/ext/bz2 bz2.c /php-src/ext/bz2/tests 001.phpt 002.phpt 005.phpt Log: updated to the new parameter-parsing api
http://cvs.php.net/viewvc.cgi/php-src/ext/bz2/bz2.c?r1=1.14.2.3.2.12.2.2&r2=1.14.2.3.2.12.2.3&diff_format=u Index: php-src/ext/bz2/bz2.c diff -u php-src/ext/bz2/bz2.c:1.14.2.3.2.12.2.2 php-src/ext/bz2/bz2.c:1.14.2.3.2.12.2.3 --- php-src/ext/bz2/bz2.c:1.14.2.3.2.12.2.2 Mon Dec 31 07:17:06 2007 +++ php-src/ext/bz2/bz2.c Sun Jun 22 12:03:30 2008 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: bz2.c,v 1.14.2.3.2.12.2.2 2007/12/31 07:17:06 sebastian Exp $ */ +/* $Id: bz2.c,v 1.14.2.3.2.12.2.3 2008/06/22 12:03:30 indeyets Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -364,23 +364,24 @@ Opens a new BZip2 stream */ static PHP_FUNCTION(bzopen) { - zval **file, /* The file to open */ - **mode; /* The mode to open the stream with */ + zval **file; /* The file to open */ + char *mode; /* The mode to open the stream with */ + long mode_len; + BZFILE *bz; /* The compressed file stream */ php_stream *stream = NULL; - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &file, &mode) == FAILURE) { - WRONG_PARAM_COUNT; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Zs", &file, &mode, &mode_len) == FAILURE) { + return; } - convert_to_string_ex(mode); - if (Z_STRLEN_PP(mode) != 1 || (Z_STRVAL_PP(mode)[0] != 'r' && Z_STRVAL_PP(mode)[0] != 'w')) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "'%s' is not a valid mode for bzopen(). Only 'w' and 'r' are supported.", Z_STRVAL_PP(mode)); + if (mode_len != 1 || (mode[0] != 'r' && mode[0] != 'w')) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "'%s' is not a valid mode for bzopen(). Only 'w' and 'r' are supported.", mode); RETURN_FALSE; } /* If it's not a resource its a string containing the filename to open */ - if (Z_TYPE_PP(file) != IS_RESOURCE) { + if (Z_TYPE_PP(file) == IS_STRING) { convert_to_string_ex(file); if (Z_STRLEN_PP(file) == 0) { @@ -390,10 +391,10 @@ stream = php_stream_bz2open(NULL, Z_STRVAL_PP(file), - Z_STRVAL_PP(mode), + mode, ENFORCE_SAFE_MODE | REPORT_ERRORS, NULL); - } else { + } else if (Z_TYPE_PP(file) == IS_RESOURCE) { /* If it is a resource, than its a stream resource */ int fd; int stream_mode_len; @@ -409,17 +410,17 @@ RETURN_FALSE; } - switch(Z_STRVAL_PP(mode)[0]) { + switch(mode[0]) { case 'r': /* only "r" and "rb" are supported */ - if (stream->mode[0] != Z_STRVAL_PP(mode)[0] && !(stream_mode_len == 2 && stream->mode[1] != Z_STRVAL_PP(mode)[0])) { + if (stream->mode[0] != mode[0] && !(stream_mode_len == 2 && stream->mode[1] != mode[0])) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "cannot read from a stream opened in write only mode"); RETURN_FALSE; } break; case 'w': /* support only "w"(b), "a"(b), "x"(b) */ - if (stream->mode[0] != Z_STRVAL_PP(mode)[0] && !(stream_mode_len == 2 && stream->mode[1] != Z_STRVAL_PP(mode)[0]) + if (stream->mode[0] != mode[0] && !(stream_mode_len == 2 && stream->mode[1] != mode[0]) && stream->mode[0] != 'a' && !(stream_mode_len == 2 && stream->mode[1] != 'a') && stream->mode[0] != 'x' && !(stream_mode_len == 2 && stream->mode[1] != 'x')) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "cannot write to a stream opened in read only mode"); @@ -435,9 +436,12 @@ RETURN_FALSE; } - bz = BZ2_bzdopen(fd, Z_STRVAL_PP(mode)); + bz = BZ2_bzdopen(fd, mode); - stream = php_stream_bz2open_from_BZFILE(bz, Z_STRVAL_PP(mode), stream); + stream = php_stream_bz2open_from_BZFILE(bz, mode, stream); + } else { + php_error_docref(NULL TSRMLS_CC, E_WARNING, "first parameter has to be string or file-resource"); + RETURN_FALSE; } if (stream) { @@ -476,47 +480,42 @@ Compresses a string into BZip2 encoded data */ static PHP_FUNCTION(bzcompress) { - zval **source, /* Source data to compress */ - **zblock_size, /* Optional block size to use */ - **zwork_factor; /* Optional work factor to use */ + char *source; /* Source data to compress */ + long zblock_size; /* Optional block size to use */ + long zwork_factor; /* Optional work factor to use */ char *dest = NULL; /* Destination to place the compressed data into */ int error, /* Error Container */ block_size = 4, /* Block size for compression algorithm */ work_factor = 0, /* Work factor for compression algorithm */ argc; /* Argument count */ - unsigned int source_len, /* Length of the source data */ - dest_len; /* Length of the destination buffer */ - + long source_len; /* Length of the source data */ + unsigned int dest_len; /* Length of the destination buffer */ + argc = ZEND_NUM_ARGS(); - if (argc < 1 || argc > 3 || zend_get_parameters_ex(argc, &source, &zblock_size, &zwork_factor) == FAILURE) { - WRONG_PARAM_COUNT; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|ll", &source, &source_len, &zblock_size, &zwork_factor) == FAILURE) { + return; } - convert_to_string_ex(source); - /* Assign them to easy to use variables, dest_len is initially the length of the data + .01 x length of data + 600 which is the largest size the results of the compression could possibly be, at least that's what the libbz2 docs say (thanks to [EMAIL PROTECTED] for pointing this out). */ - source_len = Z_STRLEN_PP(source); - dest_len = Z_STRLEN_PP(source) + (0.01 * Z_STRLEN_PP(source)) + 600; + dest_len = source_len + (0.01 * source_len) + 600; /* Allocate the destination buffer */ dest = emalloc(dest_len + 1); /* Handle the optional arguments */ if (argc > 1) { - convert_to_long_ex(zblock_size); - block_size = Z_LVAL_PP(zblock_size); + block_size = zblock_size; } if (argc > 2) { - convert_to_long_ex(zwork_factor); - work_factor = Z_LVAL_PP(zwork_factor); + work_factor = zwork_factor; } - error = BZ2_bzBuffToBuffCompress(dest, &dest_len, Z_STRVAL_PP(source), source_len, block_size, 0, work_factor); + error = BZ2_bzBuffToBuffCompress(dest, &dest_len, source, source_len, block_size, 0, work_factor); if (error != BZ_OK) { efree(dest); RETURN_LONG(error); @@ -588,17 +587,17 @@ The central error handling interface, does the work for bzerrno, bzerrstr and bzerror */ static void php_bz2_error(INTERNAL_FUNCTION_PARAMETERS, int opt) { - zval **bzp; /* BZip2 Resource Pointer */ + zval *bzp; /* BZip2 Resource Pointer */ php_stream *stream; const char *errstr; /* Error string */ int errnum; /* Error number */ struct php_bz2_stream_data_t *self; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &bzp) == FAILURE) { - WRONG_PARAM_COUNT; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &bzp) == FAILURE) { + return; } - php_stream_from_zval(stream, bzp); + php_stream_from_zval(stream, &bzp); if (!php_stream_is(stream, PHP_STREAM_IS_BZIP2)) { RETURN_FALSE; http://cvs.php.net/viewvc.cgi/php-src/ext/bz2/tests/001.phpt?r1=1.1.2.3&r2=1.1.2.3.2.1&diff_format=u Index: php-src/ext/bz2/tests/001.phpt diff -u php-src/ext/bz2/tests/001.phpt:1.1.2.3 php-src/ext/bz2/tests/001.phpt:1.1.2.3.2.1 --- php-src/ext/bz2/tests/001.phpt:1.1.2.3 Mon Jun 26 22:17:18 2006 +++ php-src/ext/bz2/tests/001.phpt Sun Jun 22 12:03:30 2008 @@ -19,7 +19,7 @@ echo "Done\n"; ?> --EXPECTF-- -Warning: Wrong parameter count for bzopen() in %s on line %d +Warning: bzopen() expects exactly 2 parameters, 0 given in %s on line %d NULL Warning: bzopen(): '' is not a valid mode for bzopen(). Only 'w' and 'r' are supported. in %s on line %d http://cvs.php.net/viewvc.cgi/php-src/ext/bz2/tests/002.phpt?r1=1.1.2.4&r2=1.1.2.4.2.1&diff_format=u Index: php-src/ext/bz2/tests/002.phpt diff -u php-src/ext/bz2/tests/002.phpt:1.1.2.4 php-src/ext/bz2/tests/002.phpt:1.1.2.4.2.1 --- php-src/ext/bz2/tests/002.phpt:1.1.2.4 Mon Sep 18 12:35:49 2006 +++ php-src/ext/bz2/tests/002.phpt Sun Jun 22 12:03:30 2008 @@ -85,12 +85,12 @@ Warning: fopen(bz_open_002.txt): failed to open stream: Bad file %s in %s on line %d -Warning: bzopen(): filename cannot be empty in %s on line %d +Warning: bzopen(): first parameter has to be string or file-resource in %s on line %d bool(false) Warning: fopen(bz_open_002.txt): failed to open stream: Bad file %s in %s on line %d -Warning: bzopen(): filename cannot be empty in %s on line %d +Warning: bzopen(): first parameter has to be string or file-resource in %s on line %d bool(false) Warning: bzopen(): cannot write to a stream opened in read only mode in %s on line %d http://cvs.php.net/viewvc.cgi/php-src/ext/bz2/tests/005.phpt?r1=1.1.2.2&r2=1.1.2.2.2.1&diff_format=u Index: php-src/ext/bz2/tests/005.phpt diff -u php-src/ext/bz2/tests/005.phpt:1.1.2.2 php-src/ext/bz2/tests/005.phpt:1.1.2.2.2.1 --- php-src/ext/bz2/tests/005.phpt:1.1.2.2 Fri Sep 14 15:28:03 2007 +++ php-src/ext/bz2/tests/005.phpt Sun Jun 22 12:03:30 2008 @@ -38,7 +38,7 @@ echo "Done\n"; ?> --EXPECTF-- -Warning: Wrong parameter count for bzcompress() in %s on line %d +Warning: bzcompress() expects at least 1 parameter, 0 given in %s on line %d NULL string(%d) "BZ%a" int(-2)
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php