1
0
mirror of https://github.com/php/php-src.git synced 2026-03-29 11:42:17 +02:00

Merge branch 'PHP-5.5' into PHP-5.6

This commit is contained in:
Derick Rethans
2014-02-09 15:57:43 -05:00
11 changed files with 77 additions and 128 deletions

View File

@@ -1,4 +1,4 @@
/* Generated by re2c 0.13.5 on Sat Jan 25 16:16:11 2014 */
/* Generated by re2c 0.13.5 on Thu Feb 6 07:35:53 2014 */
#line 1 "ext/date/lib/parse_date.re"
/*
+----------------------------------------------------------------------+
@@ -751,7 +751,7 @@ static long timelib_lookup_zone(char **ptr, int *dst, char **tz_abbr, int *found
return value;
}
static long timelib_get_zone(char **ptr, int *dst, timelib_time *t, int *tz_not_found, const timelib_tzdb *tzdb, timelib_tz_get_wrapper tz_wrapper)
long timelib_parse_zone(char **ptr, int *dst, timelib_time *t, int *tz_not_found, const timelib_tzdb *tzdb, timelib_tz_get_wrapper tz_wrapper)
{
timelib_tzinfo *res;
long retval = 0;
@@ -1006,7 +1006,7 @@ yy4:
DEBUG_OUTPUT("tzcorrection | tz");
TIMELIB_INIT;
TIMELIB_HAVE_TZ();
s->time->z = timelib_get_zone((char **) &ptr, &s->time->dst, s->time, &tz_not_found, s->tzdb, tz_get_wrapper);
s->time->z = timelib_parse_zone((char **) &ptr, &s->time->dst, s->time, &tz_not_found, s->tzdb, tz_get_wrapper);
if (tz_not_found) {
add_error(s, "The timezone could not be found in the database");
}
@@ -4468,7 +4468,7 @@ yy223:
}
if (*ptr != '\0') {
s->time->z = timelib_get_zone((char **) &ptr, &s->time->dst, s->time, &tz_not_found, s->tzdb, tz_get_wrapper);
s->time->z = timelib_parse_zone((char **) &ptr, &s->time->dst, s->time, &tz_not_found, s->tzdb, tz_get_wrapper);
if (tz_not_found) {
add_error(s, "The timezone could not be found in the database");
}
@@ -9798,7 +9798,7 @@ yy491:
}
if (*ptr != '\0') {
s->time->z = timelib_get_zone((char **) &ptr, &s->time->dst, s->time, &tz_not_found, s->tzdb, tz_get_wrapper);
s->time->z = timelib_parse_zone((char **) &ptr, &s->time->dst, s->time, &tz_not_found, s->tzdb, tz_get_wrapper);
if (tz_not_found) {
add_error(s, "The timezone could not be found in the database");
}
@@ -12073,7 +12073,7 @@ yy701:
s->time->h = timelib_get_nr((char **) &ptr, 2);
s->time->i = timelib_get_nr((char **) &ptr, 2);
s->time->s = timelib_get_nr((char **) &ptr, 2);
s->time->z = timelib_get_zone((char **) &ptr, &s->time->dst, s->time, &tz_not_found, s->tzdb, tz_get_wrapper);
s->time->z = timelib_parse_zone((char **) &ptr, &s->time->dst, s->time, &tz_not_found, s->tzdb, tz_get_wrapper);
if (tz_not_found) {
add_error(s, "The timezone could not be found in the database");
}
@@ -13464,7 +13464,7 @@ yy843:
if (*ptr == '.') {
s->time->f = timelib_get_frac_nr((char **) &ptr, 9);
if (*ptr) { /* timezone is optional */
s->time->z = timelib_get_zone((char **) &ptr, &s->time->dst, s->time, &tz_not_found, s->tzdb, tz_get_wrapper);
s->time->z = timelib_parse_zone((char **) &ptr, &s->time->dst, s->time, &tz_not_found, s->tzdb, tz_get_wrapper);
if (tz_not_found) {
add_error(s, "The timezone could not be found in the database");
}
@@ -15813,7 +15813,7 @@ yy1076:
s->time->s = timelib_get_nr((char **) &ptr, 2);
if (*ptr != '\0') {
s->time->z = timelib_get_zone((char **) &ptr, &s->time->dst, s->time, &tz_not_found, s->tzdb, tz_get_wrapper);
s->time->z = timelib_parse_zone((char **) &ptr, &s->time->dst, s->time, &tz_not_found, s->tzdb, tz_get_wrapper);
if (tz_not_found) {
add_error(s, "The timezone could not be found in the database");
}
@@ -25047,7 +25047,7 @@ timelib_time *timelib_parse_from_format(char *format, char *string, int len, tim
case 'O': /* timezone */
{
int tz_not_found;
s->time->z = timelib_get_zone((char **) &ptr, &s->time->dst, s->time, &tz_not_found, s->tzdb, tz_get_wrapper);
s->time->z = timelib_parse_zone((char **) &ptr, &s->time->dst, s->time, &tz_not_found, s->tzdb, tz_get_wrapper);
if (tz_not_found) {
add_pbf_error(s, "The timezone could not be found in the database", string, begin);
}

View File

@@ -749,7 +749,7 @@ static long timelib_lookup_zone(char **ptr, int *dst, char **tz_abbr, int *found
return value;
}
static long timelib_get_zone(char **ptr, int *dst, timelib_time *t, int *tz_not_found, const timelib_tzdb *tzdb, timelib_tz_get_wrapper tz_wrapper)
long timelib_parse_zone(char **ptr, int *dst, timelib_time *t, int *tz_not_found, const timelib_tzdb *tzdb, timelib_tz_get_wrapper tz_wrapper)
{
timelib_tzinfo *res;
long retval = 0;
@@ -1161,7 +1161,7 @@ weekdayof = (reltextnumber|reltexttext) space (dayfull|dayabbr) space 'of
}
if (*ptr != '\0') {
s->time->z = timelib_get_zone((char **) &ptr, &s->time->dst, s->time, &tz_not_found, s->tzdb, tz_get_wrapper);
s->time->z = timelib_parse_zone((char **) &ptr, &s->time->dst, s->time, &tz_not_found, s->tzdb, tz_get_wrapper);
if (tz_not_found) {
add_error(s, "The timezone could not be found in the database");
}
@@ -1202,7 +1202,7 @@ weekdayof = (reltextnumber|reltexttext) space (dayfull|dayabbr) space 'of
s->time->h = timelib_get_nr((char **) &ptr, 2);
s->time->i = timelib_get_nr((char **) &ptr, 2);
s->time->s = 0;
s->time->z = timelib_get_zone((char **) &ptr, &s->time->dst, s->time, s->tzdb, tz_get_wrapper);
s->time->z = timelib_parse_zone((char **) &ptr, &s->time->dst, s->time, s->tzdb, tz_get_wrapper);
break;
case 1:
s->time->y = timelib_get_nr((char **) &ptr, 4);
@@ -1227,7 +1227,7 @@ weekdayof = (reltextnumber|reltexttext) space (dayfull|dayabbr) space 'of
s->time->s = timelib_get_nr((char **) &ptr, 2);
if (*ptr != '\0') {
s->time->z = timelib_get_zone((char **) &ptr, &s->time->dst, s->time, &tz_not_found, s->tzdb, tz_get_wrapper);
s->time->z = timelib_parse_zone((char **) &ptr, &s->time->dst, s->time, &tz_not_found, s->tzdb, tz_get_wrapper);
if (tz_not_found) {
add_error(s, "The timezone could not be found in the database");
}
@@ -1429,7 +1429,7 @@ weekdayof = (reltextnumber|reltexttext) space (dayfull|dayabbr) space 'of
if (*ptr == '.') {
s->time->f = timelib_get_frac_nr((char **) &ptr, 9);
if (*ptr) { /* timezone is optional */
s->time->z = timelib_get_zone((char **) &ptr, &s->time->dst, s->time, &tz_not_found, s->tzdb, tz_get_wrapper);
s->time->z = timelib_parse_zone((char **) &ptr, &s->time->dst, s->time, &tz_not_found, s->tzdb, tz_get_wrapper);
if (tz_not_found) {
add_error(s, "The timezone could not be found in the database");
}
@@ -1532,7 +1532,7 @@ weekdayof = (reltextnumber|reltexttext) space (dayfull|dayabbr) space 'of
s->time->h = timelib_get_nr((char **) &ptr, 2);
s->time->i = timelib_get_nr((char **) &ptr, 2);
s->time->s = timelib_get_nr((char **) &ptr, 2);
s->time->z = timelib_get_zone((char **) &ptr, &s->time->dst, s->time, &tz_not_found, s->tzdb, tz_get_wrapper);
s->time->z = timelib_parse_zone((char **) &ptr, &s->time->dst, s->time, &tz_not_found, s->tzdb, tz_get_wrapper);
if (tz_not_found) {
add_error(s, "The timezone could not be found in the database");
}
@@ -1645,7 +1645,7 @@ weekdayof = (reltextnumber|reltexttext) space (dayfull|dayabbr) space 'of
DEBUG_OUTPUT("tzcorrection | tz");
TIMELIB_INIT;
TIMELIB_HAVE_TZ();
s->time->z = timelib_get_zone((char **) &ptr, &s->time->dst, s->time, &tz_not_found, s->tzdb, tz_get_wrapper);
s->time->z = timelib_parse_zone((char **) &ptr, &s->time->dst, s->time, &tz_not_found, s->tzdb, tz_get_wrapper);
if (tz_not_found) {
add_error(s, "The timezone could not be found in the database");
}
@@ -1698,7 +1698,7 @@ weekdayof = (reltextnumber|reltexttext) space (dayfull|dayabbr) space 'of
}
if (*ptr != '\0') {
s->time->z = timelib_get_zone((char **) &ptr, &s->time->dst, s->time, &tz_not_found, s->tzdb, tz_get_wrapper);
s->time->z = timelib_parse_zone((char **) &ptr, &s->time->dst, s->time, &tz_not_found, s->tzdb, tz_get_wrapper);
if (tz_not_found) {
add_error(s, "The timezone could not be found in the database");
}
@@ -2054,7 +2054,7 @@ timelib_time *timelib_parse_from_format(char *format, char *string, int len, tim
case 'O': /* timezone */
{
int tz_not_found;
s->time->z = timelib_get_zone((char **) &ptr, &s->time->dst, s->time, &tz_not_found, s->tzdb, tz_get_wrapper);
s->time->z = timelib_parse_zone((char **) &ptr, &s->time->dst, s->time, &tz_not_found, s->tzdb, tz_get_wrapper);
if (tz_not_found) {
add_pbf_error(s, "The timezone could not be found in the database", string, begin);
}

View File

@@ -105,6 +105,7 @@ timelib_sll timelib_get_current_offset(timelib_time *t);
void timelib_dump_tzinfo(timelib_tzinfo *tz);
const timelib_tzdb *timelib_builtin_db(void);
const timelib_tzdb_index_entry *timelib_timezone_builtin_identifiers_list(int *count);
long timelib_parse_zone(char **ptr, int *dst, timelib_time *t, int *tz_not_found, const timelib_tzdb *tzdb, timelib_tz_get_wrapper tz_wrapper);
/* From timelib.c */
timelib_tzinfo* timelib_tzinfo_ctor(char *name);

View File

@@ -2297,7 +2297,7 @@ static zend_object_value date_object_clone_timezone(zval *this_ptr TSRMLS_DC)
case TIMELIB_ZONETYPE_ABBR:
new_obj->tzi.z.utc_offset = old_obj->tzi.z.utc_offset;
new_obj->tzi.z.dst = old_obj->tzi.z.dst;
new_obj->tzi.z.abbr = old_obj->tzi.z.abbr;
new_obj->tzi.z.abbr = strdup(old_obj->tzi.z.abbr);
break;
}
@@ -3238,6 +3238,26 @@ PHP_METHOD(DateTimeImmutable, sub)
}
/* }}} */
static void set_timezone_from_timelib_time(php_timezone_obj *tzobj, timelib_time *t)
{
tzobj->initialized = 1;
tzobj->type = t->zone_type;
switch (t->zone_type) {
case TIMELIB_ZONETYPE_ID:
tzobj->tzi.tz = t->tz_info;
break;
case TIMELIB_ZONETYPE_OFFSET:
tzobj->tzi.utc_offset = t->z;
break;
case TIMELIB_ZONETYPE_ABBR:
tzobj->tzi.z.utc_offset = t->z;
tzobj->tzi.z.dst = t->dst;
tzobj->tzi.z.abbr = strdup(t->tz_abbr);
break;
}
}
/* {{{ proto DateTimeZone date_timezone_get(DateTimeInterface object)
Return new DateTimeZone object relative to give DateTime
*/
@@ -3255,21 +3275,7 @@ PHP_FUNCTION(date_timezone_get)
if (dateobj->time->is_localtime/* && dateobj->time->tz_info*/) {
php_date_instantiate(date_ce_timezone, return_value TSRMLS_CC);
tzobj = (php_timezone_obj *) zend_object_store_get_object(return_value TSRMLS_CC);
tzobj->initialized = 1;
tzobj->type = dateobj->time->zone_type;
switch (dateobj->time->zone_type) {
case TIMELIB_ZONETYPE_ID:
tzobj->tzi.tz = dateobj->time->tz_info;
break;
case TIMELIB_ZONETYPE_OFFSET:
tzobj->tzi.utc_offset = dateobj->time->z;
break;
case TIMELIB_ZONETYPE_ABBR:
tzobj->tzi.z.utc_offset = dateobj->time->z;
tzobj->tzi.z.dst = dateobj->time->dst;
tzobj->tzi.z.abbr = strdup(dateobj->time->tz_abbr);
break;
}
set_timezone_from_timelib_time(tzobj, dateobj->time);
} else {
RETURN_FALSE;
}
@@ -3620,23 +3626,21 @@ PHP_FUNCTION(date_diff)
}
/* }}} */
static int timezone_initialize(timelib_tzinfo **tzi, /*const*/ char *tz TSRMLS_DC)
static int timezone_initialize(php_timezone_obj *tzobj, /*const*/ char *tz TSRMLS_DC)
{
char *tzid;
*tzi = NULL;
if ((tzid = timelib_timezone_id_from_abbr(tz, -1, 0))) {
*tzi = php_date_parse_tzfile(tzid, DATE_TIMEZONEDB TSRMLS_CC);
} else {
*tzi = php_date_parse_tzfile(tz, DATE_TIMEZONEDB TSRMLS_CC);
}
if (*tzi) {
return SUCCESS;
} else {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown or bad timezone (%s)", tz);
timelib_time *dummy_t = ecalloc(1, sizeof(timelib_time));
int dst, not_found;
char *orig_tz = tz;
dummy_t->z = timelib_parse_zone(&tz, &dst, dummy_t, &not_found, DATE_TIMEZONEDB, php_date_parse_tzfile_wrapper);
if (not_found) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown or bad timezone (%s)", orig_tz);
efree(dummy_t);
return FAILURE;
} else {
set_timezone_from_timelib_time(tzobj, dummy_t TSRMLS_CC);
efree(dummy_t);
return SUCCESS;
}
}
@@ -3647,19 +3651,15 @@ PHP_FUNCTION(timezone_open)
{
char *tz;
int tz_len;
timelib_tzinfo *tzi = NULL;
php_timezone_obj *tzobj;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &tz, &tz_len) == FAILURE) {
RETURN_FALSE;
}
if (SUCCESS != timezone_initialize(&tzi, tz TSRMLS_CC)) {
tzobj = zend_object_store_get_object(php_date_instantiate(date_ce_timezone, return_value TSRMLS_CC) TSRMLS_CC);
if (SUCCESS != timezone_initialize(tzobj, tz TSRMLS_CC)) {
RETURN_FALSE;
}
tzobj = zend_object_store_get_object(php_date_instantiate(date_ce_timezone, return_value TSRMLS_CC) TSRMLS_CC);
tzobj->type = TIMELIB_ZONETYPE_ID;
tzobj->tzi.tz = tzi;
tzobj->initialized = 1;
}
/* }}} */
@@ -3670,18 +3670,13 @@ PHP_METHOD(DateTimeZone, __construct)
{
char *tz;
int tz_len;
timelib_tzinfo *tzi = NULL;
php_timezone_obj *tzobj;
zend_error_handling error_handling;
zend_replace_error_handling(EH_THROW, NULL, &error_handling TSRMLS_CC);
if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &tz, &tz_len)) {
if (SUCCESS == timezone_initialize(&tzi, tz TSRMLS_CC)) {
tzobj = zend_object_store_get_object(getThis() TSRMLS_CC);
tzobj->type = TIMELIB_ZONETYPE_ID;
tzobj->tzi.tz = tzi;
tzobj->initialized = 1;
} else {
tzobj = zend_object_store_get_object(getThis() TSRMLS_CC);
if (FAILURE == timezone_initialize(tzobj, tz TSRMLS_CC)) {
ZVAL_NULL(getThis());
}
}
@@ -3693,39 +3688,12 @@ static int php_date_timezone_initialize_from_hash(zval **return_value, php_timez
{
zval **z_timezone = NULL;
zval **z_timezone_type = NULL;
timelib_tzinfo *tzi;
if (zend_hash_find(myht, "timezone_type", 14, (void**) &z_timezone_type) == SUCCESS) {
if (zend_hash_find(myht, "timezone", 9, (void**) &z_timezone) == SUCCESS) {
convert_to_long(*z_timezone_type);
switch (Z_LVAL_PP(z_timezone_type)) {
case TIMELIB_ZONETYPE_OFFSET: {
char *offset, *offset_start;
offset = emalloc(sizeof(char) * (Z_STRLEN_PP(z_timezone) + 1));
memmove(offset, Z_STRVAL_PP(z_timezone), Z_STRLEN_PP(z_timezone)+1);
offset_start = offset;
++offset;
if(*offset_start == '+'){
(*tzobj)->tzi.utc_offset = -1 * timelib_parse_tz_cor(&offset);
} else {
(*tzobj)->tzi.utc_offset = timelib_parse_tz_cor(&offset);
}
efree(offset_start);
(*tzobj)->type = TIMELIB_ZONETYPE_OFFSET;
(*tzobj)->initialized = 1;
return SUCCESS;
break;
}
case TIMELIB_ZONETYPE_ABBR:
case TIMELIB_ZONETYPE_ID:
if (SUCCESS == timezone_initialize(&tzi, Z_STRVAL_PP(z_timezone) TSRMLS_CC)) {
(*tzobj)->type = TIMELIB_ZONETYPE_ID;
(*tzobj)->tzi.tz = tzi;
(*tzobj)->initialized = 1;
return SUCCESS;
}
if (SUCCESS == timezone_initialize(*tzobj, Z_STRVAL_PP(z_timezone) TSRMLS_CC)) {
return SUCCESS;
}
}
}

View File

@@ -31,15 +31,15 @@ if ($clone != $orig) {
*** Testing clone on DateTime objects ***
object(DateTimeZone)#%d (2) {
["timezone_type"]=>
int(3)
int(2)
["timezone"]=>
string(3) "UTC"
string(3) "GMT"
}
object(DateTimeZone)#%d (2) {
["timezone_type"]=>
int(3)
int(2)
["timezone"]=>
string(3) "UTC"
string(3) "GMT"
}
TEST PASSED : Objects equal but not indetical
===DONE===

View File

@@ -23,9 +23,9 @@ var_dump( new DateTimeZone("America/Los_Angeles") );
*** Testing new DateTimeZone() : basic functionality ***
object(DateTimeZone)#%d (2) {
["timezone_type"]=>
int(3)
int(2)
["timezone"]=>
string(3) "UTC"
string(3) "GMT"
}
object(DateTimeZone)#%d (2) {
["timezone_type"]=>

View File

@@ -48,11 +48,9 @@ $inputs = array(
'int 0' => 0,
'int 1' => 1,
'int 12345' => 12345,
'int -12345' => -12345,
// float data
'float 10.5' => 10.5,
'float -10.5' => -10.5,
'float .5' => .5,
// array data
@@ -123,15 +121,9 @@ FAILED: DateTimeZone::__construct(): Unknown or bad timezone (1)
-- int 12345 --
FAILED: DateTimeZone::__construct(): Unknown or bad timezone (12345)
-- int -12345 --
FAILED: DateTimeZone::__construct(): Unknown or bad timezone (-12345)
-- float 10.5 --
FAILED: DateTimeZone::__construct(): Unknown or bad timezone (10.5)
-- float -10.5 --
FAILED: DateTimeZone::__construct(): Unknown or bad timezone (-10.5)
-- float .5 --
FAILED: DateTimeZone::__construct(): Unknown or bad timezone (0.5)

View File

@@ -20,16 +20,16 @@ var_dump( $tz2->getName() );
--EXPECTF--
object(DateTimeZone)#%d (2) {
["timezone_type"]=>
int(3)
int(2)
["timezone"]=>
string(16) "America/New_York"
string(3) "EST"
}
string(88) "O:12:"DateTimeZone":2:{s:13:"timezone_type";i:3;s:8:"timezone";s:16:"America/New_York";}"
string(74) "O:12:"DateTimeZone":2:{s:13:"timezone_type";i:2;s:8:"timezone";s:3:"EST";}"
object(DateTimeZone)#%d (2) {
["timezone_type"]=>
int(3)
int(2)
["timezone"]=>
string(16) "America/New_York"
string(3) "EST"
}
string(16) "America/New_York"
string(3) "EST"
===DONE===

View File

@@ -18,14 +18,14 @@ var_dump( $tz2->getName() );
?>
===DONE===
--EXPECTF--
object(DateTimeZone)#%d (2) {
object(DateTimeZone)#1 (2) {
["timezone_type"]=>
int(3)
["timezone"]=>
string(16) "America/New_York"
}
string(88) "O:12:"DateTimeZone":2:{s:13:"timezone_type";i:3;s:8:"timezone";s:16:"America/New_York";}"
object(DateTimeZone)#%d (2) {
object(DateTimeZone)#2 (2) {
["timezone_type"]=>
int(3)
["timezone"]=>

View File

@@ -20,9 +20,9 @@ var_dump( timezone_open("America/Los_Angeles") );
*** Testing timezone_open() : basic functionality ***
object(DateTimeZone)#%d (2) {
["timezone_type"]=>
int(3)
int(2)
["timezone"]=>
string(3) "UTC"
string(3) "GMT"
}
object(DateTimeZone)#%d (2) {
["timezone_type"]=>
@@ -36,4 +36,4 @@ object(DateTimeZone)#%d (2) {
["timezone"]=>
string(19) "America/Los_Angeles"
}
===DONE===
===DONE===

View File

@@ -48,11 +48,9 @@ $inputs = array(
'int 0' => 0,
'int 1' => 1,
'int 12345' => 12345,
'int -12345' => -12345,
// float data
'float 10.5' => 10.5,
'float -10.5' => -10.5,
'float .5' => .5,
// array data
@@ -124,21 +122,11 @@ bool(false)
Warning: timezone_open(): Unknown or bad timezone (12345) in %s on line %d
bool(false)
-- int -12345 --
Warning: timezone_open(): Unknown or bad timezone (-12345) in %s on line %d
bool(false)
-- float 10.5 --
Warning: timezone_open(): Unknown or bad timezone (10.5) in %s on line %d
bool(false)
-- float -10.5 --
Warning: timezone_open(): Unknown or bad timezone (-10.5) in %s on line %d
bool(false)
-- float .5 --
Warning: timezone_open(): Unknown or bad timezone (0.5) in %s on line %d