com php-src: Added EG(flags) - executor global flags EG_FLAGS_IN_SHUTDOWN - is set when PHP is i n shutdown state: Zend/zend.c Zend/zend_globals .h Zend/zend_objects_API.c main/main.c

[email protected] (Dmitry Stogov)
Newsgroups php.cvs
Message-ID <[email protected]>
Commit:    1b1399c95d1358b23f234c14e84dda9b5007904e
Author:    Jim Zubov <[email protected]>         Thu, 9 Feb 2017 12:40:33 -0500
Parents:   f9afc6aabc8af2da5874b32e11f9e4cca722c079
Branches:  master

Link:       http://git.php.net/?p=php-src.git;a=commitdiff;h=1b1399c95d1358b23f234c14e84dda9b5007904e

Log:
Added EG(flags) - executor global flags
EG_FLAGS_IN_SHUTDOWN - is set when PHP is in shutdown state

Changed paths:
  M  Zend/zend.c
  M  Zend/zend_globals.h
  M  Zend/zend_objects_API.c
  M  main/main.c


Diff:
diff --git a/Zend/zend.c b/Zend/zend.c
index bcbca56..c5236ba 100644
--- a/Zend/zend.c
+++ b/Zend/zend.c
@@ -648,6 +648,7 @@ static void executor_globals_ctor(zend_executor_globals *executor_globals) /* {{
 #ifdef ZEND_WIN32
 	zend_get_windows_version_info(&executor_globals->windows_version_info);
 #endif
+	executor_globals->flags = EG_FLAGS_INITIAL;
 }
 /* }}} */
 
diff --git a/Zend/zend_globals.h b/Zend/zend_globals.h
index 083875f..3440edf 100644
--- a/Zend/zend_globals.h
+++ b/Zend/zend_globals.h
@@ -214,6 +214,7 @@ struct _zend_executor_globals {
 
 	zend_bool active;
 	zend_bool valid_symbol_table;
+	zend_uchar flags;
 
 	zend_long assertions;
 
@@ -235,6 +236,9 @@ struct _zend_executor_globals {
 	void *reserved[ZEND_MAX_RESERVED_RESOURCES];
 };
 
+#define EG_FLAGS_INITIAL	0x00
+#define EG_FLAGS_IN_SHUTDOWN	0x01
+
 struct _zend_ini_scanner_globals {
 	zend_file_handle *yy_in;
 	zend_file_handle *yy_out;
diff --git a/Zend/zend_objects_API.c b/Zend/zend_objects_API.c
index b64d413..3aedba1 100644
--- a/Zend/zend_objects_API.c
+++ b/Zend/zend_objects_API.c
@@ -26,15 +26,12 @@
 #include "zend_API.h"
 #include "zend_objects_API.h"
 
-ZEND_TLS zend_objects_store_no_reuse; /* Would make more sense to make it a member of zend_objects_store, defining as a global to not break alignments */
-
 ZEND_API void zend_objects_store_init(zend_objects_store *objects, uint32_t init_size)
 {
 	objects->object_buckets = (zend_object **) emalloc(init_size * sizeof(zend_object*));
 	objects->top = 1; /* Skip 0 so that handles are true */
 	objects->size = init_size;
 	objects->free_list_head = -1;
-	zend_objects_store_no_reuse = 0;
 	memset(&objects->object_buckets[0], 0, sizeof(zend_object*));
 }
 
@@ -46,7 +43,6 @@ ZEND_API void zend_objects_store_destroy(zend_objects_store *objects)
 
 ZEND_API void zend_objects_store_call_destructors(zend_objects_store *objects)
 {
-	zend_objects_store_no_reuse = 1; /* new objects spawned by dtors will never reuse unused slots, so their own dtors will be called further down the loop */
 	if (objects->top > 1) {
 		uint32_t i;
 		for (i = 1; i < objects->top; i++) {
@@ -115,7 +111,10 @@ ZEND_API void zend_objects_store_put(zend_object *object)
 {
 	int handle;
 
-	if (!zend_objects_store_no_reuse && EG(objects_store).free_list_head != -1) {
+	/* When in shutdown sequesnce - do not reuse previously freed handles, to make sure
+	 * the dtors for newly created objects are called in zend_objects_store_call_destructors() loop
+	 */
+	if (!(EG(flags) & EG_FLAGS_IN_SHUTDOWN) && EG(objects_store).free_list_head != -1) {
 		handle = EG(objects_store).free_list_head;
 		EG(objects_store).free_list_head = GET_OBJ_BUCKET_NUMBER(EG(objects_store).object_buckets[handle]);
 	} else {
diff --git a/main/main.c b/main/main.c
index a8674a5..0d84763 100644
--- a/main/main.c
+++ b/main/main.c
@@ -1798,6 +1798,8 @@ void php_request_shutdown_for_hook(void *dummy)
 void php_request_shutdown(void *dummy)
 {
 	zend_bool report_memleaks;
+	
+	EG(flags) |= EG_FLAGS_IN_SHUTDOWN;
 
 	report_memleaks = PG(report_memleaks);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.