forked from hnw/php-timecop
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathphp_timecop.h
More file actions
198 lines (160 loc) · 5.9 KB
/
php_timecop.h
File metadata and controls
198 lines (160 loc) · 5.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/*
MIT License
Copyright (c) 2012-2017 Yoshio HANAWA
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef PHP_TIMECOP_H
#define PHP_TIMECOP_H
#define PHP_TIMECOP_VERSION "1.9.0"
extern zend_module_entry timecop_module_entry;
#define phpext_timecop_ptr &timecop_module_entry
#ifdef PHP_WIN32
# define PHP_TIMECOP_API __declspec(dllexport)
#elif defined(__GNUC__) && __GNUC__ >= 4
# define PHP_TIMECOP_API __attribute__ ((visibility("default")))
#else
# define PHP_TIMECOP_API
#endif
#ifdef ZTS
#include "TSRM.h"
#endif
#ifndef PHP_WIN32
#include <time.h>
#else
#include "win32/time.h"
#endif
#include "Zend/zend_interfaces.h"
#include "tc_timeval.h"
PHP_MINIT_FUNCTION(timecop);
PHP_MSHUTDOWN_FUNCTION(timecop);
PHP_RINIT_FUNCTION(timecop);
PHP_RSHUTDOWN_FUNCTION(timecop);
PHP_MINFO_FUNCTION(timecop);
PHP_FUNCTION(timecop_freeze);
PHP_FUNCTION(timecop_travel);
PHP_FUNCTION(timecop_scale);
PHP_FUNCTION(timecop_return);
PHP_FUNCTION(timecop_time);
PHP_FUNCTION(timecop_mktime);
PHP_FUNCTION(timecop_gmmktime);
PHP_FUNCTION(timecop_date);
PHP_FUNCTION(timecop_gmdate);
PHP_FUNCTION(timecop_idate);
PHP_FUNCTION(timecop_getdate);
PHP_FUNCTION(timecop_localtime);
PHP_FUNCTION(timecop_strtotime);
#if PHP_VERSION_ID < 80400
PHP_FUNCTION(timecop_strftime);
PHP_FUNCTION(timecop_gmstrftime);
#endif
#ifdef HAVE_GETTIMEOFDAY
PHP_FUNCTION(timecop_microtime);
PHP_FUNCTION(timecop_gettimeofday);
#endif
PHP_FUNCTION(timecop_unixtojd);
PHP_FUNCTION(timecop_date_create);
PHP_FUNCTION(timecop_date_create_from_format);
PHP_FUNCTION(timecop_date_create_immutable);
PHP_FUNCTION(timecop_date_create_immutable_from_format);
PHP_METHOD(TimecopDateTime, __construct);
PHP_METHOD(TimecopOrigDateTime, __construct);
PHP_METHOD(TimecopDateTimeImmutable, __construct);
PHP_METHOD(TimecopOrigDateTimeImmutable, __construct);
PHP_METHOD(Timecop, freeze);
PHP_METHOD(Timecop, travel);
typedef enum timecop_mode_t {
TIMECOP_MODE_REALTIME,
TIMECOP_MODE_FREEZE,
TIMECOP_MODE_TRAVEL
} timecop_mode_t;
ZEND_BEGIN_MODULE_GLOBALS(timecop)
long func_override;
long sync_request_time;
zval orig_request_time;
timecop_mode_t timecop_mode;
tc_timeval freezed_time;
tc_timeval travel_origin;
tc_timeval travel_offset;
zend_long scaling_factor;
zend_class_entry *ce_DateTimeZone;
zend_class_entry *ce_DateTimeInterface;
zend_class_entry *ce_DateTime;
zend_class_entry *ce_TimecopDateTime;
zend_class_entry *ce_DateTimeImmutable;
zend_class_entry *ce_TimecopDateTimeImmutable;
ZEND_END_MODULE_GLOBALS(timecop)
#if ZEND_DEBUG
# define TIMECOP_ASSERT(c) assert(c)
#else
# define TIMECOP_ASSERT(c)
#endif /* ZEND_DEBUG */
#define SAVE_FUNC_PREFIX "timecop_orig_"
#define OVRD_FUNC_PREFIX "timecop_"
#define OVRD_CLASS_PREFIX "timecop"
#define ORIG_FUNC_NAME(fname) \
(TIMECOP_G(func_override) ? (SAVE_FUNC_PREFIX fname) : fname)
#define TIMECOP_OFE(fname) {fname, OVRD_FUNC_PREFIX fname, SAVE_FUNC_PREFIX fname}
#define TIMECOP_OCE(cname, mname) \
{cname, mname, OVRD_CLASS_PREFIX cname, SAVE_FUNC_PREFIX mname}
/*
* Trick for guarding the multi-referenced internal function from function destructor on PHP 7.2.0+
* See: https://github.com/hnw/php-timecop/issues/29#issuecomment-332171527
*/
#define FIX_FUNCTION_ARG_INFO_DTOR(zend_func) zend_func->common.arg_info = NULL;
struct timecop_override_func_entry {
char *orig_func;
char *ovrd_func;
char *save_func;
};
struct timecop_override_class_entry {
char *orig_class;
char *orig_method;
char *ovrd_class;
char *save_method;
};
#define call_php_method_with_0_params(obj, ce, method_name, retval) \
_call_php_method_with_0_params(obj, ce, method_name, retval)
#define call_php_method_with_1_params(obj, ce, method_name, retval, arg1) \
_call_php_method_with_1_params(obj, ce, method_name, retval, arg1)
#define call_php_method_with_2_params(obj, ce, method_name, retval, arg1, arg2) \
_call_php_method_with_2_params(obj, ce, method_name, retval, arg1, arg2)
#define call_php_function_with_0_params(function_name, retval) \
_call_php_method_with_0_params(NULL, NULL, function_name, retval)
#define call_php_function_with_1_params(function_name, retval, arg1) \
_call_php_method_with_1_params(NULL, NULL, function_name, retval, arg1)
#define call_php_function_with_2_params(function_name, retval, arg1, arg2) \
_call_php_method_with_2_params(NULL, NULL, function_name, retval, arg1, arg2)
#define call_php_function_with_3_params(function_name, retval, arg1, arg2, arg3) \
_call_php_function_with_3_params(function_name, retval, arg1, arg2, arg3)
#define TIMECOP_PARSE_TRAVEL_ARGS(timeval) \
if (parse_travel_freeze_arguments(&timeval, INTERNAL_FUNCTION_PARAM_PASSTHRU) > 0) { \
RETURN_THROWS(); \
}
#define TIMECOP_PARSE_FREEZE_ARGS TIMECOP_PARSE_TRAVEL_ARGS
#define TIMECOP_G(v) ZEND_MODULE_GLOBALS_ACCESSOR(timecop, v)
#if defined(ZTS) && defined(COMPILE_DL_TIMECOP)
ZEND_TSRMLS_CACHE_EXTERN();
#endif
#endif /* PHP_TIMECOP_H */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/