summaryrefslogtreecommitdiffstats
path: root/45.patch
blob: 4ba34e6c90981a62022699cbf43960338c59a68b (plain)
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
From 53d972905a9f36edd86daf7381e5a9d3f99a962c Mon Sep 17 00:00:00 2001
From: Remi Collet <remi@remirepo.net>
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,