andrei Thu Nov 30 21:18:22 2006 UTC Modified files: /php-src/ext/standard pack.c Log: Mark pack()/unpack() as Unicode-safe. They will accept Unicode strings but convert them to binary. We can revisit supporting something like 'U' format in the future, if it's needed. http://cvs.php.net/viewvc.cgi/php-src/ext/standard/pack.c?r1=1.63&r2=1.64&diff_format=u Index: php-src/ext/standard/pack.c diff -u php-src/ext/standard/pack.c:1.63 php-src/ext/standard/pack.c:1.64 --- php-src/ext/standard/pack.c:1.63 Sun Nov 19 18:21:50 2006 +++ php-src/ext/standard/pack.c Thu Nov 30 21:18:22 2006 @@ -15,7 +15,7 @@ | Author: Chris Schneider <[EMAIL PROTECTED]> | +----------------------------------------------------------------------+ */ -/* $Id: pack.c,v 1.63 2006/11/19 18:21:50 iliaa Exp $ */ +/* $Id: pack.c,v 1.64 2006/11/30 21:18:22 andrei Exp $ */ #include "php.h" @@ -98,7 +98,7 @@ /* pack() idea stolen from Perl (implemented formats behave the same as there) * Implemented formats are A, a, h, H, c, C, s, S, i, I, l, L, n, N, f, d, x, X, @. */ -/* {{{ proto string pack(string format, mixed arg1 [, mixed arg2 [, mixed ...]]) +/* {{{ proto string pack(string format, mixed arg1 [, mixed arg2 [, mixed ...]]) U Takes one or more arguments and packs them into a binary string according to the format argument */ PHP_FUNCTION(pack) { @@ -113,27 +113,15 @@ int outputpos = 0, outputsize = 0; char *output; - argc = ZEND_NUM_ARGS(); - - if (argc < 1) { - WRONG_PARAM_COUNT; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s&*", &format, + &formatlen, UG(ascii_conv), &argv, &argc) == FAILURE) { + return; } - argv = safe_emalloc(argc, sizeof(zval **), 0); - - if (zend_get_parameters_array_ex(argc, argv) == FAILURE) { - efree(argv); - WRONG_PARAM_COUNT; - } - - convert_to_string_ex(argv[0]); - format = Z_STRVAL_PP(argv[0]); - formatlen = Z_STRLEN_PP(argv[0]); - /* We have a maximum of <formatlen> format codes to deal with */ formatcodes = safe_emalloc(formatlen, sizeof(*formatcodes), 0); formatargs = safe_emalloc(formatlen, sizeof(*formatargs), 0); - currentarg = 1; + currentarg = 0; /* Preprocess format into formatcodes and formatargs */ for (i = 0; i < formatlen; formatcount++) { @@ -303,7 +291,7 @@ output = emalloc(outputsize + 1); outputpos = 0; - currentarg = 1; + currentarg = 0; /* Do actual packing */ for (i = 0; i < formatcount; i++) { @@ -506,30 +494,21 @@ * f and d will return doubles. * Implemented formats are A, a, h, H, c, C, s, S, i, I, l, L, n, N, f, d, x, X, @. */ -/* {{{ proto array unpack(string format, string input) +/* {{{ proto array unpack(string format, string input) U Unpack binary string into named array elements according to format argument */ PHP_FUNCTION(unpack) { - zval **formatarg; - zval **inputarg; char *format; char *input; int formatlen; int inputpos, inputlen; int i; - if (ZEND_NUM_ARGS() != 2 || - zend_get_parameters_ex(2, &formatarg, &inputarg) == FAILURE) { - WRONG_PARAM_COUNT; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s&s", &format, + &formatlen, UG(ascii_conv), &input, &inputlen) == FAILURE) { + return; } - convert_to_string_ex(formatarg); - convert_to_string_ex(inputarg); - - format = Z_STRVAL_PP(formatarg); - formatlen = Z_STRLEN_PP(formatarg); - input = Z_STRVAL_PP(inputarg); - inputlen = Z_STRLEN_PP(inputarg); inputpos = 0; array_init(return_value);
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php