Re: [PHP-CVS] cvs: php-src(PHP_5_3) / NEWS /ext/standard php_string.h string.c /ext/standard/tests/strings bug47546.phpt

2009-06-12 Thread Michael Wallner
Matt Wilmas wrote:
 Hi Dmitry, Antony,
 
 Fixed, thanks.
 

 Matt Wilmas wrote:
 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 
 

In what state is this now?

php_explode() does not work as expected with limit=-1 and
php_explode_negative_limit() is not exported in php_string.h

Mike

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-CVS] Re: [PHP-DEV] Re: [PHP-CVS] cvs: php-src(PHP_5_3) / NEWS /ext/standard php_string.h string.c /ext/standard/tests/strings bug47546.phpt

2009-06-12 Thread Richard Quadling
2009/6/12 Michael Wallner m...@php.net:
 Matt Wilmas wrote:
 Hi Dmitry, Antony,

 Fixed, thanks.


 Matt Wilmas wrote:
 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


 In what state is this now?

 php_explode() does not work as expected with limit=-1 and
 php_explode_negative_limit() is not exported in php_string.h

 Mike

 --
 PHP Internals - PHP Runtime Development Mailing List
 To unsubscribe, visit: http://www.php.net/unsub.php



From a user's perspective, I would say that explode() now works as I
would expect.

When a valid delimiter is supplied with no limit, then the result is
the same as if the limit was the count of items after the split.

For negative limits (with a valid delimiter), the result is chopped by
the abs($limit).

?php
$string = 'one.two.three.four';
$results = array();

foreach(array('Valid' = '.', 'Invalid' = '_') as $valid = $delimiter) {
$results[$valid]['No Limit'] = explode($delimiter, $string);

foreach(range(-4, 4) as $limit) {
$results[$valid][$limit] = explode($delimiter, $string, $limit);
}
}

print_r($results);
?

outputs what I think is correct.

Array
(
[Valid] = Array
(
[No Limit] = Array
(
[0] = one
[1] = two
[2] = three
[3] = four
)
[-4] = Array
(
)
[-3] = Array
(
[0] = one
)
[-2] = Array
(
[0] = one
[1] = two
)
[-1] = Array
(
[0] = one
[1] = two
[2] = three
)
[0] = Array
(
[0] = one.two.three.four
)
[1] = Array
(
[0] = one.two.three.four
)
[2] = Array
(
[0] = one
[1] = two.three.four
)
[3] = Array
(
[0] = one
[1] = two
[2] = three.four
)
[4] = Array
(
[0] = one
[1] = two
[2] = three
[3] = four
)
)
[Invalid] = Array
(
[No Limit] = Array
(
[0] = one.two.three.four
)
[-4] = Array
(
)
[-3] = Array
(
)
[-2] = Array
(
)
[-1] = Array
(
)
[0] = Array
(
[0] = one.two.three.four
)
[1] = Array
(
[0] = one.two.three.four
)
[2] = Array
(
[0] = one.two.three.four
)
[3] = Array
(
[0] = one.two.three.four
)
[4] = Array
(
[0] = one.two.three.four
)
)
)

-- 
-
Richard Quadling
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498r=213474731
Standing on the shoulders of some very clever giants!

--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-CVS] cvs: php-src(PHP_5_3) / NEWS /ext/standard php_string.h string.c /ext/standard/tests/strings bug47546.phpt

2009-04-02 Thread Dmitry Stogov

Hi Matt,

I suppose the following tests start fail after this patch

explode() function [ext/standard/tests/strings/explode.phpt]
Test explode() function [ext/standard/tests/strings/explode1.phpt]
Test explode() function : usage variations - positive and negative 
limits [ext/standard/tests/strings/explode_variation5.phpt]
Test explode() function : usage variations - misc tests 
[ext/standard/tests/strings/explode_variation6.phpt]


Could you please check them.

Thanks. Dmitry.

Matt Wilmas wrote:

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.548r2=1.2027.2.547.2.965.2.549diff_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/NEWSWed 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.4r2=1.87.2.2.2.3.2.5diff_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.45r2=1.445.2.14.2.69.2.46diff_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 

Re: [PHP-CVS] cvs: php-src(PHP_5_3) / NEWS /ext/standard php_string.h string.c /ext/standard/tests/strings bug47546.phpt

2009-04-02 Thread Matt Wilmas

Hi Dmitry, Antony,

- Original Message -
From: Dmitry Stogov
Sent: Thursday, April 02, 2009


Hi Matt,

I suppose the following tests start fail after this patch

explode() function [ext/standard/tests/strings/explode.phpt]
Test explode() function [ext/standard/tests/strings/explode1.phpt]
Test explode() function : usage variations - positive and negative limits 
[ext/standard/tests/strings/explode_variation5.phpt]
Test explode() function : usage variations - misc tests 
[ext/standard/tests/strings/explode_variation6.phpt]


Could you please check them.


Fixed, thanks.


Thanks. Dmitry.


- Matt


Matt Wilmas wrote:

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 



--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-CVS] cvs: php-src(PHP_5_3) / NEWS /ext/standard php_string.h string.c /ext/standard/tests/strings bug47546.phpt

2009-04-01 Thread Matt Wilmas
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-srcNEWS 
/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.548r2=1.2027.2.547.2.965.2.549diff_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/NEWSWed 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.4r2=1.87.2.2.2.3.2.5diff_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.45r2=1.445.2.14.2.69.2.46diff_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 @@