mattwil Wed Apr 1 17:05:37 2009 UTC
Removed files: (Branch: PHP_5_3)
/php-src/ext/standard/tests/strings bug47546.phpt
Modified files:
/php-src NEWS
/php-src/ext/standard php_string.h string.c
Log:
MFH: explode() stuff:
- Fixed bug #47560 (explode()'s limit parameter odd behaviour) by reverting
change for bug #47546
- Changed int to long where needed (should fix memory errors from overflow
seen in bug #47854)
- Simplified logic a bit with limit and its default value
- php_explode_negative_limit(): removed safe_emalloc (not needed; plain
erealloc is used later)
- Moved declarations/allocation to optimize if the delimiter isn't found
- Changed ALLOC_STEP size for less realloc's (and maybe better memory block
alignment?)
http://cvs.php.net/viewvc.cgi/php-src/NEWS?r1=1.2027.2.547.2.965.2.548&r2=1.2027.2.547.2.965.2.549&diff_format=u
Index: php-src/NEWS
diff -u php-src/NEWS:1.2027.2.547.2.965.2.548
php-src/NEWS:1.2027.2.547.2.965.2.549
--- php-src/NEWS:1.2027.2.547.2.965.2.548 Wed Apr 1 14:00:35 2009
+++ php-src/NEWS Wed Apr 1 17:05:34 2009
@@ -18,6 +18,7 @@
crashes). (Dmitry)
- Fixed bug #47699 (autoload and late static binding). (Dmitry)
- Fixed bug #47596 (Bus error on parsing file). (Dmitry)
+- Fixed bug #47560 (explode()'s limit parameter odd behaviour). (Matt)
- Fixed bug #47516 (nowdoc can not be embed in heredoc but can be embed in
double quote). (Dmitry)
- Fixed bug #47038 (Memory leak in include). (Dmitry)
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/php_string.h?r1=1.87.2.2.2.3.2.4&r2=1.87.2.2.2.3.2.5&diff_format=u
Index: php-src/ext/standard/php_string.h
diff -u php-src/ext/standard/php_string.h:1.87.2.2.2.3.2.4
php-src/ext/standard/php_string.h:1.87.2.2.2.3.2.5
--- php-src/ext/standard/php_string.h:1.87.2.2.2.3.2.4 Wed Dec 31 11:15:45 2008
+++ php-src/ext/standard/php_string.h Wed Apr 1 17:05:35 2009
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_string.h,v 1.87.2.2.2.3.2.4 2008/12/31 11:15:45 sebastian Exp $ */
+/* $Id: php_string.h,v 1.87.2.2.2.3.2.5 2009/04/01 17:05:35 mattwil Exp $ */
/* Synced with php 3.0 revision 1.43 1999-06-16 [ssb] */
@@ -138,7 +138,7 @@
PHPAPI int php_char_to_str_ex(char *str, uint len, char from, char *to, int
to_len, zval *result, int case_sensitivity, int *replace_count);
PHPAPI int php_char_to_str(char *str, uint len, char from, char *to, int
to_len, zval *result);
PHPAPI void php_implode(zval *delim, zval *arr, zval *return_value TSRMLS_DC);
-PHPAPI void php_explode(zval *delim, zval *str, zval *return_value, int limit);
+PHPAPI void php_explode(zval *delim, zval *str, zval *return_value, long
limit);
PHPAPI size_t php_strspn(char *s1, char *s2, char *s1_end, char *s2_end);
PHPAPI size_t php_strcspn(char *s1, char *s2, char *s1_end, char *s2_end);
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/string.c?r1=1.445.2.14.2.69.2.45&r2=1.445.2.14.2.69.2.46&diff_format=u
Index: php-src/ext/standard/string.c
diff -u php-src/ext/standard/string.c:1.445.2.14.2.69.2.45
php-src/ext/standard/string.c:1.445.2.14.2.69.2.46
--- php-src/ext/standard/string.c:1.445.2.14.2.69.2.45 Wed Apr 1 14:00:38 2009
+++ php-src/ext/standard/string.c Wed Apr 1 17:05:35 2009
@@ -18,7 +18,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: string.c,v 1.445.2.14.2.69.2.45 2009/04/01 14:00:38 iliaa Exp $ */
+/* $Id: string.c,v 1.445.2.14.2.69.2.46 2009/04/01 17:05:35 mattwil Exp $ */
/* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */
@@ -928,7 +928,7 @@
/* {{{ php_explode
*/
-PHPAPI void php_explode(zval *delim, zval *str, zval *return_value, int limit)
+PHPAPI void php_explode(zval *delim, zval *str, zval *return_value, long limit)
{
char *p1, *p2, *endp;
@@ -944,7 +944,7 @@
add_next_index_stringl(return_value, p1, p2 - p1, 1);
p1 = p2 + Z_STRLEN_P(delim);
} while ((p2 = php_memnstr(p1, Z_STRVAL_P(delim), Z_STRLEN_P(delim),
endp)) != NULL &&
- (limit == -1 || --limit > 1));
+ --limit > 1);
if (p1 <= endp)
add_next_index_stringl(return_value, p1, endp-p1, 1);
@@ -954,12 +954,10 @@
/* {{{ php_explode_negative_limit
*/
-PHPAPI void php_explode_negative_limit(zval *delim, zval *str, zval *return_value, int limit)
+PHPAPI void php_explode_negative_limit(zval *delim, zval *str, zval *return_value, long limit)
{
-#define EXPLODE_ALLOC_STEP 50
+#define EXPLODE_ALLOC_STEP 64
char *p1, *p2, *endp;
- int allocated = EXPLODE_ALLOC_STEP, found = 0, i = 0, to_return = 0;
- char **positions = safe_emalloc(allocated, sizeof(char *), 0);
endp = Z_STRVAL_P(str) + Z_STRLEN_P(str);
@@ -972,6 +970,10 @@
by doing nothing we return empty array
*/
} else {
+ int allocated = EXPLODE_ALLOC_STEP, found = 0;
+ long i, to_return;
+ char **positions = emalloc(allocated * sizeof(char *));
+
positions[found++] = p1;
do {
if (found >= allocated) {
@@ -989,8 +991,8 @@
1
);
}
+ efree(positions);
}
- efree(positions);
#undef EXPLODE_ALLOC_STEP
}
/* }}} */
@@ -1000,8 +1002,7 @@
PHP_FUNCTION(explode)
{
zval **str, **delim;
- long limit = -1;
- int argc = ZEND_NUM_ARGS();
+ long limit = LONG_MAX; /* No limit */
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ZZ|l", &delim, &str,
&limit) == FAILURE) {
return;
@@ -1018,19 +1019,18 @@
array_init(return_value);
if (! Z_STRLEN_PP(str)) {
- if (limit >= 0 || argc == 2) {
+ if (limit >= 0) {
add_next_index_stringl(return_value, "", sizeof("") -
1, 1);
}
return;
}
-
- if (limit == 0 || limit == 1) {
- add_index_stringl(return_value, 0, Z_STRVAL_PP(str),
Z_STRLEN_PP(str), 1);
- } else if (limit < -1 && argc == 3) {
+ if (limit > 1) {
+ php_explode(*delim, *str, return_value, limit);
+ } else if (limit < 0) {
php_explode_negative_limit(*delim, *str, return_value, limit);
} else {
- php_explode(*delim, *str, return_value, limit);
+ add_index_stringl(return_value, 0, Z_STRVAL_PP(str),
Z_STRLEN_PP(str), 1);
}
}
/* }}} */