Hello Felipe,
Tuesday, August 12, 2008, 9:38:55 PM, you wrote:
felipe Tue Aug 12 19:38:55 2008 UTC
Modified files: (Branch: PHP_5_3)
/php-src/ext/standard file.c
/php-src/ext/standard/tests/filefscanf.phpt fscanf_error.phpt
Log:
- New parameter parsing API (for fscanf)
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/file.c?r1=1.409.2.6.2.28.2.20r2=1.409.2.6.2.28.2.21diff_format=u
Index: php-src/ext/standard/file.c
diff -u php-src/ext/standard/file.c:1.409.2.6.2.28.2.20
php-src/ext/standard/file.c:1.409.2.6.2.28.2.21
--- php-src/ext/standard/file.c:1.409.2.6.2.28.2.20 Mon Aug 11 13:11:30
2008
+++ php-src/ext/standard/file.c Tue Aug 12 19:38:54 2008
@@ -21,7 +21,7 @@
+--+
*/
-/* $Id: file.c,v 1.409.2.6.2.28.2.20 2008/08/11 13:11:30 pajoye Exp $ */
+/* $Id: file.c,v 1.409.2.6.2.28.2.21 2008/08/12 19:38:54 felipe Exp $ */
/* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */
@@ -1168,30 +1168,18 @@
Implements a mostly ANSI compatible fscanf() */
PHP_FUNCTION(fscanf)
{
- int result;
- zval **file_handle, **format_string;
+ int result, format_len, type, argc = 0;
+ zval ***args = NULL;
+ zval *file_handle;
+ char *buf, *format;
size_t len;
- int type;
- char *buf;
void *what;
-
- zval ***args;
- int argCount;
-
- argCount = ZEND_NUM_ARGS();
- if (argCount 2) {
- WRONG_PARAM_COUNT;
- }
- args = (zval ***)safe_emalloc(argCount, sizeof(zval **), 0);
- if (zend_get_parameters_array_ex(argCount, args) == FAILURE) {
- efree( args );
- WRONG_PARAM_COUNT;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, rs*,
file_handle, format, format_len, args, argc) == FAILURE) {
+ return;
}
- file_handle = args[0];
- format_string = args[1];
-
- what = zend_fetch_resource(file_handle TSRMLS_CC, -1,
File-Handle, type, 2, php_file_le_stream(), php_file_le_pstream());
+ what = zend_fetch_resource(file_handle TSRMLS_CC, -1,
File-Handle, type, 2, php_file_le_stream(), php_file_le_pstream());
/*
* we can't do a ZEND_VERIFY_RESOURCE(what), otherwise we end up
@@ -1199,26 +1187,30 @@
* if the code behind ZEND_VERIFY_RESOURCE changed. - cc
*/
if (!what) {
- efree(args);
+ if (args) {
+ efree(args);
+ }
RETURN_FALSE;
}
buf = php_stream_get_line((php_stream *) what, NULL, 0, len);
if (buf == NULL) {
- efree(args);
+ if (args) {
+ efree(args);
+ }
RETURN_FALSE;
}
- convert_to_string_ex(format_string);
- result = php_sscanf_internal(buf, Z_STRVAL_PP(format_string),
argCount, args, 2, return_value TSRMLS_CC);
+ result = php_sscanf_internal(buf, format, argc, args, 0,
return_value TSRMLS_CC);
- efree(args);
+ if (args) {
+ efree(args);
+ }
efree(buf);
if (SCAN_ERROR_WRONG_PARAM_COUNT == result) {
WRONG_PARAM_COUNT;
}
-
}
/* }}} */
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/file/fscanf.phpt?r1=1.1.2.2.2.1r2=1.1.2.2.2.2diff_format=u
Index: php-src/ext/standard/tests/file/fscanf.phpt
diff -u php-src/ext/standard/tests/file/fscanf.phpt:1.1.2.2.2.1
php-src/ext/standard/tests/file/fscanf.phpt:1.1.2.2.2.2
--- php-src/ext/standard/tests/file/fscanf.phpt:1.1.2.2.2.1 Mon Nov 5
17:43:20 2007
+++ php-src/ext/standard/tests/file/fscanf.phpt Tue Aug 12 19:38:54 2008
@@ -60,14 +60,14 @@
echo Done\n;
?
--EXPECTF--
-Warning: Wrong parameter count for fscanf() in %s on line %d
+Warning: fscanf() expects at least 2 parameters, 0 given in %s on line %d
NULL
-Warning: Wrong parameter count for fscanf() in %s on line %d
+Warning: fscanf() expects at least 2 parameters, 1 given in %s on line %d
NULL
-Warning: fscanf(): supplied argument is not a valid File-Handle resource in
%s on line %d
-bool(false)
+Warning: fscanf() expects parameter 1 to be resource, array given in %s on
line %d
+NULL
int(0)
NULL
int(1)
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/file/fscanf_error.phpt?r1=1.1.2.1.2.1r2=1.1.2.1.2.2diff_format=u
Index: php-src/ext/standard/tests/file/fscanf_error.phpt
diff -u php-src/ext/standard/tests/file/fscanf_error.phpt:1.1.2.1.2.1
php-src/ext/standard/tests/file/fscanf_error.phpt:1.1.2.1.2.2
--- php-src/ext/standard/tests/file/fscanf_error.phpt:1.1.2.1.2.1 Mon
Nov 5 17:43:20 2007
+++ php-src/ext/standard/tests/file/fscanf_error.phpt Tue Aug 12