diff --git a/README.md b/README.md index 7e13ca2..0a9d2d9 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ extension=timecop.so ## SYSTEM REQUIREMENTS - OS: Linux, macOS -- PHP: 5.3.1 - 7.1.x (might work on 5.2.x and 5.3.0, but not tested enough) +- PHP: 5.3.1 - 7.2.x (might work on 5.2.x and 5.3.0, but not tested enough) - SAPI: Apache, CLI - Other SAPIs are not tested, but there is no SAPI-dependent code. - non-ZTS(recommended), ZTS diff --git a/php_timecop.h b/php_timecop.h index 2d1466e..cef742c 100644 --- a/php_timecop.h +++ b/php_timecop.h @@ -112,7 +112,11 @@ ZEND_BEGIN_MODULE_GLOBALS(timecop) tc_timeval freezed_time; tc_timeval travel_origin; tc_timeval travel_offset; - tc_timeval_long scaling_factor; +#if PHP_VERSION_ID >= 70000 + zend_long scaling_factor; +#else + long scaling_factor; +#endif zend_class_entry *ce_DateTimeZone; zend_class_entry *ce_DateTimeInterface; zend_class_entry *ce_DateTime; diff --git a/tc_timeval.c b/tc_timeval.c index 9e35d64..8498574 100644 --- a/tc_timeval.c +++ b/tc_timeval.c @@ -26,7 +26,11 @@ SOFTWARE. int tc_timeval_add(tc_timeval *ret, const tc_timeval *arg1, const tc_timeval *arg2) { - tc_timeval_long sec, usec; +#if PHP_MAJOR_VERSION >= 7 + zend_long sec, usec; +#else + long sec, usec; +#endif usec = arg1->usec + arg2->usec; sec = arg1->sec + arg2->sec; if (usec < 0) { @@ -47,7 +51,11 @@ int tc_timeval_add(tc_timeval *ret, const tc_timeval *arg1, const tc_timeval *ar } int tc_timeval_sub(tc_timeval *ret, const tc_timeval *arg1, const tc_timeval *arg2) { - tc_timeval_long sec, usec; +#if PHP_MAJOR_VERSION >= 7 + zend_long sec, usec; +#else + long sec, usec; +#endif usec = arg1->usec - arg2->usec; sec = arg1->sec - arg2->sec; if (usec < 0) { @@ -66,9 +74,18 @@ int tc_timeval_sub(tc_timeval *ret, const tc_timeval *arg1, const tc_timeval *ar return 0; } -int tc_timeval_mul(tc_timeval *ret, const tc_timeval *arg1, const tc_timeval_long arg2) + +#if PHP_MAJOR_VERSION >= 7 +int tc_timeval_mul(tc_timeval *ret, const tc_timeval *arg1, const zend_long arg2) +#else +int tc_timeval_mul(tc_timeval *ret, const tc_timeval *arg1, const long arg2) +#endif { - tc_timeval_long sec, usec; +#if PHP_MAJOR_VERSION >= 7 + zend_long sec, usec; +#else + long sec, usec; +#endif usec = arg1->usec * arg2; sec = arg1->sec * arg2; if (usec < 0) { diff --git a/tc_timeval.h b/tc_timeval.h index fb25903..bf0f8a9 100644 --- a/tc_timeval.h +++ b/tc_timeval.h @@ -29,20 +29,24 @@ SOFTWARE. # define USEC_PER_SEC 1000000 #endif +typedef struct _tc_timeval { #if PHP_MAJOR_VERSION >= 7 -typedef zend_long tc_timeval_long; + zend_long sec; + zend_long usec; #else -typedef long tc_timeval_long; + long sec; + long usec; #endif - -typedef struct _tc_timeval { - tc_timeval_long sec; - tc_timeval_long usec; } tc_timeval; + int tc_timeval_add(tc_timeval *ret, const tc_timeval *arg1, const tc_timeval *arg2); int tc_timeval_sub(tc_timeval *ret, const tc_timeval *arg1, const tc_timeval *arg2); +#if PHP_MAJOR_VERSION >= 7 +int tc_timeval_mul(tc_timeval *ret, const tc_timeval *arg1, const zend_long arg2); +#else int tc_timeval_mul(tc_timeval *ret, const tc_timeval *arg1, const long arg2); +#endif #endif /* TC_TIMEVAL_H */ diff --git a/timecop_php5.c b/timecop_php5.c index 4e73b2f..d266a5d 100644 --- a/timecop_php5.c +++ b/timecop_php5.c @@ -1323,7 +1323,7 @@ static int get_current_time(tc_timeval *now TSRMLS_DC) if (ts == -1) { ret = -1; } else { - now->sec = ts; + now->sec = (long)ts; now->usec = 0; } #endif diff --git a/timecop_php7.c b/timecop_php7.c index f673af0..ec7400d 100644 --- a/timecop_php7.c +++ b/timecop_php7.c @@ -1231,15 +1231,15 @@ static int get_current_time(tc_timeval *now) struct timeval tv; ret = gettimeofday(&tv, NULL); if (ret == 0) { - now->sec = (long)tv.tv_sec; - now->usec = (long)tv.tv_usec; + now->sec = (zend_long)tv.tv_sec; + now->usec = (zend_long)tv.tv_usec; } #else time_t ts = time(NULL); if (ts == -1) { ret = -1; } else { - now->sec = ts; + now->sec = (zend_long)ts; now->usec = 0; } #endif