Skip to content

Commit d722041

Browse files
author
Ion Bazan
committed
fix
1 parent 64b8658 commit d722041

File tree

2 files changed

+54
-64
lines changed

2 files changed

+54
-64
lines changed

timecop.c

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -332,8 +332,8 @@ zend_module_entry timecop_module_entry = {
332332
};
333333
/* }}} */
334334

335-
#if defined(COMPILE_DL_TIMECOP) && PHP_MAJOR_VERSION >= 7
336-
# ifdef ZTS
335+
#if defined(COMPILE_DL_TIMECOP)
336+
# if defined(ZTS) && PHP_MAJOR_VERSION >= 7
337337
ZEND_TSRMLS_CACHE_DEFINE();
338338
# endif
339339
ZEND_GET_MODULE(timecop)
@@ -993,13 +993,15 @@ static int get_formatted_mock_time(zval *time, zval *timezone_obj, zval *retval_
993993
static int get_formatted_mock_time(zval *time, zval *timezone_obj, zval **retval_time, zval **retval_timezone TSRMLS_DC)
994994
#endif
995995
{
996-
zval str_now, now_timestamp;
996+
zval str_now, now_timestamp, format_str;
997997
tc_timeval now;
998998
zend_long fixed_usec;
999+
char buf[64];
1000+
9991001
#if PHP_MAJOR_VERSION >= 7
1000-
zval fixed_sec, orig_zonename;
1002+
zval fixed_sec, orig_zonename, dt;
10011003
#else
1002-
zval *fixed_sec, *orig_sec, *orig_zonename;
1004+
zval *fixed_sec, *orig_sec, *orig_zonename, *dt;
10031005
#endif
10041006

10051007
if (TIMECOP_G(timecop_mode) == TIMECOP_MODE_REALTIME) {
@@ -1092,15 +1094,6 @@ static int get_formatted_mock_time(zval *time, zval *timezone_obj, zval **retval
10921094
fixed_usec = now.usec;
10931095
}
10941096

1095-
#if PHP_MAJOR_VERSION >= 7
1096-
zval dt;
1097-
#else
1098-
zval *dt;
1099-
#endif
1100-
zval format_str;
1101-
1102-
char buf[64];
1103-
11041097
call_php_function_with_2_params(ORIG_FUNC_NAME("date_create"), &dt, time, timezone_obj);
11051098

11061099
#if PHP_MAJOR_VERSION >= 7

timecop.h

Lines changed: 47 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,12 @@ SOFTWARE.
3535
#include "php_ini.h"
3636
#include "ext/standard/info.h"
3737

38-
#if !defined(PHP_VERSION_ID) || PHP_VERSION_ID < 50300
39-
#include "ext/date/lib/timelib.h"
40-
#endif
41-
42-
extern zend_module_entry timecop_module_entry;
43-
#define phpext_timecop_ptr &timecop_module_entry
44-
4538
#ifdef PHP_WIN32
46-
# define PHP_TIMECOP_API __declspec(dllexport)
39+
# define PHP_TIMECOP_API __declspec(dllexport)
4740
#elif defined(__GNUC__) && __GNUC__ >= 4
48-
# define PHP_TIMECOP_API __attribute__ ((visibility("default")))
41+
# define PHP_TIMECOP_API __attribute__ ((visibility("default")))
4942
#else
50-
# define PHP_TIMECOP_API
43+
# define PHP_TIMECOP_API
5144
#endif
5245

5346
#ifdef ZTS
@@ -63,6 +56,10 @@ extern zend_module_entry timecop_module_entry;
6356
#include "Zend/zend_interfaces.h"
6457
#include "tc_timeval.h"
6558

59+
60+
extern zend_module_entry timecop_module_entry;
61+
#define phpext_timecop_ptr &timecop_module_entry
62+
6663
PHP_MINIT_FUNCTION(timecop);
6764
PHP_MSHUTDOWN_FUNCTION(timecop);
6865
PHP_RINIT_FUNCTION(timecop);
@@ -112,30 +109,30 @@ PHP_METHOD(Timecop, freeze);
112109
PHP_METHOD(Timecop, travel);
113110

114111
typedef enum timecop_mode_t {
115-
TIMECOP_MODE_REALTIME,
116-
TIMECOP_MODE_FREEZE,
117-
TIMECOP_MODE_TRAVEL
112+
TIMECOP_MODE_REALTIME,
113+
TIMECOP_MODE_FREEZE,
114+
TIMECOP_MODE_TRAVEL
118115
} timecop_mode_t;
119116

120117
ZEND_BEGIN_MODULE_GLOBALS(timecop)
121-
long func_override;
122-
long sync_request_time;
123-
#if PHP_VERSION_ID >= 70000
124-
zval orig_request_time;
118+
long func_override;
119+
long sync_request_time;
120+
#if PHP_MAJOR_VERSION >= 7
121+
zval orig_request_time;
125122
#else
126-
zval *orig_request_time;
123+
zval *orig_request_time;
127124
#endif
128-
timecop_mode_t timecop_mode;
129-
tc_timeval freezed_time;
130-
tc_timeval travel_origin;
131-
tc_timeval travel_offset;
132-
zend_long scaling_factor;
133-
zend_class_entry *ce_DateTimeZone;
134-
zend_class_entry *ce_DateTimeInterface;
135-
zend_class_entry *ce_DateTime;
136-
zend_class_entry *ce_TimecopDateTime;
137-
zend_class_entry *ce_DateTimeImmutable;
138-
zend_class_entry *ce_TimecopDateTimeImmutable;
125+
timecop_mode_t timecop_mode;
126+
tc_timeval freezed_time;
127+
tc_timeval travel_origin;
128+
tc_timeval travel_offset;
129+
zend_long scaling_factor;
130+
zend_class_entry *ce_DateTimeZone;
131+
zend_class_entry *ce_DateTimeInterface;
132+
zend_class_entry *ce_DateTime;
133+
zend_class_entry *ce_TimecopDateTime;
134+
zend_class_entry *ce_DateTimeImmutable;
135+
zend_class_entry *ce_TimecopDateTimeImmutable;
139136
ZEND_END_MODULE_GLOBALS(timecop)
140137

141138
#if ZEND_DEBUG
@@ -150,23 +147,23 @@ ZEND_END_MODULE_GLOBALS(timecop)
150147
#define OVRD_CLASS_PREFIX "timecop"
151148

152149
#define ORIG_FUNC_NAME(fname) \
153-
(TIMECOP_G(func_override) ? (SAVE_FUNC_PREFIX fname) : fname)
150+
(TIMECOP_G(func_override) ? (SAVE_FUNC_PREFIX fname) : fname)
154151

155152
#define TIMECOP_OFE(fname) {fname, OVRD_FUNC_PREFIX fname, SAVE_FUNC_PREFIX fname}
156153
#define TIMECOP_OCE(cname, mname) \
157-
{cname, mname, OVRD_CLASS_PREFIX cname, SAVE_FUNC_PREFIX mname}
154+
{cname, mname, OVRD_CLASS_PREFIX cname, SAVE_FUNC_PREFIX mname}
158155

159156
struct timecop_override_func_entry {
160-
char *orig_func;
161-
char *ovrd_func;
162-
char *save_func;
157+
char *orig_func;
158+
char *ovrd_func;
159+
char *save_func;
163160
};
164161

165162
struct timecop_override_class_entry {
166-
char *orig_class;
167-
char *orig_method;
168-
char *ovrd_class;
169-
char *save_method;
163+
char *orig_class;
164+
char *orig_method;
165+
char *ovrd_class;
166+
char *save_method;
170167
};
171168

172169
static void timecop_globals_ctor(zend_timecop_globals *globals TSRMLS_DC);
@@ -229,35 +226,35 @@ static inline void _call_php_function_with_params(const char *function_name, zva
229226

230227
#if PHP_MAJOR_VERSION >= 7
231228
#define register_internal_class_ex(class_entry, parent_ce) \
232-
zend_register_internal_class_ex(class_entry, parent_ce)
229+
zend_register_internal_class_ex(class_entry, parent_ce)
233230
#else
234231
#define register_internal_class_ex(class_entry, parent_ce) \
235-
zend_register_internal_class_ex(class_entry, parent_ce, NULL TSRMLS_CC)
232+
zend_register_internal_class_ex(class_entry, parent_ce, NULL TSRMLS_CC)
236233
#endif
237234

238235
#define call_php_method_with_0_params(obj, ce, method_name, retval) \
239-
_call_php_method_with_0_params(obj, ce, method_name, retval TSRMLS_CC)
236+
_call_php_method_with_0_params(obj, ce, method_name, retval TSRMLS_CC)
240237

241-
#define call_php_method_with_1_params(obj, ce, method_name, retval, arg1) \
242-
_call_php_method_with_1_params(obj, ce, method_name, retval, arg1 TSRMLS_CC)
238+
#define call_php_method_with_1_params(obj, ce, method_name, retval, arg1) \
239+
_call_php_method_with_1_params(obj, ce, method_name, retval, arg1 TSRMLS_CC)
243240

244241
#define call_php_method_with_2_params(obj, ce, method_name, retval, arg1, arg2) \
245-
_call_php_method_with_2_params(obj, ce, method_name, retval, arg1, arg2 TSRMLS_CC)
242+
_call_php_method_with_2_params(obj, ce, method_name, retval, arg1, arg2 TSRMLS_CC)
246243

247244
#define call_php_function_with_0_params(function_name, retval) \
248-
_call_php_function_with_0_params(function_name, retval TSRMLS_CC)
245+
_call_php_function_with_0_params(function_name, retval TSRMLS_CC)
249246

250247
#define call_php_function_with_1_params(function_name, retval, arg1) \
251-
_call_php_function_with_1_params(function_name, retval, arg1 TSRMLS_CC)
248+
_call_php_function_with_1_params(function_name, retval, arg1 TSRMLS_CC)
252249

253250
#define call_php_function_with_2_params(function_name, retval, arg1, arg2) \
254-
_call_php_function_with_2_params(function_name, retval, arg1, arg2 TSRMLS_CC)
251+
_call_php_function_with_2_params(function_name, retval, arg1, arg2 TSRMLS_CC)
255252

256253
#define call_php_function_with_3_params(function_name, retval, arg1, arg2, arg3) \
257-
_call_php_function_with_3_params(function_name, retval, arg1, arg2, arg3 TSRMLS_CC)
254+
_call_php_function_with_3_params(function_name, retval, arg1, arg2, arg3 TSRMLS_CC)
258255

259256
#define call_php_function_with_params(function_name, retval, param_count, params) \
260-
_call_php_function_with_params(function_name, retval, param_count, params TSRMLS_CC)
257+
_call_php_function_with_params(function_name, retval, param_count, params TSRMLS_CC)
261258

262259
/* In every utility function you add that needs to use variables
263260
in php_timecop_globals, call TSRMLS_FETCH(); after declaring other
@@ -282,7 +279,7 @@ static inline void _call_php_function_with_params(const char *function_name, zva
282279
# endif
283280
#endif
284281

285-
#endif /* PHP_TIMECOP_H */
282+
#endif /* PHP_TIMECOP_H */
286283

287284
/*
288285
* Local variables:

0 commit comments

Comments
 (0)