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(
12831283 return 0 ;
12841284 }
12851285
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+
12861293 /* Expand array if needed */
12871294 if (vector -> length == vector -> capacity ) {
12881295 vector -> capacity = vector -> capacity ? vector -> capacity * 2 : 4 ;
@@ -1384,6 +1391,13 @@ ZEND_API void zend_async_add_main_coroutine_start_handler(
13841391{
13851392 zend_coroutine_switch_handlers_vector_t * vector = & global_main_coroutine_start_handlers ;
13861393
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+
13871401 /* Expand vector if needed */
13881402 if (vector -> length >= vector -> capacity ) {
13891403 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()
14231423
14241424/* Global Main Coroutine Switch Handlers API Macros */
14251425#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+ }
14261432
14271433#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)
285285
286286 if (shutdown_context -> coroutine == coroutine ) {
287287 shutdown_context -> coroutine = NULL ;
288+ shutdown_context -> is_started = false;
288289 zend_error (E_CORE_ERROR , "Shutdown destructors coroutine was not finished property" );
289290 EG (symbol_table ).pDestructor = zend_unclean_zval_ptr_dtor ;
290291 shutdown_destructors ();
@@ -304,6 +305,12 @@ static bool shutdown_destructors_context_switch_handler(
304305 return false;
305306 }
306307
308+ zend_shutdown_context_t * shutdown_context = & EG (shutdown_context );
309+
310+ if (false == shutdown_context -> is_started ) {
311+ return false;
312+ }
313+
307314 zend_coroutine_t * shutdown_coroutine = ZEND_ASYNC_SPAWN_WITH_SCOPE_EX (ZEND_ASYNC_MAIN_SCOPE , 1 );
308315 shutdown_coroutine -> internal_entry = shutdown_destructors_async ;
309316 shutdown_coroutine -> extended_dispose = shutdown_destructors_coroutine_dtor ;
@@ -385,9 +392,12 @@ void shutdown_destructors_async(void) /* {{{ */
385392 }
386393 } zend_catch {
387394 EG (symbol_table ).pDestructor = zend_unclean_zval_ptr_dtor ;
395+ shutdown_context -> is_started = false;
388396 shutdown_destructors ();
389397 zend_bailout ();
390398 } zend_end_try ();
399+
400+ shutdown_context -> is_started = false;
391401}
392402/* }}} */
393403#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)
7272
7373 if (shutdown_context -> coroutine == coroutine ) {
7474 shutdown_context -> coroutine = NULL ;
75+ shutdown_context -> is_started = false;
7576 zend_error (E_CORE_ERROR , "Shutdown destructors coroutine was not finished property" );
7677 shutdown_destructors ();
7778 }
@@ -95,6 +96,12 @@ static bool store_call_destructors_context_switch_handler(
9596 return false;
9697 }
9798
99+ zend_shutdown_context_t * shutdown_context = & EG (shutdown_context );
100+
101+ if (false == shutdown_context -> is_started ) {
102+ return false;
103+ }
104+
98105 zend_coroutine_t * shutdown_coroutine = ZEND_ASYNC_SPAWN_WITH_SCOPE_EX (ZEND_ASYNC_MAIN_SCOPE , 1 );
99106 shutdown_coroutine -> internal_entry = store_call_destructors_entry ;
100107 shutdown_coroutine -> extended_dispose = store_call_destructors_coroutine_dtor ;
You can’t perform that action at this time.
0 commit comments