summaryrefslogtreecommitdiffstats
path: root/fedora/uopz-upstream.patch
blob: 35a29a764d0edfe8063826808843a94ab6b99aeb (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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
From b15f4d83a760013142c5275a2b29244a5ef62d90 Mon Sep 17 00:00:00 2001
From: Joe Watkins <krakjoe@php.net>
Date: Thu, 26 May 2016 12:10:15 +0100
Subject: [PATCH] fixes for 7.1, add leave helper function

---
 src/class.c    | 55 +++++++++++++++++++++++++++++++++----------------------
 src/handlers.c | 33 +++++++++++++++++++++++----------
 uopz.h         |  2 +-
 3 files changed, 57 insertions(+), 33 deletions(-)

diff --git a/src/class.c b/src/class.c
index 15100d9..db9fe6c 100644
--- a/src/class.c
+++ b/src/class.c
@@ -27,6 +27,14 @@
 
 ZEND_EXTERN_MODULE_GLOBALS(uopz);
 
+#if PHP_VERSION_ID >= 70100
+#	define uopz_get_scope(e) ((e) ? zend_get_executed_scope() : EG(fake_scope))
+#	define uopz_set_scope(s) EG(fake_scope) = (s)
+#else
+#	define uopz_get_scope(e) EG(scope)
+#	define uopz_set_scope(s) EG(scope) = (s)
+#endif
+
 void uopz_set_mock(zend_string *clazz, zval *mock) { /* {{{ */
 	zend_string *key = zend_string_tolower(clazz);
 
@@ -131,12 +139,12 @@ zend_bool uopz_implement(zend_class_entry *clazz, zend_class_entry *interface) {
 } /* }}} */
 
 void uopz_set_property(zval *object, zval *member, zval *value) { /* {{{ */
-	zend_class_entry *scope = EG(scope);
+	zend_class_entry *scope = uopz_get_scope(1);
 	zend_class_entry *ce = Z_OBJCE_P(object);
 	zend_property_info *info;
 
 	do {
-		EG(scope) = ce;
+		uopz_set_scope(ce);
 
 		info = zend_get_property_info(ce, Z_STR_P(member), 1);
 	
@@ -148,25 +156,25 @@ void uopz_set_property(zval *object, zval *member, zval *value) { /* {{{ */
 	} while (ce);
 
 	if (info && info != ZEND_WRONG_PROPERTY_INFO) {
-		EG(scope) = info->ce;
+		uopz_set_scope(info->ce);
 	} else {
-		EG(scope) = Z_OBJCE_P(object);
+		uopz_set_scope(Z_OBJCE_P(object));
 	}
 
 	Z_OBJ_HT_P(object)
 		->write_property(object, member, value, NULL);
 
-	EG(scope) = scope;
+	uopz_set_scope(scope);
 } /* }}} */
 
 void uopz_get_property(zval *object, zval *member, zval *value) { /* {{{ */
-	zend_class_entry *scope = EG(scope);
+	zend_class_entry *scope = uopz_get_scope(1);
 	zend_class_entry *ce = Z_OBJCE_P(object);
 	zend_property_info *info;
 	zval *prop, rv;
 
 	do {
-		EG(scope) = ce;
+		uopz_set_scope(ce);
 
 		info = zend_get_property_info(ce, Z_STR_P(member), 1);
 	
@@ -178,14 +186,15 @@ void uopz_get_property(zval *object, zval *member, zval *value) { /* {{{ */
 	} while (ce);
 
 	if (info && info != ZEND_WRONG_PROPERTY_INFO) {
-		EG(scope) = info->ce;
+		uopz_set_scope(info->ce);
 	} else {
-		EG(scope) = Z_OBJCE_P(object);
+		uopz_set_scope(Z_OBJCE_P(object));
 	}
 	
 	prop = Z_OBJ_HT_P(object)
 		->read_property(object, member, BP_VAR_R, NULL, &rv);
-	EG(scope) = scope;
+
+	uopz_set_scope(scope);
 
 	if (!prop) {
 		return;
@@ -195,13 +204,13 @@ void uopz_get_property(zval *object, zval *member, zval *value) { /* {{{ */
 } /* }}} */
 
 void uopz_set_static_property(zend_class_entry *ce, zend_string *property, zval *value) { /* {{{ */
-	zend_class_entry *scope = EG(scope);
+	zend_class_entry *scope = uopz_get_scope(1);
 	zend_class_entry *seek = ce;
 	zend_property_info *info;
 	zval *prop;
 
 	do {
-		EG(scope) = seek;
+		uopz_set_scope(seek);
 
 		info = zend_get_property_info(seek, property, 1);
 	
@@ -213,13 +222,14 @@ void uopz_set_static_property(zend_class_entry *ce, zend_string *property, zval
 	} while (seek);
 
 	if (info && info != ZEND_WRONG_PROPERTY_INFO) {
-		EG(scope) = info->ce;
+		uopz_set_scope(info->ce);
 	} else {
-		EG(scope) = ce;
+		uopz_set_scope(ce);
 	}
 
-	prop = zend_std_get_static_property(EG(scope), property, 1);
-	EG(scope) = scope;
+	prop = zend_std_get_static_property(uopz_get_scope(0), property, 1);
+	
+	uopz_set_scope(scope);
 
 	if (!prop) {
 		return;
@@ -230,13 +240,13 @@ void uopz_set_static_property(zend_class_entry *ce, zend_string *property, zval
 } /* }}} */
 
 void uopz_get_static_property(zend_class_entry *ce, zend_string *property, zval *value) { /* {{{ */
-	zend_class_entry *scope = EG(scope);
+	zend_class_entry *scope = uopz_get_scope(1);
 	zend_class_entry *seek = ce;
 	zend_property_info *info;
 	zval *prop;
 
 	do {
-		EG(scope) = seek;
+		uopz_set_scope(seek);
 
 		info = zend_get_property_info(seek, property, 1);
 	
@@ -248,13 +258,14 @@ void uopz_get_static_property(zend_class_entry *ce, zend_string *property, zval
 	} while (seek);
 
 	if (info && info != ZEND_WRONG_PROPERTY_INFO) {
-		EG(scope) = info->ce;
+		uopz_set_scope(info->ce);
 	} else {
-		EG(scope) = ce;
+		uopz_set_scope(ce);
 	}
 
-	prop = zend_std_get_static_property(EG(scope), property, 1);
-	EG(scope) = scope;
+	prop = zend_std_get_static_property(uopz_get_scope(0), property, 1);
+	
+	uopz_set_scope(scope);
 
 	if (!prop) {
 		return;
diff --git a/src/handlers.c b/src/handlers.c
index 11b7f5f..98e9c37 100644
--- a/src/handlers.c
+++ b/src/handlers.c
@@ -344,6 +344,27 @@ static inline void uopz_run_hook(zend_function *function, zend_execute_data *exe
 	}
 } /* }}} */
 
+/* {{{ */
+static inline int php_uopz_leave_helper(zend_execute_data *execute_data) {
+	zend_execute_data *call = EX(call);
+	uint32_t info = ZEND_CALL_INFO(call);
+
+	if (info & ZEND_CALL_RELEASE_THIS) {
+		OBJ_RELEASE(Z_OBJ(call->This));
+	} else if (info & ZEND_CALL_CLOSURE) {
+		 OBJ_RELEASE((zend_object*)call->func->op_array.prototype);
+	}
+
+	EX(call) = call->prev_execute_data;
+
+	zend_vm_stack_free_args(call);
+	zend_vm_stack_free_call_frame(call);
+
+	EX(opline) = EX(opline) + 1;
+
+	return ZEND_USER_OPCODE_LEAVE;
+} /* }}} */
+
 int uopz_return_handler(UOPZ_OPCODE_HANDLER_ARGS) { /* {{{ */
 	zend_execute_data *call = EX(call);
 
@@ -366,26 +387,18 @@ int uopz_return_handler(UOPZ_OPCODE_HANDLER_ARGS) { /* {{{ */
 
 				uopz_execute_return(ureturn, call, return_value);
 
-				EX(call) = call->prev_execute_data;
-				zend_vm_stack_free_call_frame(call);
-				EX(opline) = opline + 1;
-
 				if (!RETURN_VALUE_USED(opline)) {
 					zval_ptr_dtor(&rv);
 				}
 
-				return ZEND_USER_OPCODE_CONTINUE;
+				return php_uopz_leave_helper(UOPZ_OPCODE_HANDLER_ARGS_PASSTHRU);
 			}
 
 			if (RETURN_VALUE_USED(opline)) {
 				ZVAL_COPY(return_value, &ureturn->value);
 			}
 
-			EX(call) = call->prev_execute_data;
-			zend_vm_stack_free_call_frame(call);
-			EX(opline) = opline + 1;
-
-			return ZEND_USER_OPCODE_CONTINUE;
+			return php_uopz_leave_helper(UOPZ_OPCODE_HANDLER_ARGS_PASSTHRU);
 		}
 	}