--- embedaddon/php/ext/date/php_date.c 2012/02/21 23:47:53 1.1 +++ embedaddon/php/ext/date/php_date.c 2012/05/29 12:34:36 1.1.1.2 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_date.c,v 1.1 2012/02/21 23:47:53 misho Exp $ */ +/* $Id: php_date.c,v 1.1.1.2 2012/05/29 12:34:36 misho Exp $ */ #include "php.h" #include "php_streams.h" @@ -566,8 +566,8 @@ static int date_object_compare_date(zval *d1, zval *d2 static HashTable *date_object_get_properties(zval *object TSRMLS_DC); static HashTable *date_object_get_properties_interval(zval *object TSRMLS_DC); -zval *date_interval_read_property(zval *object, zval *member, int type TSRMLS_DC); -void date_interval_write_property(zval *object, zval *member, zval *value TSRMLS_DC); +zval *date_interval_read_property(zval *object, zval *member, int type, const zend_literal *key TSRMLS_DC); +void date_interval_write_property(zval *object, zval *member, zval *value, const zend_literal *key TSRMLS_DC); /* {{{ Module struct */ zend_module_entry date_module_entry = { @@ -845,17 +845,10 @@ timelib_tzinfo *php_date_parse_tzfile_wrapper(char *fo /* {{{ Helper functions */ static char* guess_timezone(const timelib_tzdb *tzdb TSRMLS_DC) { - char *env; - /* Checking configure timezone */ if (DATEG(timezone) && (strlen(DATEG(timezone)) > 0)) { return DATEG(timezone); } - /* Check environment variable */ - env = getenv("TZ"); - if (env && *env && timelib_timezone_id_is_valid(env, tzdb)) { - return env; - } /* Check config setting for default timezone */ if (!DATEG(default_timezone)) { /* Special case: ext/date wasn't initialized yet */ @@ -870,73 +863,8 @@ static char* guess_timezone(const timelib_tzdb *tzdb T } else if (*DATEG(default_timezone) && timelib_timezone_id_is_valid(DATEG(default_timezone), tzdb)) { return DATEG(default_timezone); } -#if HAVE_TM_ZONE - /* Try to guess timezone from system information */ - { - struct tm *ta, tmbuf; - time_t the_time; - char *tzid = NULL; - - the_time = time(NULL); - ta = php_localtime_r(&the_time, &tmbuf); - if (ta) { - tzid = timelib_timezone_id_from_abbr(ta->tm_zone, ta->tm_gmtoff, ta->tm_isdst); - } - if (! tzid) { - tzid = "UTC"; - } - - php_error_docref(NULL TSRMLS_CC, E_WARNING, DATE_TZ_ERRMSG "We selected '%s' for '%s/%.1f/%s' instead", tzid, ta ? ta->tm_zone : "Unknown", ta ? (float) (ta->tm_gmtoff / 3600) : 0, ta ? (ta->tm_isdst ? "DST" : "no DST") : "Unknown"); - return tzid; - } -#endif -#ifdef PHP_WIN32 - { - char *tzid; - TIME_ZONE_INFORMATION tzi; - - switch (GetTimeZoneInformation(&tzi)) - { - /* DST in effect */ - case TIME_ZONE_ID_DAYLIGHT: - /* If user has disabled DST in the control panel, Windows returns 0 here */ - if (tzi.DaylightBias == 0) { - goto php_win_std_time; - } - - tzid = timelib_timezone_id_from_abbr("", (tzi.Bias + tzi.DaylightBias) * -60, 1); - if (! tzid) { - tzid = "UTC"; - } - php_error_docref(NULL TSRMLS_CC, E_WARNING, DATE_TZ_ERRMSG "We selected '%s' for '%.1f/DST' instead", tzid, ((tzi.Bias + tzi.DaylightBias) / -60.0)); - break; - - /* no DST or not in effect */ - case TIME_ZONE_ID_UNKNOWN: - case TIME_ZONE_ID_STANDARD: - default: -php_win_std_time: - tzid = timelib_timezone_id_from_abbr("", (tzi.Bias + tzi.StandardBias) * -60, 0); - if (! tzid) { - tzid = "UTC"; - } - php_error_docref(NULL TSRMLS_CC, E_WARNING, DATE_TZ_ERRMSG "We selected '%s' for '%.1f/no DST' instead", tzid, ((tzi.Bias + tzi.StandardBias) / -60.0)); - break; - - } - return tzid; - } -#elif defined(NETWARE) - /* Try to guess timezone from system information */ - { - char *tzid = timelib_timezone_id_from_abbr("", ((_timezone * -1) + (daylightOffset * daylightOnOff)), daylightOnOff); - if (tzid) { - return tzid; - } - } -#endif /* Fallback to UTC */ - php_error_docref(NULL TSRMLS_CC, E_WARNING, DATE_TZ_ERRMSG "We had to select 'UTC' because your platform doesn't provide functionality for the guessing algorithm"); + php_error_docref(NULL TSRMLS_CC, E_WARNING, DATE_TZ_ERRMSG "We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone."); return "UTC"; } @@ -1213,14 +1141,13 @@ PHPAPI char *php_format_date(char *format, int format_ /* {{{ php_idate */ -PHPAPI int php_idate(char format, time_t ts, int localtime) +PHPAPI int php_idate(char format, time_t ts, int localtime TSRMLS_DC) { timelib_time *t; timelib_tzinfo *tzi; int retval = -1; timelib_time_offset *offset = NULL; timelib_sll isoweek, isoyear; - TSRMLS_FETCH(); t = timelib_time_ctor(); @@ -1346,7 +1273,7 @@ PHP_FUNCTION(idate) ts = time(NULL); } - ret = php_idate(format[0], ts, 0); + ret = php_idate(format[0], ts, 0 TSRMLS_CC); if (ret == -1) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unrecognized date format token."); RETURN_FALSE; @@ -2026,7 +1953,6 @@ static inline zend_object_value date_object_new_date_e { php_date_obj *intern; zend_object_value retval; - zval *tmp; intern = emalloc(sizeof(php_date_obj)); memset(intern, 0, sizeof(php_date_obj)); @@ -2035,7 +1961,7 @@ static inline zend_object_value date_object_new_date_e } zend_object_std_init(&intern->std, class_type TSRMLS_CC); - zend_hash_copy(intern->std.properties, &class_type->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *)); + object_properties_init(&intern->std, class_type); retval.handle = zend_objects_store_put(intern, (zend_objects_store_dtor_t)zend_objects_destroy_object, (zend_objects_free_object_storage_t) date_object_free_storage_date, NULL TSRMLS_CC); retval.handlers = &date_object_handlers_date; @@ -2150,7 +2076,6 @@ static inline zend_object_value date_object_new_timezo { php_timezone_obj *intern; zend_object_value retval; - zval *tmp; intern = emalloc(sizeof(php_timezone_obj)); memset(intern, 0, sizeof(php_timezone_obj)); @@ -2159,7 +2084,7 @@ static inline zend_object_value date_object_new_timezo } zend_object_std_init(&intern->std, class_type TSRMLS_CC); - zend_hash_copy(intern->std.properties, &class_type->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *)); + object_properties_init(&intern->std, class_type); retval.handle = zend_objects_store_put(intern, (zend_objects_store_dtor_t)zend_objects_destroy_object, (zend_objects_free_object_storage_t) date_object_free_storage_timezone, NULL TSRMLS_CC); retval.handlers = &date_object_handlers_timezone; @@ -2206,7 +2131,6 @@ static inline zend_object_value date_object_new_interv { php_interval_obj *intern; zend_object_value retval; - zval *tmp; intern = emalloc(sizeof(php_interval_obj)); memset(intern, 0, sizeof(php_interval_obj)); @@ -2215,7 +2139,7 @@ static inline zend_object_value date_object_new_interv } zend_object_std_init(&intern->std, class_type TSRMLS_CC); - zend_hash_copy(intern->std.properties, &class_type->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *)); + object_properties_init(&intern->std, class_type); retval.handle = zend_objects_store_put(intern, (zend_objects_store_dtor_t)zend_objects_destroy_object, (zend_objects_free_object_storage_t) date_object_free_storage_interval, NULL TSRMLS_CC); retval.handlers = &date_object_handlers_interval; @@ -2282,7 +2206,6 @@ static inline zend_object_value date_object_new_period { php_period_obj *intern; zend_object_value retval; - zval *tmp; intern = emalloc(sizeof(php_period_obj)); memset(intern, 0, sizeof(php_period_obj)); @@ -2291,7 +2214,7 @@ static inline zend_object_value date_object_new_period } zend_object_std_init(&intern->std, class_type TSRMLS_CC); - zend_hash_copy(intern->std.properties, &class_type->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *)); + object_properties_init(&intern->std, class_type); retval.handle = zend_objects_store_put(intern, (zend_objects_store_dtor_t)zend_objects_destroy_object, (zend_objects_free_object_storage_t) date_object_free_storage_period, NULL TSRMLS_CC); retval.handlers = &date_object_handlers_period; @@ -3495,7 +3418,7 @@ static int date_interval_initialize(timelib_rel_time * } /* {{{ date_interval_read_property */ -zval *date_interval_read_property(zval *object, zval *member, int type TSRMLS_DC) +zval *date_interval_read_property(zval *object, zval *member, int type, const zend_literal *key TSRMLS_DC) { php_interval_obj *obj; zval *retval; @@ -3526,7 +3449,7 @@ zval *date_interval_read_property(zval *object, zval * GET_VALUE_FROM_STRUCT(invert, "invert"); GET_VALUE_FROM_STRUCT(days, "days"); /* didn't find any */ - retval = (zend_get_std_object_handlers())->read_property(object, member, type TSRMLS_CC); + retval = (zend_get_std_object_handlers())->read_property(object, member, type, key TSRMLS_CC); if (member == &tmp_member) { zval_dtor(member); @@ -3549,7 +3472,7 @@ zval *date_interval_read_property(zval *object, zval * /* }}} */ /* {{{ date_interval_write_property */ -void date_interval_write_property(zval *object, zval *member, zval *value TSRMLS_DC) +void date_interval_write_property(zval *object, zval *member, zval *value, const zend_literal *key TSRMLS_DC) { php_interval_obj *obj; zval tmp_member, tmp_value; @@ -3586,7 +3509,7 @@ void date_interval_write_property(zval *object, zval * SET_VALUE_FROM_STRUCT(s, "s"); SET_VALUE_FROM_STRUCT(invert, "invert"); /* didn't find any */ - (zend_get_std_object_handlers())->write_property(object, member, value TSRMLS_CC); + (zend_get_std_object_handlers())->write_property(object, member, value, key TSRMLS_CC); } while(0); if (member == &tmp_member) {