diff --git a/ext/hook.c b/ext/hook.c index 1f2af89..09dd578 100644 --- a/ext/hook.c +++ b/ext/hook.c @@ -122,10 +122,12 @@ static inline void apply_interval(timelib_time **time, timelib_rel_time *interva fci->params = _params; \ fci->named_params = NULL; \ fcc->function_handler = zend_hash_str_find_ptr(CG(function_table), #_name, strlen(#_name)); \ + zif_handler hook_handler = fcc->function_handler->internal_function.handler; \ fcc->function_handler->internal_function.handler = COLOPL_TS_G(orig_##_name); \ fcc->called_scope = NULL; \ fcc->object = NULL; \ zend_call_function(fci, fcc); \ + fcc->function_handler->internal_function.handler = hook_handler; \ efree(fci); \ efree(fcc); \ } while (0); @@ -699,25 +701,11 @@ static void hook_strtotime(INTERNAL_FUNCTION_PARAMETERS) return; } - if (is_fixed_ret == 2) { - CALL_ORIGINAL_FUNCTION(strtotime); - } else { - /* Call original function with params. */ - zval *params = NULL; - uint32_t param_count = 0; - zend_parse_parameters(ZEND_NUM_ARGS(), "+", ¶ms, ¶m_count); - ZVAL_LONG(¶ms[1], get_shifted_time(NULL)); - CALL_ORIGINAL_FUNCTION_WITH_PARAMS(strtotime, params, param_count); - } - - /* Apply interval. */ - timelib_time *t = timelib_time_ctor(); - timelib_rel_time interval; - timelib_unixtime2gmt(t, Z_LVAL_P(return_value)); - get_shift_interval(&interval); - apply_interval(&t, &interval); - RETVAL_LONG(timelib_date_to_int(t, NULL)); - timelib_time_dtor(t); + /* Call original function based on shifted time */ + zval params[2]; + ZVAL_STR(¶ms[0], times); + ZVAL_LONG(¶ms[1], get_shifted_time(NULL)); + CALL_ORIGINAL_FUNCTION_WITH_PARAMS(strtotime, params, 2); } #if HAVE_GETTIMEOFDAY diff --git a/ext/tests/functions/strtotime_extra.phpt b/ext/tests/functions/strtotime_extra.phpt deleted file mode 100644 index ea96580..0000000 --- a/ext/tests/functions/strtotime_extra.phpt +++ /dev/null @@ -1,30 +0,0 @@ ---TEST-- -Check strtotime() extra pattern ---EXTENSIONS-- -colopl_timeshifter ---FILE-- -diff($before); - -if ($before == $after_one || $before == $after_two) { - die('failed'); -} - -/* Note: Sometime valgrind makes flaky: $interval->y !== 2 */ -if (($interval->y > 2 && $interval->y !== 0) || $interval->invert !== 0) { - die('failed'); -} - -die('success'); - -?> ---EXPECT-- -success diff --git a/ext/tests/gh13.phpt b/ext/tests/gh13.phpt new file mode 100644 index 0000000..4bd6930 --- /dev/null +++ b/ext/tests/gh13.phpt @@ -0,0 +1,33 @@ +--TEST-- +Check GitHub Issue - #13 (strtotime extra pattern) +--EXTENSIONS-- +colopl_timeshifter +--FILE-- +diff($before); + +if ($before->getTimestamp() == $after_one->getTimestamp()) { + die('failed, $before == $after_one, ' . $before->format('Y-m-d H:i:s.u') . ' / ' . $after_one->format('Y-m-d H:i:s.u') . ' / ' . $after_two->format('Y-m-d H:i:s.u')); +} +if ($before->getTimestamp() == $after_two->getTimestamp()) { + die('failed, $before == $after_two, ' . $before->format('Y-m-d H:i:s.u') . ' / ' . $after_one->format('Y-m-d H:i:s.u') . ' / ' . $after_two->format('Y-m-d H:i:s.u')); +} + +/* Note: Sometime valgrind makes flaky: $interval->y !== 2 */ +if (($interval->y > 2 && $interval->y !== 0) || $interval->invert !== 0) { + die('failed, $interval->y = ' . $interval->y . ', $interval->invert = ' . $interval->invert); +} + +die('success'); + +?> +--EXPECT-- +success