Skip to content

Commit 492980c

Browse files
committed
Use bool/zend_result instead of int in Date extension
1 parent c19977d commit 492980c

File tree

2 files changed

+47
-46
lines changed

2 files changed

+47
-46
lines changed

ext/date/php_date.c

Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -621,15 +621,15 @@ static const char *php_date_short_day_name(timelib_sll y, timelib_sll m, timelib
621621
/* }}} */
622622

623623
/* {{{ date_format - (gm)date helper */
624-
static zend_string *date_format(const char *format, size_t format_len, timelib_time *t, int localtime)
624+
static zend_string *date_format(const char *format, size_t format_len, timelib_time *t, bool localtime)
625625
{
626626
smart_str string = {0};
627627
size_t i;
628628
int length = 0;
629629
char buffer[97];
630630
timelib_time_offset *offset = NULL;
631631
timelib_sll isoweek, isoyear;
632-
int rfc_colon;
632+
bool rfc_colon;
633633
int weekYearSet = 0;
634634

635635
if (!format_len) {
@@ -788,7 +788,7 @@ static zend_string *date_format(const char *format, size_t format_len, timelib_t
788788
return string.s;
789789
}
790790

791-
static void php_date(INTERNAL_FUNCTION_PARAMETERS, int localtime)
791+
static void php_date(INTERNAL_FUNCTION_PARAMETERS, bool localtime)
792792
{
793793
zend_string *format;
794794
zend_long ts;
@@ -808,7 +808,7 @@ static void php_date(INTERNAL_FUNCTION_PARAMETERS, int localtime)
808808
}
809809
/* }}} */
810810

811-
PHPAPI zend_string *php_format_date(const char *format, size_t format_len, time_t ts, int localtime) /* {{{ */
811+
PHPAPI zend_string *php_format_date(const char *format, size_t format_len, time_t ts, bool localtime) /* {{{ */
812812
{
813813
timelib_time *t;
814814
timelib_tzinfo *tzi;
@@ -834,7 +834,7 @@ PHPAPI zend_string *php_format_date(const char *format, size_t format_len, time_
834834
/* }}} */
835835

836836
/* {{{ php_idate */
837-
PHPAPI int php_idate(char format, time_t ts, int localtime)
837+
PHPAPI int php_idate(char format, time_t ts, bool localtime)
838838
{
839839
timelib_time *t;
840840
timelib_tzinfo *tzi;
@@ -1069,7 +1069,7 @@ PHP_FUNCTION(strtotime)
10691069
/* }}} */
10701070

10711071
/* {{{ php_mktime - (gm)mktime helper */
1072-
PHPAPI void php_mktime(INTERNAL_FUNCTION_PARAMETERS, int gmt)
1072+
PHPAPI void php_mktime(INTERNAL_FUNCTION_PARAMETERS, bool gmt)
10731073
{
10741074
zend_long hou, min, sec, mon, day, yea;
10751075
bool min_is_null = 1, sec_is_null = 1, mon_is_null = 1, day_is_null = 1, yea_is_null = 1;
@@ -1182,7 +1182,7 @@ PHP_FUNCTION(checkdate)
11821182
/* }}} */
11831183

11841184
/* {{{ php_strftime - (gm)strftime helper */
1185-
PHPAPI void php_strftime(INTERNAL_FUNCTION_PARAMETERS, int gmt)
1185+
PHPAPI void php_strftime(INTERNAL_FUNCTION_PARAMETERS, bool gmt)
11861186
{
11871187
zend_string *format;
11881188
zend_long timestamp;
@@ -2191,7 +2191,7 @@ static void php_date_get_current_time_with_fraction(time_t *sec, suseconds_t *us
21912191
#endif
21922192
}
21932193

2194-
PHPAPI int php_date_initialize(php_date_obj *dateobj, const char *time_str, size_t time_str_len, const char *format, zval *timezone_object, int flags) /* {{{ */
2194+
PHPAPI bool php_date_initialize(php_date_obj *dateobj, const char *time_str, size_t time_str_len, const char *format, zval *timezone_object, int flags) /* {{{ */
21952195
{
21962196
timelib_time *now;
21972197
timelib_tzinfo *tzi = NULL;
@@ -2526,13 +2526,13 @@ static bool php_date_initialize_from_hash(php_date_obj **dateobj, HashTable *myh
25262526
zend_string *tmp = zend_string_concat3(
25272527
Z_STRVAL_P(z_date), Z_STRLEN_P(z_date), " ", 1,
25282528
Z_STRVAL_P(z_timezone), Z_STRLEN_P(z_timezone));
2529-
int ret = php_date_initialize(*dateobj, ZSTR_VAL(tmp), ZSTR_LEN(tmp), NULL, NULL, 0);
2529+
bool ret = php_date_initialize(*dateobj, ZSTR_VAL(tmp), ZSTR_LEN(tmp), NULL, NULL, 0);
25302530
zend_string_release(tmp);
2531-
return 1 == ret;
2531+
return ret;
25322532
}
25332533

25342534
case TIMELIB_ZONETYPE_ID: {
2535-
int ret;
2535+
bool ret;
25362536
php_timezone_obj *tzobj;
25372537

25382538
tzi = php_date_parse_tzfile(Z_STRVAL_P(z_timezone), DATE_TIMEZONEDB);
@@ -2548,7 +2548,7 @@ static bool php_date_initialize_from_hash(php_date_obj **dateobj, HashTable *myh
25482548

25492549
ret = php_date_initialize(*dateobj, Z_STRVAL_P(z_date), Z_STRLEN_P(z_date), NULL, &tmp_obj, 0);
25502550
zval_ptr_dtor(&tmp_obj);
2551-
return 1 == ret;
2551+
return ret;
25522552
}
25532553
}
25542554
return false;
@@ -2793,7 +2793,7 @@ PHP_FUNCTION(date_format)
27932793
}
27942794
/* }}} */
27952795

2796-
static int php_date_modify(zval *object, char *modify, size_t modify_len) /* {{{ */
2796+
static bool php_date_modify(zval *object, char *modify, size_t modify_len) /* {{{ */
27972797
{
27982798
php_date_obj *dateobj;
27992799
timelib_time *tmp_time;
@@ -3389,7 +3389,7 @@ PHP_FUNCTION(date_diff)
33893389
}
33903390
/* }}} */
33913391

3392-
static int timezone_initialize(php_timezone_obj *tzobj, const char *tz, size_t tz_len) /* {{{ */
3392+
static zend_result timezone_initialize(php_timezone_obj *tzobj, const char *tz, size_t tz_len) /* {{{ */
33933393
{
33943394
timelib_time *dummy_t = ecalloc(1, sizeof(timelib_time));
33953395
int dst, not_found;
@@ -3425,7 +3425,7 @@ PHP_FUNCTION(timezone_open)
34253425
ZEND_PARSE_PARAMETERS_END();
34263426

34273427
tzobj = Z_PHPTIMEZONE_P(php_date_instantiate(date_ce_timezone, return_value));
3428-
if (SUCCESS != timezone_initialize(tzobj, ZSTR_VAL(tz), ZSTR_LEN(tz))) {
3428+
if (FAILURE == timezone_initialize(tzobj, ZSTR_VAL(tz), ZSTR_LEN(tz))) {
34293429
zval_ptr_dtor(return_value);
34303430
RETURN_FALSE;
34313431
}
@@ -3450,26 +3450,27 @@ PHP_METHOD(DateTimeZone, __construct)
34503450
}
34513451
/* }}} */
34523452

3453-
static int php_date_timezone_initialize_from_hash(zval **return_value, php_timezone_obj **tzobj, HashTable *myht) /* {{{ */
3453+
static zend_result php_date_timezone_initialize_from_hash(zval **return_value, php_timezone_obj **tzobj, HashTable *myht) /* {{{ */
34543454
{
34553455
zval *z_timezone_type;
34563456

3457-
if ((z_timezone_type = zend_hash_str_find(myht, "timezone_type", sizeof("timezone_type") - 1)) != NULL) {
3458-
zval *z_timezone;
3457+
if ((z_timezone_type = zend_hash_str_find(myht, "timezone_type", sizeof("timezone_type") - 1)) == NULL) {
3458+
return FAILURE;
3459+
}
34593460

3460-
if ((z_timezone = zend_hash_str_find(myht, "timezone", sizeof("timezone") - 1)) != NULL) {
3461-
if (Z_TYPE_P(z_timezone_type) != IS_LONG) {
3462-
return FAILURE;
3463-
}
3464-
if (Z_TYPE_P(z_timezone) != IS_STRING) {
3465-
return FAILURE;
3466-
}
3467-
if (SUCCESS == timezone_initialize(*tzobj, Z_STRVAL_P(z_timezone), Z_STRLEN_P(z_timezone))) {
3468-
return SUCCESS;
3469-
}
3470-
}
3461+
zval *z_timezone;
3462+
3463+
if ((z_timezone = zend_hash_str_find(myht, "timezone", sizeof("timezone") - 1)) == NULL) {
3464+
return FAILURE;
3465+
}
3466+
3467+
if (Z_TYPE_P(z_timezone_type) != IS_LONG) {
3468+
return FAILURE;
34713469
}
3472-
return FAILURE;
3470+
if (Z_TYPE_P(z_timezone) != IS_STRING) {
3471+
return FAILURE;
3472+
}
3473+
return timezone_initialize(*tzobj, Z_STRVAL_P(z_timezone), Z_STRLEN_P(z_timezone));
34733474
} /* }}} */
34743475

34753476
/* {{{ */
@@ -3487,7 +3488,7 @@ PHP_METHOD(DateTimeZone, __set_state)
34873488

34883489
php_date_instantiate(date_ce_timezone, return_value);
34893490
tzobj = Z_PHPTIMEZONE_P(return_value);
3490-
if(php_date_timezone_initialize_from_hash(&return_value, &tzobj, myht) != SUCCESS) {
3491+
if (php_date_timezone_initialize_from_hash(&return_value, &tzobj, myht) == FAILURE) {
34913492
zend_throw_error(NULL, "Timezone initialization failed");
34923493
zval_ptr_dtor(return_value);
34933494
}
@@ -3507,7 +3508,7 @@ PHP_METHOD(DateTimeZone, __wakeup)
35073508

35083509
myht = Z_OBJPROP_P(object);
35093510

3510-
if(php_date_timezone_initialize_from_hash(&return_value, &tzobj, myht) != SUCCESS) {
3511+
if (php_date_timezone_initialize_from_hash(&return_value, &tzobj, myht) == FAILURE) {
35113512
zend_throw_error(NULL, "Timezone initialization failed");
35123513
}
35133514
}
@@ -3590,7 +3591,8 @@ PHP_FUNCTION(timezone_transitions_get)
35903591
{
35913592
zval *object, element;
35923593
php_timezone_obj *tzobj;
3593-
unsigned int begin = 0, found;
3594+
int begin = 0;
3595+
bool found;
35943596
zend_long timestamp_begin = ZEND_LONG_MIN, timestamp_end = INT32_MAX;
35953597

35963598
if (zend_parse_method_parameters(ZEND_NUM_ARGS(), getThis(), "O|ll", &object, date_ce_timezone, &timestamp_begin, &timestamp_end) == FAILURE) {
@@ -3899,7 +3901,6 @@ PHP_METHOD(DateInterval, __construct)
38993901
}
39003902
/* }}} */
39013903

3902-
39033904
static int php_date_interval_initialize_from_hash(zval **return_value, php_interval_obj **intobj, HashTable *myht) /* {{{ */
39043905
{
39053906
(*intobj)->diff = timelib_rel_time_ctor();
@@ -4511,7 +4512,7 @@ PHP_FUNCTION(date_default_timezone_get)
45114512
/* {{{ php_do_date_sunrise_sunset
45124513
* Common for date_sunrise() and date_sunset() functions
45134514
*/
4514-
static void php_do_date_sunrise_sunset(INTERNAL_FUNCTION_PARAMETERS, int calc_sunset)
4515+
static void php_do_date_sunrise_sunset(INTERNAL_FUNCTION_PARAMETERS, bool calc_sunset)
45154516
{
45164517
double latitude, longitude, zenith, gmt_offset, altitude;
45174518
bool latitude_is_null = 1, longitude_is_null = 1, zenith_is_null = 1, gmt_offset_is_null = 1;
@@ -4788,7 +4789,7 @@ static HashTable *date_object_get_properties_period(zend_object *object) /* {{{
47884789
return props;
47894790
} /* }}} */
47904791

4791-
static int php_date_period_initialize_from_hash(php_period_obj *period_obj, HashTable *myht) /* {{{ */
4792+
static bool php_date_period_initialize_from_hash(php_period_obj *period_obj, HashTable *myht) /* {{{ */
47924793
{
47934794
zval *ht_entry;
47944795

@@ -4911,7 +4912,7 @@ PHP_METHOD(DatePeriod, __wakeup)
49114912
/* {{{ date_period_is_magic_property
49124913
* Common for date_period_read_property() and date_period_write_property() functions
49134914
*/
4914-
static int date_period_is_magic_property(zend_string *name)
4915+
static bool date_period_is_magic_property(zend_string *name)
49154916
{
49164917
if (zend_string_equals_literal(name, "recurrences")
49174918
|| zend_string_equals_literal(name, "include_start_date")

ext/date/php_date.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ static inline php_date_obj *php_date_obj_from_obj(zend_object *obj) {
5050
#define Z_PHPDATE_P(zv) php_date_obj_from_obj(Z_OBJ_P((zv)))
5151

5252
struct _php_timezone_obj {
53-
int initialized;
53+
bool initialized;
5454
int type;
5555
union {
5656
timelib_tzinfo *tz; /* TIMELIB_ZONETYPE_ID */
@@ -72,7 +72,7 @@ static inline php_timezone_obj *php_timezone_obj_from_obj(zend_object *obj) {
7272
struct _php_interval_obj {
7373
timelib_rel_time *diff;
7474
int civil_or_wall;
75-
int initialized;
75+
bool initialized;
7676
zend_object std;
7777
};
7878

@@ -89,8 +89,8 @@ struct _php_period_obj {
8989
timelib_time *end;
9090
timelib_rel_time *interval;
9191
int recurrences;
92-
int initialized;
93-
int include_start_date;
92+
bool initialized;
93+
bool include_start_date;
9494
zend_object std;
9595
};
9696

@@ -114,13 +114,13 @@ PHPAPI time_t php_time(void);
114114

115115
/* Backwards compatibility wrapper */
116116
PHPAPI zend_long php_parse_date(const char *string, zend_long *now);
117-
PHPAPI void php_mktime(INTERNAL_FUNCTION_PARAMETERS, int gmt);
118-
PHPAPI int php_idate(char format, time_t ts, int localtime);
117+
PHPAPI void php_mktime(INTERNAL_FUNCTION_PARAMETERS, bool gmt);
118+
PHPAPI int php_idate(char format, time_t ts, bool localtime);
119119

120120
#define _php_strftime php_strftime
121121

122-
PHPAPI void php_strftime(INTERNAL_FUNCTION_PARAMETERS, int gm);
123-
PHPAPI zend_string *php_format_date(const char *format, size_t format_len, time_t ts, int localtime);
122+
PHPAPI void php_strftime(INTERNAL_FUNCTION_PARAMETERS, bool gm);
123+
PHPAPI zend_string *php_format_date(const char *format, size_t format_len, time_t ts, bool localtime);
124124

125125
/* Mechanism to set new TZ database */
126126
PHPAPI void php_date_set_tzdb(timelib_tzdb *tzdb);
@@ -139,7 +139,7 @@ PHPAPI zend_class_entry *php_date_get_period_ce(void);
139139
#define PHP_DATE_INIT_FORMAT 0x02
140140

141141
PHPAPI zval *php_date_instantiate(zend_class_entry *pce, zval *object);
142-
PHPAPI int php_date_initialize(php_date_obj *dateobj, const char *time_str, size_t time_str_len, const char *format, zval *timezone_object, int flags);
142+
PHPAPI bool php_date_initialize(php_date_obj *dateobj, const char *time_str, size_t time_str_len, const char *format, zval *timezone_object, int flags);
143143

144144

145145
#endif /* PHP_DATE_H */

0 commit comments

Comments
 (0)