diff options
author | Alexey Zakhlestin <indeyets@php.net> | 2008-06-22 12:03:30 +0000 |
---|---|---|
committer | Alexey Zakhlestin <indeyets@php.net> | 2008-06-22 12:03:30 +0000 |
commit | e4ad58109fcc75379c70e05efe5b355358a71639 (patch) | |
tree | 0736069c320edee7ca091d58bb6c68769b69759a /ext/bz2 | |
parent | 592cecf7d4058169edddb48603b1ba31d3983061 (diff) | |
download | php-git-e4ad58109fcc75379c70e05efe5b355358a71639.tar.gz |
updated to the new parameter-parsing api
Diffstat (limited to 'ext/bz2')
-rw-r--r-- | ext/bz2/bz2.c | 71 | ||||
-rw-r--r-- | ext/bz2/tests/001.phpt | 2 | ||||
-rw-r--r-- | ext/bz2/tests/002.phpt | 4 | ||||
-rw-r--r-- | ext/bz2/tests/005.phpt | 2 |
4 files changed, 39 insertions, 40 deletions
diff --git a/ext/bz2/bz2.c b/ext/bz2/bz2.c index 3062a418b5..4abed85acf 100644 --- a/ext/bz2/bz2.c +++ b/ext/bz2/bz2.c @@ -364,23 +364,24 @@ static PHP_FUNCTION(bzread) 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 @@ static PHP_FUNCTION(bzopen) 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 @@ static PHP_FUNCTION(bzopen) 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 @@ static PHP_FUNCTION(bzopen) 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 @@ static PHP_FUNCTION(bzerror) 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 jeremy@nirvani.net 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 @@ static PHP_FUNCTION(bzdecompress) 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; diff --git a/ext/bz2/tests/001.phpt b/ext/bz2/tests/001.phpt index a4ef1a2af7..47dbfe8499 100644 --- a/ext/bz2/tests/001.phpt +++ b/ext/bz2/tests/001.phpt @@ -19,7 +19,7 @@ var_dump(bzopen($fp, "r")); 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 diff --git a/ext/bz2/tests/002.phpt b/ext/bz2/tests/002.phpt index 7b9673275c..c55e22d0af 100644 --- a/ext/bz2/tests/002.phpt +++ b/ext/bz2/tests/002.phpt @@ -85,12 +85,12 @@ resource(%d) of type (stream) 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 diff --git a/ext/bz2/tests/005.phpt b/ext/bz2/tests/005.phpt index fc2235d627..da29a6d0b4 100644 --- a/ext/bz2/tests/005.phpt +++ b/ext/bz2/tests/005.phpt @@ -38,7 +38,7 @@ var_dump(bzdecompress($data2)); 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) |