derick Mon, 30 Aug 2010 15:32:09 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=302887
Log: - Fixed bug #52668 (Iterating over a dateperiod twice is broken). Bug: http://bugs.php.net/52668 (Assigned) Iterating over a dateperiod twice is broken Changed paths: U php/php-src/branches/PHP_5_3/NEWS U php/php-src/branches/PHP_5_3/ext/date/lib/timelib.c U php/php-src/branches/PHP_5_3/ext/date/lib/timelib.h U php/php-src/branches/PHP_5_3/ext/date/php_date.c U php/php-src/branches/PHP_5_3/ext/date/php_date.h A php/php-src/branches/PHP_5_3/ext/date/tests/bug52668.phpt U php/php-src/trunk/ext/date/lib/timelib.c U php/php-src/trunk/ext/date/lib/timelib.h U php/php-src/trunk/ext/date/php_date.c U php/php-src/trunk/ext/date/php_date.h A php/php-src/trunk/ext/date/tests/bug52668.phpt
Modified: php/php-src/branches/PHP_5_3/NEWS =================================================================== --- php/php-src/branches/PHP_5_3/NEWS 2010-08-30 15:21:31 UTC (rev 302886) +++ php/php-src/branches/PHP_5_3/NEWS 2010-08-30 15:32:09 UTC (rev 302887) @@ -22,6 +22,7 @@ (Adam) - Fixed bug #52674 (FPM Status page returns inconsistent Content-Type headers). (fat) +- Fixed bug #52668 (Iterating over a dateperiod twice is broken). (Derick) - Fixed bug #52654 (mysqli doesn't install headers with structures it uses). (Andrey) - Fixed bug #52636 (php_mysql_fetch_hash writes long value into int). Modified: php/php-src/branches/PHP_5_3/ext/date/lib/timelib.c =================================================================== --- php/php-src/branches/PHP_5_3/ext/date/lib/timelib.c 2010-08-30 15:21:31 UTC (rev 302886) +++ php/php-src/branches/PHP_5_3/ext/date/lib/timelib.c 2010-08-30 15:32:09 UTC (rev 302887) @@ -46,6 +46,19 @@ return t; } +timelib_time* timelib_time_clone(timelib_time *orig) +{ + timelib_time *tmp = timelib_time_ctor(); + memcpy(tmp, orig, sizeof(timelib_time)); + if (orig->tz_abbr) { + tmp->tz_abbr = strdup(orig->tz_abbr); + } + if (orig->tz_info) { + tmp->tz_info = orig->tz_info; + } + return tmp; +} + timelib_rel_time* timelib_rel_time_clone(timelib_rel_time *rel) { timelib_rel_time *tmp = timelib_rel_time_ctor(); Modified: php/php-src/branches/PHP_5_3/ext/date/lib/timelib.h =================================================================== --- php/php-src/branches/PHP_5_3/ext/date/lib/timelib.h 2010-08-30 15:21:31 UTC (rev 302886) +++ php/php-src/branches/PHP_5_3/ext/date/lib/timelib.h 2010-08-30 15:32:09 UTC (rev 302887) @@ -109,6 +109,7 @@ timelib_time* timelib_time_ctor(void); void timelib_time_set_option(timelib_time* tm, int option, void* option_value); void timelib_time_dtor(timelib_time* t); +timelib_time* timelib_time_clone(timelib_time* orig); timelib_time_offset* timelib_time_offset_ctor(void); void timelib_time_offset_dtor(timelib_time_offset* t); Modified: php/php-src/branches/PHP_5_3/ext/date/php_date.c =================================================================== --- php/php-src/branches/PHP_5_3/ext/date/php_date.c 2010-08-30 15:21:31 UTC (rev 302886) +++ php/php-src/branches/PHP_5_3/ext/date/php_date.c 2010-08-30 15:32:09 UTC (rev 302887) @@ -1822,7 +1822,7 @@ { date_period_it *iterator = (date_period_it *)iter; php_period_obj *object = iterator->object; - timelib_time *it_time = object->start; + timelib_time *it_time = object->current; /* apply modification if it's not the first iteration */ if (!object->include_start_date || iterator->current_index > 0) { @@ -1834,7 +1834,7 @@ } if (object->end) { - return object->start->sse < object->end->sse ? SUCCESS : FAILURE; + return object->current->sse < object->end->sse ? SUCCESS : FAILURE; } else { return (iterator->current_index < object->recurrences) ? SUCCESS : FAILURE; } @@ -1847,7 +1847,7 @@ { date_period_it *iterator = (date_period_it *)iter; php_period_obj *object = iterator->object; - timelib_time *it_time = object->start; + timelib_time *it_time = object->current; php_date_obj *newdateobj; /* Create new object */ @@ -1895,6 +1895,10 @@ date_period_it *iterator = (date_period_it *)iter; iterator->current_index = 0; + if (iterator->object->current) { + timelib_time_dtor(iterator->object->current); + } + iterator->object->current = timelib_time_clone(iterator->object->start); date_period_it_invalidate_current(iter TSRMLS_CC); } /* }}} */ @@ -2335,6 +2339,10 @@ timelib_time_dtor(intern->start); } + if (intern->current) { + timelib_time_dtor(intern->current); + } + if (intern->end) { timelib_time_dtor(intern->end); } @@ -3713,6 +3721,7 @@ } dpobj = zend_object_store_get_object(getThis() TSRMLS_CC); + dpobj->current = NULL; if (isostr_len) { date_period_initialize(&(dpobj->start), &(dpobj->end), &(dpobj->interval), (int*) &recurrences, isostr, isostr_len TSRMLS_CC); @@ -3754,14 +3763,7 @@ /* end date */ if (end) { dateobj = (php_date_obj *) zend_object_store_get_object(end TSRMLS_CC); - clone = timelib_time_ctor(); - memcpy(clone, dateobj->time, sizeof(timelib_time)); - if (dateobj->time->tz_abbr) { - clone->tz_abbr = strdup(dateobj->time->tz_abbr); - } - if (dateobj->time->tz_info) { - clone->tz_info = dateobj->time->tz_info; - } + clone = timelib_time_clone(dateobj->time); dpobj->end = clone; } } Modified: php/php-src/branches/PHP_5_3/ext/date/php_date.h =================================================================== --- php/php-src/branches/PHP_5_3/ext/date/php_date.h 2010-08-30 15:21:31 UTC (rev 302886) +++ php/php-src/branches/PHP_5_3/ext/date/php_date.h 2010-08-30 15:32:09 UTC (rev 302887) @@ -139,6 +139,7 @@ struct _php_period_obj { zend_object std; timelib_time *start; + timelib_time *current; timelib_time *end; timelib_rel_time *interval; int recurrences; Added: php/php-src/branches/PHP_5_3/ext/date/tests/bug52668.phpt =================================================================== --- php/php-src/branches/PHP_5_3/ext/date/tests/bug52668.phpt (rev 0) +++ php/php-src/branches/PHP_5_3/ext/date/tests/bug52668.phpt 2010-08-30 15:32:09 UTC (rev 302887) @@ -0,0 +1,25 @@ +--TEST-- +Bug #52668 (Iterating over a dateperiod twice is broken) +--INI-- +date.timezone=UTC +--FILE-- +<?php +$start = new DateTime('20101212'); +$interval = DateInterval::createFromDateString('next day'); +$dp = new DatePeriod($start, $interval, 1); +foreach($dp as $dt) { + echo $dt->format('r') . "\n"; // Sun, 12 Dec 2010 00:00:00 +0100 +} +echo $start->format('r'), "\n"; +foreach($dp as $dt) { + echo $dt->format('r') . "\n"; // Sun, 12 Dec 2010 00:00:00 +0100 +} +echo $start->format('r'), "\n\n"; +?> +--EXPECT-- +Sun, 12 Dec 2010 00:00:00 +0000 +Mon, 13 Dec 2010 00:00:00 +0000 +Sun, 12 Dec 2010 00:00:00 +0000 +Sun, 12 Dec 2010 00:00:00 +0000 +Mon, 13 Dec 2010 00:00:00 +0000 +Sun, 12 Dec 2010 00:00:00 +0000 Modified: php/php-src/trunk/ext/date/lib/timelib.c =================================================================== --- php/php-src/trunk/ext/date/lib/timelib.c 2010-08-30 15:21:31 UTC (rev 302886) +++ php/php-src/trunk/ext/date/lib/timelib.c 2010-08-30 15:32:09 UTC (rev 302887) @@ -46,6 +46,19 @@ return t; } +timelib_time* timelib_time_clone(timelib_time *orig) +{ + timelib_time *tmp = timelib_time_ctor(); + memcpy(tmp, orig, sizeof(timelib_time)); + if (orig->tz_abbr) { + tmp->tz_abbr = strdup(orig->tz_abbr); + } + if (orig->tz_info) { + tmp->tz_info = orig->tz_info; + } + return tmp; +} + timelib_rel_time* timelib_rel_time_clone(timelib_rel_time *rel) { timelib_rel_time *tmp = timelib_rel_time_ctor(); Modified: php/php-src/trunk/ext/date/lib/timelib.h =================================================================== --- php/php-src/trunk/ext/date/lib/timelib.h 2010-08-30 15:21:31 UTC (rev 302886) +++ php/php-src/trunk/ext/date/lib/timelib.h 2010-08-30 15:32:09 UTC (rev 302887) @@ -109,6 +109,7 @@ timelib_time* timelib_time_ctor(void); void timelib_time_set_option(timelib_time* tm, int option, void* option_value); void timelib_time_dtor(timelib_time* t); +timelib_time* timelib_time_clone(timelib_time* orig); timelib_time_offset* timelib_time_offset_ctor(void); void timelib_time_offset_dtor(timelib_time_offset* t); Modified: php/php-src/trunk/ext/date/php_date.c =================================================================== --- php/php-src/trunk/ext/date/php_date.c 2010-08-30 15:21:31 UTC (rev 302886) +++ php/php-src/trunk/ext/date/php_date.c 2010-08-30 15:32:09 UTC (rev 302887) @@ -1821,7 +1821,7 @@ { date_period_it *iterator = (date_period_it *)iter; php_period_obj *object = iterator->object; - timelib_time *it_time = object->start; + timelib_time *it_time = object->current; /* apply modification if it's not the first iteration */ if (!object->include_start_date || iterator->current_index > 0) { @@ -1833,7 +1833,7 @@ } if (object->end) { - return object->start->sse < object->end->sse ? SUCCESS : FAILURE; + return object->current->sse < object->end->sse ? SUCCESS : FAILURE; } else { return (iterator->current_index < object->recurrences) ? SUCCESS : FAILURE; } @@ -1846,7 +1846,7 @@ { date_period_it *iterator = (date_period_it *)iter; php_period_obj *object = iterator->object; - timelib_time *it_time = object->start; + timelib_time *it_time = object->current; php_date_obj *newdateobj; /* Create new object */ @@ -1894,6 +1894,10 @@ date_period_it *iterator = (date_period_it *)iter; iterator->current_index = 0; + if (iterator->object->current) { + timelib_time_dtor(iterator->object->current); + } + iterator->object->current = timelib_time_clone(iterator->object->start); date_period_it_invalidate_current(iter TSRMLS_CC); } /* }}} */ @@ -2330,6 +2334,10 @@ timelib_time_dtor(intern->start); } + if (intern->current) { + timelib_time_dtor(intern->current); + } + if (intern->end) { timelib_time_dtor(intern->end); } @@ -3708,6 +3716,7 @@ } dpobj = zend_object_store_get_object(getThis() TSRMLS_CC); + dpobj->current = NULL; if (isostr_len) { date_period_initialize(&(dpobj->start), &(dpobj->end), &(dpobj->interval), (int*) &recurrences, isostr, isostr_len TSRMLS_CC); @@ -3749,14 +3758,7 @@ /* end date */ if (end) { dateobj = (php_date_obj *) zend_object_store_get_object(end TSRMLS_CC); - clone = timelib_time_ctor(); - memcpy(clone, dateobj->time, sizeof(timelib_time)); - if (dateobj->time->tz_abbr) { - clone->tz_abbr = strdup(dateobj->time->tz_abbr); - } - if (dateobj->time->tz_info) { - clone->tz_info = dateobj->time->tz_info; - } + clone = timelib_time_clone(dateobj->time); dpobj->end = clone; } } Modified: php/php-src/trunk/ext/date/php_date.h =================================================================== --- php/php-src/trunk/ext/date/php_date.h 2010-08-30 15:21:31 UTC (rev 302886) +++ php/php-src/trunk/ext/date/php_date.h 2010-08-30 15:32:09 UTC (rev 302887) @@ -139,6 +139,7 @@ struct _php_period_obj { zend_object std; timelib_time *start; + timelib_time *current; timelib_time *end; timelib_rel_time *interval; int recurrences; Added: php/php-src/trunk/ext/date/tests/bug52668.phpt =================================================================== --- php/php-src/trunk/ext/date/tests/bug52668.phpt (rev 0) +++ php/php-src/trunk/ext/date/tests/bug52668.phpt 2010-08-30 15:32:09 UTC (rev 302887) @@ -0,0 +1,25 @@ +--TEST-- +Bug #52668 (Iterating over a dateperiod twice is broken) +--INI-- +date.timezone=UTC +--FILE-- +<?php +$start = new DateTime('20101212'); +$interval = DateInterval::createFromDateString('next day'); +$dp = new DatePeriod($start, $interval, 1); +foreach($dp as $dt) { + echo $dt->format('r') . "\n"; // Sun, 12 Dec 2010 00:00:00 +0100 +} +echo $start->format('r'), "\n"; +foreach($dp as $dt) { + echo $dt->format('r') . "\n"; // Sun, 12 Dec 2010 00:00:00 +0100 +} +echo $start->format('r'), "\n\n"; +?> +--EXPECT-- +Sun, 12 Dec 2010 00:00:00 +0000 +Mon, 13 Dec 2010 00:00:00 +0000 +Sun, 12 Dec 2010 00:00:00 +0000 +Sun, 12 Dec 2010 00:00:00 +0000 +Mon, 13 Dec 2010 00:00:00 +0000 +Sun, 12 Dec 2010 00:00:00 +0000
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php