38
38
((int)((ZEND_MM_ALIGNED_SIZE(sizeof(coro_task)) + ZEND_MM_ALIGNED_SIZE(sizeof(zval)) - 1) / ZEND_MM_ALIGNED_SIZE(sizeof(zval))))
39
39
#define SWCC (x ) sw_current_context->x
40
40
coro_global COROG ;
41
- zval * allocated_return_value_ptr = NULL ;
42
41
43
42
static void (* orig_interrupt_function )(zend_execute_data * execute_data );
44
43
static void sw_interrupt_function (zend_execute_data * execute_data );
@@ -118,9 +117,6 @@ int coro_init(TSRMLS_D)
118
117
fake_frame .return_value = NULL ;
119
118
fake_frame .prev_execute_data = NULL ;
120
119
121
- COROG .origin_vm_stack = EG (vm_stack );
122
- COROG .origin_vm_stack_top = EG (vm_stack_top );
123
- COROG .origin_vm_stack_end = EG (vm_stack_end );
124
120
COROG .origin_ex = & fake_frame ;
125
121
126
122
while (1 )
@@ -164,9 +160,7 @@ int coro_init(TSRMLS_D)
164
160
{
165
161
COROG .stack_size = DEFAULT_STACK_SIZE ;
166
162
}
167
- zval * retval ;
168
- SW_ALLOC_INIT_ZVAL (retval );
169
- allocated_return_value_ptr = retval ;
163
+
170
164
COROG .require = 0 ;
171
165
COROG .active = 1 ;
172
166
SwooleWG .coro_timeout_list = swLinkedList_new (1 , NULL );
@@ -175,10 +169,7 @@ int coro_init(TSRMLS_D)
175
169
176
170
void coro_destroy (TSRMLS_D )
177
171
{
178
- if (allocated_return_value_ptr )
179
- {
180
- efree (allocated_return_value_ptr );
181
- }
172
+
182
173
}
183
174
184
175
static int sw_terminate_opcode_handler (zend_execute_data * execute_data )
@@ -220,6 +211,11 @@ int sw_coro_create(zend_fcall_info_cache *fci_cache, zval **argv, int argc, zval
220
211
swWarn ("exceed max number of coro %d" , COROG .coro_num );
221
212
return CORO_LIMIT ;
222
213
}
214
+
215
+ COROG .origin_vm_stack = EG (vm_stack );
216
+ COROG .origin_vm_stack_top = EG (vm_stack_top );
217
+ COROG .origin_vm_stack_end = EG (vm_stack_end );
218
+
223
219
zend_function * func ;
224
220
uint32_t i ;
225
221
@@ -240,7 +236,7 @@ int sw_coro_create(zend_fcall_info_cache *fci_cache, zval **argv, int argc, zval
240
236
coro_frame -> return_value = NULL ;
241
237
coro_frame -> prev_execute_data = & dummy_frame ;
242
238
243
- call = zend_vm_stack_push_call_frame (ZEND_CALL_NESTED_FUNCTION | ZEND_CALL_DYNAMIC , func , argc ,
239
+ call = zend_vm_stack_push_call_frame (ZEND_CALL_TOP_FUNCTION | ZEND_CALL_ALLOCATED , func , argc ,
244
240
fci_cache -> called_scope , fci_cache -> object );
245
241
#if PHP_MINOR_VERSION < 1
246
242
EG (scope ) = func -> common .scope ;
@@ -253,7 +249,7 @@ int sw_coro_create(zend_fcall_info_cache *fci_cache, zval **argv, int argc, zval
253
249
ZVAL_COPY (target , argv [i ]);
254
250
}
255
251
call -> symbol_table = NULL ;
256
- allocated_return_value_ptr = retval ;
252
+
257
253
EG (current_execute_data ) = NULL ;
258
254
if (UNEXPECTED (func -> op_array .fn_flags & ZEND_ACC_CLOSURE ))
259
255
{
@@ -278,7 +274,7 @@ int sw_coro_create(zend_fcall_info_cache *fci_cache, zval **argv, int argc, zval
278
274
COROG .root_coro -> post_callback_params = params ;
279
275
COROG .root_coro -> has_yield_parent = 0 ;
280
276
COROG .require = 1 ;
281
- if (COROG .current_coro )
277
+ if (COROG .call_stack_size > 1 && COROG . current_coro )
282
278
{
283
279
COROG .root_coro -> origin_coro = COROG .current_coro ;
284
280
}
@@ -326,7 +322,6 @@ sw_inline php_context *sw_coro_save(zval *return_value, php_context *sw_current_
326
322
SWCC (current_vm_stack_top ) = EG (vm_stack_top );
327
323
SWCC (current_vm_stack_end ) = EG (vm_stack_end );
328
324
SWCC (current_task ) = COROG .current_coro ;
329
- SWCC (allocated_return_value_ptr ) = allocated_return_value_ptr ;
330
325
return sw_current_context ;
331
326
}
332
327
@@ -344,7 +339,6 @@ int sw_coro_resume(php_context *sw_current_context, zval *retval, zval *coro_ret
344
339
#if PHP_MINOR_VERSION < 1
345
340
EG (scope ) = EG (current_execute_data )-> func -> op_array .scope ;
346
341
#endif
347
- allocated_return_value_ptr = SWCC (allocated_return_value_ptr );
348
342
EG (current_execute_data )-> opline -- ;
349
343
if (EG (current_execute_data )-> opline -> result_type != IS_UNUSED )
350
344
{
@@ -369,7 +363,6 @@ int sw_coro_resume_parent(php_context *sw_current_context, zval *retval, zval *c
369
363
EG (vm_stack_end ) = SWCC (current_vm_stack_end );
370
364
EG (current_execute_data ) = SWCC (current_execute_data );
371
365
COROG .current_coro = SWCC (current_task );
372
- allocated_return_value_ptr = SWCC (allocated_return_value_ptr );
373
366
return CORO_END ;
374
367
}
375
368
@@ -419,9 +412,8 @@ void sw_interrupt_function(zend_execute_data *execute_data)
419
412
else
420
413
{
421
414
EG (current_execute_data ) = COROG .origin_ex ;
422
- if (current_coro && current_coro -> origin_coro && current_coro -> has_yield_parent == 0 )
415
+ if (current_coro && current_coro -> origin_coro && COROG . call_stack_size > 1 && current_coro -> has_yield_parent == 0 )
423
416
{
424
- current_coro -> has_yield_parent = 1 ;
425
417
EG (vm_stack ) = current_coro -> origin_coro -> stack ;
426
418
EG (vm_stack_top ) = current_coro -> origin_coro -> vm_stack_top ;
427
419
EG (vm_stack_end ) = current_coro -> origin_coro -> vm_stack_end ;
@@ -432,6 +424,7 @@ void sw_interrupt_function(zend_execute_data *execute_data)
432
424
EG (vm_stack_top ) = COROG .origin_vm_stack_top ;
433
425
EG (vm_stack_end ) = COROG .origin_vm_stack_end ;
434
426
}
427
+ current_coro -> has_yield_parent = 1 ;
435
428
}
436
429
COROG .require = 1 ;
437
430
COROG .next_coro = NULL ;
0 commit comments