File tree Expand file tree Collapse file tree 4 files changed +37
-0
lines changed Expand file tree Collapse file tree 4 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -1283,6 +1283,13 @@ ZEND_API uint32_t zend_coroutine_add_switch_handler(
1283
1283
return 0 ;
1284
1284
}
1285
1285
1286
+ /* Check for duplicate handler */
1287
+ for (uint32_t i = 0 ; i < vector -> length ; i ++ ) {
1288
+ if (vector -> data [i ].handler == handler ) {
1289
+ return i ;
1290
+ }
1291
+ }
1292
+
1286
1293
/* Expand array if needed */
1287
1294
if (vector -> length == vector -> capacity ) {
1288
1295
vector -> capacity = vector -> capacity ? vector -> capacity * 2 : 4 ;
@@ -1384,6 +1391,13 @@ ZEND_API void zend_async_add_main_coroutine_start_handler(
1384
1391
{
1385
1392
zend_coroutine_switch_handlers_vector_t * vector = & global_main_coroutine_start_handlers ;
1386
1393
1394
+ /* Check for duplicate handler */
1395
+ for (uint32_t i = 0 ; i < vector -> length ; i ++ ) {
1396
+ if (vector -> data [i ].handler == handler ) {
1397
+ return ;
1398
+ }
1399
+ }
1400
+
1387
1401
/* Expand vector if needed */
1388
1402
if (vector -> length >= vector -> capacity ) {
1389
1403
uint32_t new_capacity = vector -> capacity ? vector -> capacity * 2 : 4 ;
Original file line number Diff line number Diff line change @@ -1423,5 +1423,11 @@ END_EXTERN_C()
1423
1423
1424
1424
/* Global Main Coroutine Switch Handlers API Macros */
1425
1425
#define ZEND_ASYNC_ADD_MAIN_COROUTINE_START_HANDLER (handler ) zend_async_add_main_coroutine_start_handler(handler)
1426
+ #define ZEND_ASYNC_ADD_SWITCH_HANDLER (handler ) \
1427
+ if (ZEND_ASYNC_CURRENT_COROUTINE) { \
1428
+ zend_coroutine_add_switch_handler(ZEND_ASYNC_CURRENT_COROUTINE, handler); \
1429
+ } else { \
1430
+ zend_async_add_main_coroutine_start_handler(handler); \
1431
+ }
1426
1432
1427
1433
#endif //ZEND_ASYNC_API_H
Original file line number Diff line number Diff line change @@ -285,6 +285,7 @@ static void shutdown_destructors_coroutine_dtor(zend_coroutine_t *coroutine)
285
285
286
286
if (shutdown_context -> coroutine == coroutine ) {
287
287
shutdown_context -> coroutine = NULL ;
288
+ shutdown_context -> is_started = false;
288
289
zend_error (E_CORE_ERROR , "Shutdown destructors coroutine was not finished property" );
289
290
EG (symbol_table ).pDestructor = zend_unclean_zval_ptr_dtor ;
290
291
shutdown_destructors ();
@@ -304,6 +305,12 @@ static bool shutdown_destructors_context_switch_handler(
304
305
return false;
305
306
}
306
307
308
+ zend_shutdown_context_t * shutdown_context = & EG (shutdown_context );
309
+
310
+ if (false == shutdown_context -> is_started ) {
311
+ return false;
312
+ }
313
+
307
314
zend_coroutine_t * shutdown_coroutine = ZEND_ASYNC_SPAWN_WITH_SCOPE_EX (ZEND_ASYNC_MAIN_SCOPE , 1 );
308
315
shutdown_coroutine -> internal_entry = shutdown_destructors_async ;
309
316
shutdown_coroutine -> extended_dispose = shutdown_destructors_coroutine_dtor ;
@@ -385,9 +392,12 @@ void shutdown_destructors_async(void) /* {{{ */
385
392
}
386
393
} zend_catch {
387
394
EG (symbol_table ).pDestructor = zend_unclean_zval_ptr_dtor ;
395
+ shutdown_context -> is_started = false;
388
396
shutdown_destructors ();
389
397
zend_bailout ();
390
398
} zend_end_try ();
399
+
400
+ shutdown_context -> is_started = false;
391
401
}
392
402
/* }}} */
393
403
#endif
Original file line number Diff line number Diff line change @@ -72,6 +72,7 @@ static void store_call_destructors_coroutine_dtor(zend_coroutine_t *coroutine)
72
72
73
73
if (shutdown_context -> coroutine == coroutine ) {
74
74
shutdown_context -> coroutine = NULL ;
75
+ shutdown_context -> is_started = false;
75
76
zend_error (E_CORE_ERROR , "Shutdown destructors coroutine was not finished property" );
76
77
shutdown_destructors ();
77
78
}
@@ -95,6 +96,12 @@ static bool store_call_destructors_context_switch_handler(
95
96
return false;
96
97
}
97
98
99
+ zend_shutdown_context_t * shutdown_context = & EG (shutdown_context );
100
+
101
+ if (false == shutdown_context -> is_started ) {
102
+ return false;
103
+ }
104
+
98
105
zend_coroutine_t * shutdown_coroutine = ZEND_ASYNC_SPAWN_WITH_SCOPE_EX (ZEND_ASYNC_MAIN_SCOPE , 1 );
99
106
shutdown_coroutine -> internal_entry = store_call_destructors_entry ;
100
107
shutdown_coroutine -> extended_dispose = store_call_destructors_coroutine_dtor ;
You can’t perform that action at this time.
0 commit comments