From b52a9ec52e796b3e340a7193cdccd4e11e182b6b Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Thu, 28 Feb 2019 11:46:40 +0100 Subject: test build for pending PR --- 44.patch | 197 ++++++++++++++++++++++++++++++++++++++++++++++++++ 45.patch | 184 ++++++++++++++++++++++++++++++++++++++++++++++ php-pecl-timecop.spec | 22 +++--- 3 files changed, 393 insertions(+), 10 deletions(-) create mode 100644 44.patch create mode 100644 45.patch diff --git a/44.patch b/44.patch new file mode 100644 index 0000000..e627247 --- /dev/null +++ b/44.patch @@ -0,0 +1,197 @@ +From aa0e74ca7f9fdff5fb25dc990a72005a8bfc018e Mon Sep 17 00:00:00 2001 +From: Ben Allison +Date: Mon, 14 Jan 2019 13:03:17 -0800 +Subject: [PATCH] Support strict_types=1 for overridden functions Fixes #43 + +--- + tests/issue_043.phpt | 22 ++++++++++++ + timecop_php7.c | 84 ++++++++++++++++++++++++++++++++++++++++++++ + 2 files changed, 106 insertions(+) + create mode 100644 tests/issue_043.phpt + +diff --git a/tests/issue_043.phpt b/tests/issue_043.phpt +new file mode 100644 +index 0000000..9e4fa0b +--- /dev/null ++++ b/tests/issue_043.phpt +@@ -0,0 +1,22 @@ ++--TEST-- ++Check for issue #43 (Overridden functions ignore declare(strict_types=1)) ++--SKIPIF-- ++getMessage(); ++} ++--EXPECT-- ++timecop_strtotime() expects parameter 1 to be string, null given +diff --git a/timecop_php7.c b/timecop_php7.c +index 8d7faec..0a0dda7 100644 +--- a/timecop_php7.c ++++ b/timecop_php7.c +@@ -1088,6 +1088,17 @@ PHP_FUNCTION(timecop_time) + Get UNIX timestamp for a date */ + PHP_FUNCTION(timecop_mktime) + { ++ zend_long hou = 0, min = 0, sec = 0, mon = 0, day = 0, yea = 0; ++ ZEND_PARSE_PARAMETERS_START(0, 6) ++ Z_PARAM_OPTIONAL ++ Z_PARAM_LONG(hou) ++ Z_PARAM_LONG(min) ++ Z_PARAM_LONG(sec) ++ Z_PARAM_LONG(mon) ++ Z_PARAM_LONG(day) ++ Z_PARAM_LONG(yea) ++ ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); ++ + TIMECOP_CALL_MKTIME("mktime", "date"); + } + /* }}} */ +@@ -1096,6 +1107,17 @@ PHP_FUNCTION(timecop_mktime) + Get UNIX timestamp for a GMT date */ + PHP_FUNCTION(timecop_gmmktime) + { ++ zend_long hou = 0, min = 0, sec = 0, mon = 0, day = 0, yea = 0; ++ ZEND_PARSE_PARAMETERS_START(0, 6) ++ Z_PARAM_OPTIONAL ++ Z_PARAM_LONG(hou) ++ Z_PARAM_LONG(min) ++ Z_PARAM_LONG(sec) ++ Z_PARAM_LONG(mon) ++ Z_PARAM_LONG(day) ++ Z_PARAM_LONG(yea) ++ ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); ++ + TIMECOP_CALL_MKTIME("gmmktime", "gmdate"); + } + /* }}} */ +@@ -1104,6 +1126,14 @@ PHP_FUNCTION(timecop_gmmktime) + Format a local date/time */ + PHP_FUNCTION(timecop_date) + { ++ zend_string *format; ++ zend_long ts; ++ ZEND_PARSE_PARAMETERS_START(1, 2) ++ Z_PARAM_STR(format) ++ Z_PARAM_OPTIONAL ++ Z_PARAM_LONG(ts) ++ ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); ++ + TIMECOP_CALL_FUNCTION("date", 1); + } + /* }}} */ +@@ -1112,6 +1142,14 @@ PHP_FUNCTION(timecop_date) + Format a GMT date/time */ + PHP_FUNCTION(timecop_gmdate) + { ++ zend_string *format; ++ zend_long ts; ++ ZEND_PARSE_PARAMETERS_START(1, 2) ++ Z_PARAM_STR(format) ++ Z_PARAM_OPTIONAL ++ Z_PARAM_LONG(ts) ++ ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); ++ + TIMECOP_CALL_FUNCTION("gmdate", 1); + } + /* }}} */ +@@ -1120,6 +1158,14 @@ PHP_FUNCTION(timecop_gmdate) + Format a local time/date as integer */ + PHP_FUNCTION(timecop_idate) + { ++ zend_string *format; ++ zend_long ts; ++ ZEND_PARSE_PARAMETERS_START(1, 2) ++ Z_PARAM_STR(format) ++ Z_PARAM_OPTIONAL ++ Z_PARAM_LONG(ts) ++ ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); ++ + TIMECOP_CALL_FUNCTION("idate", 1); + } + /* }}} */ +@@ -1128,6 +1174,12 @@ PHP_FUNCTION(timecop_idate) + Get date/time information */ + PHP_FUNCTION(timecop_getdate) + { ++ zend_long ts; ++ ZEND_PARSE_PARAMETERS_START(0, 1) ++ Z_PARAM_OPTIONAL ++ Z_PARAM_LONG(ts) ++ ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); ++ + TIMECOP_CALL_FUNCTION("getdate", 0); + } + /* }}} */ +@@ -1137,6 +1189,14 @@ PHP_FUNCTION(timecop_getdate) + the associative_array argument is set to 1 other wise it is a regular array */ + PHP_FUNCTION(timecop_localtime) + { ++ zend_long timestamp; ++ zend_bool associative; ++ ZEND_PARSE_PARAMETERS_START(0, 2) ++ Z_PARAM_OPTIONAL ++ Z_PARAM_LONG(timestamp) ++ Z_PARAM_BOOL(associative) ++ ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); ++ + TIMECOP_CALL_FUNCTION("localtime", 0); + } + /* }}} */ +@@ -1145,6 +1205,14 @@ PHP_FUNCTION(timecop_localtime) + Convert string representation of date and time to a timestamp */ + PHP_FUNCTION(timecop_strtotime) + { ++ zend_string *times; ++ zend_long preset_ts; ++ ZEND_PARSE_PARAMETERS_START(1, 2) ++ Z_PARAM_STR(times) ++ Z_PARAM_OPTIONAL ++ Z_PARAM_LONG(preset_ts) ++ ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); ++ + TIMECOP_CALL_FUNCTION("strtotime", 1); + } + /* }}} */ +@@ -1153,6 +1221,14 @@ PHP_FUNCTION(timecop_strtotime) + Format a local time/date according to locale settings */ + PHP_FUNCTION(timecop_strftime) + { ++ zend_string *format; ++ zend_long timestamp; ++ ZEND_PARSE_PARAMETERS_START(1, 2) ++ Z_PARAM_STR(format) ++ Z_PARAM_OPTIONAL ++ Z_PARAM_LONG(timestamp) ++ ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); ++ + TIMECOP_CALL_FUNCTION("strftime", 1); + } + /* }}} */ +@@ -1161,6 +1237,14 @@ PHP_FUNCTION(timecop_strftime) + Format a GMT/UCT time/date according to locale settings */ + PHP_FUNCTION(timecop_gmstrftime) + { ++ zend_string *format; ++ zend_long timestamp = 0; ++ ZEND_PARSE_PARAMETERS_START(1, 2) ++ Z_PARAM_STR(format) ++ Z_PARAM_OPTIONAL ++ Z_PARAM_LONG(timestamp) ++ ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE); ++ + TIMECOP_CALL_FUNCTION("gmstrftime", 1); + } + /* }}} */ diff --git a/45.patch b/45.patch new file mode 100644 index 0000000..4ba34e6 --- /dev/null +++ b/45.patch @@ -0,0 +1,184 @@ +From 53d972905a9f36edd86daf7381e5a9d3f99a962c Mon Sep 17 00:00:00 2001 +From: Remi Collet +Date: Thu, 28 Feb 2019 11:34:36 +0100 +Subject: [PATCH] fix for ZTS + +--- + timecop_php7.c | 61 ++++++++++++++++++++++++++++---------------------- + 1 file changed, 34 insertions(+), 27 deletions(-) + +diff --git a/timecop_php7.c b/timecop_php7.c +index 8d7faec..ea912f2 100644 +--- a/timecop_php7.c ++++ b/timecop_php7.c +@@ -311,12 +311,17 @@ static inline void _call_php_function_with_2_params(const char *function_name, z + static void _call_php_function_with_3_params(const char *function_name, zval *retval_ptr, zval *arg1, zval *arg2, zval *arg3); + static inline void _call_php_function_with_params(const char *function_name, zval *retval_ptr, uint32_t param_count, zval params[]); + ++static const zend_module_dep timecop_module_deps[] = { ++ ZEND_MOD_REQUIRED("Date") ++ ZEND_MOD_END ++}; ++ + /* {{{ timecop_module_entry + */ + zend_module_entry timecop_module_entry = { +-#if ZEND_MODULE_API_NO >= 20010901 +- STANDARD_MODULE_HEADER, +-#endif ++ STANDARD_MODULE_HEADER_EX, ++ NULL, ++ timecop_module_deps, + "timecop", + timecop_functions, + PHP_MINIT(timecop), +@@ -355,6 +360,14 @@ PHP_MINIT_FUNCTION(timecop) + ZEND_INIT_MODULE_GLOBALS(timecop, timecop_globals_ctor, NULL); + REGISTER_INI_ENTRIES(); + register_timecop_classes(); ++ ++ if (TIMECOP_G(func_override)) { ++ if (SUCCESS != timecop_func_override() || ++ SUCCESS != timecop_class_override()) { ++ return FAILURE; ++ } ++ } ++ + return SUCCESS; + } + /* }}} */ +@@ -364,6 +377,12 @@ PHP_MINIT_FUNCTION(timecop) + PHP_MSHUTDOWN_FUNCTION(timecop) + { + UNREGISTER_INI_ENTRIES(); ++ ++ if (TIMECOP_G(func_override)) { ++ timecop_func_override_clear(); ++ timecop_class_override_clear(); ++ } ++ + return SUCCESS; + } + /* }}} */ +@@ -375,13 +394,6 @@ PHP_RINIT_FUNCTION(timecop) + ZEND_TSRMLS_CACHE_UPDATE(); + #endif + +- if (TIMECOP_G(func_override)) { +- if (SUCCESS != timecop_func_override() || +- SUCCESS != timecop_class_override()) { +- return FAILURE; +- } +- } +- + return SUCCESS; + } + /* }}} */ +@@ -389,11 +401,6 @@ PHP_RINIT_FUNCTION(timecop) + /* {{{ PHP_RSHUTDOWN_FUNCTION(timecop) */ + PHP_RSHUTDOWN_FUNCTION(timecop) + { +- if (TIMECOP_G(func_override)) { +- timecop_func_override_clear(); +- timecop_class_override_clear(); +- } +- + if (Z_TYPE(TIMECOP_G(orig_request_time)) == IS_NULL) { + restore_request_time(); + } +@@ -496,14 +503,14 @@ static int timecop_func_override() + + p = &(timecop_override_func_table[0]); + while (p->orig_func != NULL) { +- zf_orig = zend_hash_str_find_ptr(EG(function_table), p->orig_func, strlen(p->orig_func)); ++ zf_orig = zend_hash_str_find_ptr(CG(function_table), p->orig_func, strlen(p->orig_func)); + if (zf_orig == NULL) { + /* Do nothing. Because some functions are introduced by optional extensions. */ + p++; + continue; + } + +- zf_ovrd = zend_hash_str_find_ptr(EG(function_table), p->ovrd_func, strlen(p->ovrd_func)); ++ zf_ovrd = zend_hash_str_find_ptr(CG(function_table), p->ovrd_func, strlen(p->ovrd_func)); + if (zf_ovrd == NULL) { + php_error_docref("https://github.com/hnw/php-timecop", E_WARNING, + "timecop couldn't find function %s.", p->ovrd_func); +@@ -511,7 +518,7 @@ static int timecop_func_override() + continue; + } + +- zf_save = zend_hash_str_find_ptr(EG(function_table), p->save_func, strlen(p->save_func)); ++ zf_save = zend_hash_str_find_ptr(CG(function_table), p->save_func, strlen(p->save_func)); + if (zf_save != NULL) { + php_error_docref("https://github.com/hnw/php-timecop", E_WARNING, + "timecop couldn't create function %s because already exists.", +@@ -523,12 +530,12 @@ static int timecop_func_override() + TIMECOP_ASSERT(zf_orig->type == ZEND_INTERNAL_FUNCTION); + TIMECOP_ASSERT(zf_ovrd->type == ZEND_INTERNAL_FUNCTION); + +- zend_hash_str_add_mem(EG(function_table), p->save_func, strlen(p->save_func), ++ zend_hash_str_add_mem(CG(function_table), p->save_func, strlen(p->save_func), + zf_orig, sizeof(zend_internal_function)); + function_add_ref(zf_orig); + + GUARD_FUNCTION_ARG_INFO_BEGIN(zf_orig); +- zend_hash_str_update_mem(EG(function_table), p->orig_func, strlen(p->orig_func), ++ zend_hash_str_update_mem(CG(function_table), p->orig_func, strlen(p->orig_func), + zf_ovrd, sizeof(zend_internal_function)); + GUARD_FUNCTION_ARG_INFO_END(); + function_add_ref(zf_ovrd); +@@ -546,7 +553,7 @@ static int timecop_class_override() + + p = &(timecop_override_class_table[0]); + while (p->orig_class != NULL) { +- ce_orig = zend_hash_str_find_ptr(EG(class_table), p->orig_class, strlen(p->orig_class)); ++ ce_orig = zend_hash_str_find_ptr(CG(class_table), p->orig_class, strlen(p->orig_class)); + if (ce_orig == NULL) { + php_error_docref("https://github.com/hnw/php-timecop", E_WARNING, + "timecop couldn't find class %s.", p->orig_class); +@@ -554,7 +561,7 @@ static int timecop_class_override() + continue; + } + +- ce_ovrd = zend_hash_str_find_ptr(EG(class_table), p->ovrd_class, strlen(p->ovrd_class)); ++ ce_ovrd = zend_hash_str_find_ptr(CG(class_table), p->ovrd_class, strlen(p->ovrd_class)); + if (ce_ovrd == NULL) { + php_error_docref("https://github.com/hnw/php-timecop", E_WARNING, + "timecop couldn't find class %s.", p->ovrd_class); +@@ -626,9 +633,9 @@ static int timecop_func_override_clear() + + p = &(timecop_override_func_table[0]); + while (p->orig_func != NULL) { +- zf_orig = zend_hash_str_find_ptr(EG(function_table), ++ zf_orig = zend_hash_str_find_ptr(CG(function_table), + p->save_func, strlen(p->save_func)); +- zf_ovld = zend_hash_str_find_ptr(EG(function_table), ++ zf_ovld = zend_hash_str_find_ptr(CG(function_table), + p->orig_func, strlen(p->orig_func)); + if (zf_orig == NULL || zf_ovld == NULL) { + p++; +@@ -636,13 +643,13 @@ static int timecop_func_override_clear() + } + + GUARD_FUNCTION_ARG_INFO_BEGIN(zf_ovld); +- zend_hash_str_update_mem(EG(function_table), p->orig_func, strlen(p->orig_func), ++ zend_hash_str_update_mem(CG(function_table), p->orig_func, strlen(p->orig_func), + zf_orig, sizeof(zend_internal_function)); + GUARD_FUNCTION_ARG_INFO_END(); + function_add_ref(zf_orig); + + GUARD_FUNCTION_ARG_INFO_BEGIN(zf_orig); +- zend_hash_str_del(EG(function_table), p->save_func, strlen(p->save_func)); ++ zend_hash_str_del(CG(function_table), p->save_func, strlen(p->save_func)); + GUARD_FUNCTION_ARG_INFO_END(); + + p++; +@@ -658,7 +665,7 @@ static int timecop_class_override_clear() + + p = &(timecop_override_class_table[0]); + while (p->orig_class != NULL) { +- ce_orig = zend_hash_str_find_ptr(EG(class_table), ++ ce_orig = zend_hash_str_find_ptr(CG(class_table), + p->orig_class, strlen(p->orig_class)); + if (ce_orig == NULL) { + php_error_docref("https://github.com/hnw/php-timecop", E_WARNING, diff --git a/php-pecl-timecop.spec b/php-pecl-timecop.spec index 10ac6b0..8b07c70 100644 --- a/php-pecl-timecop.spec +++ b/php-pecl-timecop.spec @@ -1,6 +1,6 @@ # remirepo spec file for php-pecl-timecop # -# Copyright (c) 2017-2018 Remi Collet +# Copyright (c) 2017-2019 Remi Collet # License: CC-BY-SA # http://creativecommons.org/licenses/by-sa/4.0/ # @@ -23,11 +23,16 @@ Summary: Time travel and freezing extension Name: %{?sub_prefix}php-pecl-timecop Version: 1.2.10 -Release: 4%{?dist}%{!?scl:%{!?nophptag:%(%{__php} -r 'echo ".".PHP_MAJOR_VERSION.".".PHP_MINOR_VERSION;')}} +Release: 5%{?dist}%{!?scl:%{!?nophptag:%(%{__php} -r 'echo ".".PHP_MAJOR_VERSION.".".PHP_MINOR_VERSION;')}} License: MIT URL: http://pecl.php.net/package/%{pecl_name} Source0: http://pecl.php.net/get/%{pecl_name}-%{version}.tgz +# https://github.com/hnw/php-timecop/pull/44 Support strict_types +Patch0: https://patch-diff.githubusercontent.com/raw/hnw/php-timecop/pull/44.patch +# https://github.com/hnw/php-timecop/pull/45 for ZTS +Patch1: https://patch-diff.githubusercontent.com/raw/hnw/php-timecop/pull/45.patch + BuildRequires: %{?dtsprefix}gcc BuildRequires: %{?scl_prefix}php-devel BuildRequires: %{?scl_prefix}php-pear @@ -48,14 +53,6 @@ Provides: %{?scl_prefix}php-pecl-%{pecl_name}%{?_isa} = %{version}-%{relea %if "%{?vendor}" == "Remi Collet" && 0%{!?scl:1} && 0%{?rhel} # Other third party repo stuff -%if "%{php_version}" > "5.6" -Obsoletes: php56u-pecl-%{pecl_name} <= %{version} -Obsoletes: php56w-pecl-%{pecl_name} <= %{version} -%endif -%if "%{php_version}" > "7.0" -Obsoletes: php70u-pecl-%{pecl_name} <= %{version} -Obsoletes: php70w-pecl-%{pecl_name} <= %{version} -%endif %if "%{php_version}" > "7.1" Obsoletes: php71u-pecl-%{pecl_name} <= %{version} Obsoletes: php71w-pecl-%{pecl_name} <= %{version} @@ -94,6 +91,8 @@ sed -e 's/role="test"/role="src"/' \ -i package.xml cd NTS +%patch0 -p1 -b .pr44 +%patch1 -p1 -b .pr45 # Sanity check, really often broken extver=$(sed -n '/#define PHP_TIMECOP_VERSION/{s/.* "//;s/".*$//;p}' php_timecop.h) @@ -247,6 +246,9 @@ fi %changelog +* Thu Feb 28 2019 Remi Collet - 1.2.10-5 +- test build for pending PR + * Wed Dec 12 2018 Remi Collet - 1.2.10-4 - ignore failing test with 7.3, reported as https://github.com/hnw/php-timecop/issues/42 -- cgit