[prev in list] [next in list] [prev in thread] [next in thread] 

List:       php-cvs
Subject:    [PHP-CVS] [php-src] master: Use common struct to store error information
From:       Nikita Popov <noreply () php ! net>
Date:       2021-04-29 9:52:20
Message-ID: DFbZ6Kj0lHELZAmm3Nm6rxCmza4wStYm5swBLUVYE () main ! php ! net
[Download RAW message or body]

Author: Nikita Popov (nikic)
Date: 2021-04-29T11:50:54+02:00

Commit: https://github.com/php/php-src/commit/e8e7c04a3a9d49e1936fa7f0e2f4fb26aa126cca
 Raw diff: https://github.com/php/php-src/commit/e8e7c04a3a9d49e1936fa7f0e2f4fb26aa126cca.diff


Use common struct to store error information

This is needed by both fibers and opcache (and GH-6903 also uses it),
so make it a common structure that can be used by any functionality
storing warnings/errors.

Changed paths:
  M  Zend/zend.h
  M  Zend/zend_fibers.c
  M  Zend/zend_fibers.h
  M  Zend/zend_globals.h
  M  ext/opcache/ZendAccelerator.c
  M  ext/opcache/ZendAccelerator.h
  M  ext/opcache/zend_file_cache.c
  M  ext/opcache/zend_persist.c
  M  ext/opcache/zend_persist_calc.c


Diff:

diff --git a/Zend/zend.h b/Zend/zend.h
index 47b84b299e1d..7d449c8f329b 100644
--- a/Zend/zend.h
+++ b/Zend/zend.h
@@ -378,6 +378,13 @@ typedef struct {
 	zend_class_entry       *exception;
 } zend_error_handling;
 
+typedef struct _zend_error_info {
+	int type;
+	uint32_t lineno;
+	zend_string *filename;
+	zend_string *message;
+} zend_error_info;
+
 ZEND_API void zend_save_error_handling(zend_error_handling *current);
 ZEND_API void zend_replace_error_handling(zend_error_handling_t error_handling, \
zend_class_entry *exception_class, zend_error_handling *current);  ZEND_API void \
                zend_restore_error_handling(zend_error_handling *saved);
diff --git a/Zend/zend_fibers.c b/Zend/zend_fibers.c
index 5548177979fc..65e3a4cf45cc 100644
--- a/Zend/zend_fibers.c
+++ b/Zend/zend_fibers.c
@@ -278,7 +278,7 @@ static void zend_fiber_switch_to(zend_fiber *fiber)
 			abort(); // This fiber should never be resumed.
 		}
 
-		zend_fiber_error *error = EG(fiber_error);
+		zend_error_info *error = EG(fiber_error);
 		zend_error_zstr_at(error->type, error->filename, error->lineno, error->message);
 	}
 }
@@ -288,7 +288,7 @@ ZEND_COLD void zend_error_suspend_fiber(
 {
 	ZEND_ASSERT(EG(current_fiber) && "Must be within an active fiber!");
 
-	zend_fiber_error *error = emalloc(sizeof(zend_fiber_error));
+	zend_error_info *error = emalloc(sizeof(zend_error_info));
 
 	error->type = orig_type;
 	error->filename = error_filename;
diff --git a/Zend/zend_fibers.h b/Zend/zend_fibers.h
index 5dc8877e1601..0e3ff01d7ea0 100644
--- a/Zend/zend_fibers.h
+++ b/Zend/zend_fibers.h
@@ -74,13 +74,6 @@ typedef struct _zend_fiber {
 	zval value;
 } zend_fiber;
 
-typedef struct _zend_fiber_error {
-	int type;
-	zend_string *filename;
-	uint32_t lineno;
-	zend_string *message;
-} zend_fiber_error;
-
 static const zend_uchar ZEND_FIBER_STATUS_INIT      = 0x0;
 static const zend_uchar ZEND_FIBER_STATUS_SUSPENDED = 0x1;
 static const zend_uchar ZEND_FIBER_STATUS_RUNNING   = 0x2;
diff --git a/Zend/zend_globals.h b/Zend/zend_globals.h
index cd1e7b57c04c..b94ef1de8d0f 100644
--- a/Zend/zend_globals.h
+++ b/Zend/zend_globals.h
@@ -62,7 +62,7 @@ END_EXTERN_C()
 typedef struct _zend_vm_stack *zend_vm_stack;
 typedef struct _zend_ini_entry zend_ini_entry;
 typedef struct _zend_fiber zend_fiber;
-typedef struct _zend_fiber_error zend_fiber_error;
+typedef struct _zend_error_info zend_error_info;
 
 
 struct _zend_compiler_globals {
@@ -258,7 +258,7 @@ struct _zend_executor_globals {
 	zend_long fiber_stack_size;
 
 	/* Pointer to fatal error that occurred in a fiber while switching to {main}. */
-	zend_fiber_error *fiber_error;
+	zend_error_info *fiber_error;
 
 	void *reserved[ZEND_MAX_RESERVED_RESOURCES];
 };
diff --git a/ext/opcache/ZendAccelerator.c b/ext/opcache/ZendAccelerator.c
index de1a75e5aa55..a55befbb91fb 100644
--- a/ext/opcache/ZendAccelerator.c
+++ b/ext/opcache/ZendAccelerator.c
@@ -1686,27 +1686,26 @@ static void zend_accel_set_auto_globals(int mask)
 	ZCG(auto_globals_mask) |= mask;
 }
 
-static void persistent_error_cb(int type, zend_string *error_filename, const \
uint32_t error_lineno, zend_string *message) { +static void persistent_error_cb(int \
type, zend_string *filename, const uint32_t lineno, zend_string *message) {  if \
                (ZCG(record_warnings)) {
-		zend_recorded_warning *warning = emalloc(sizeof(zend_recorded_warning));
+		zend_error_info *warning = emalloc(sizeof(zend_error_info));
 		warning->type = type;
-		warning->error_lineno = error_lineno;
-		warning->error_filename = zend_string_copy(error_filename);
-		warning->error_message = zend_string_copy(message);
+		warning->lineno = lineno;
+		warning->filename = zend_string_copy(filename);
+		warning->message = zend_string_copy(message);
 
 		ZCG(num_warnings)++;
-		ZCG(warnings) = erealloc(ZCG(warnings), sizeof(zend_recorded_warning) * \
ZCG(num_warnings)); +		ZCG(warnings) = erealloc(ZCG(warnings), \
sizeof(zend_error_info) * ZCG(num_warnings));  ZCG(warnings)[ZCG(num_warnings)-1] = \
warning;  }
-	accelerator_orig_zend_error_cb(type, error_filename, error_lineno, message);
+	accelerator_orig_zend_error_cb(type, filename, lineno, message);
 }
 
 static void replay_warnings(zend_persistent_script *script) {
 	for (uint32_t i = 0; i < script->num_warnings; i++) {
-		zend_recorded_warning *warning = script->warnings[i];
+		zend_error_info *warning = script->warnings[i];
 		accelerator_orig_zend_error_cb(
-			warning->type, warning->error_filename, warning->error_lineno,
-			warning->error_message);
+			warning->type, warning->filename, warning->lineno, warning->message);
 	}
 }
 
@@ -1716,9 +1715,9 @@ static void free_recorded_warnings() {
 	}
 
 	for (uint32_t i = 0; i < ZCG(num_warnings); i++) {
-		zend_recorded_warning *warning = ZCG(warnings)[i];
-		zend_string_release(warning->error_filename);
-		zend_string_release(warning->error_message);
+		zend_error_info *warning = ZCG(warnings)[i];
+		zend_string_release(warning->filename);
+		zend_string_release(warning->message);
 		efree(warning);
 	}
 	efree(ZCG(warnings));
diff --git a/ext/opcache/ZendAccelerator.h b/ext/opcache/ZendAccelerator.h
index 9dc431e533dc..b4cf3052812d 100644
--- a/ext/opcache/ZendAccelerator.h
+++ b/ext/opcache/ZendAccelerator.h
@@ -109,13 +109,6 @@ typedef enum _zend_accel_restart_reason {
 	ACCEL_RESTART_USER    /* restart scheduled by opcache_reset() */
 } zend_accel_restart_reason;
 
-typedef struct _zend_recorded_warning {
-	int type;
-	uint32_t error_lineno;
-	zend_string *error_filename;
-	zend_string *error_message;
-} zend_recorded_warning;
-
 typedef struct _zend_persistent_script {
 	zend_script    script;
 	zend_long      compiler_halt_offset;   /* position of __HALT_COMPILER or -1 */
@@ -125,7 +118,7 @@ typedef struct _zend_persistent_script {
 	bool      is_phar;
 	bool      empty;
 	uint32_t       num_warnings;
-	zend_recorded_warning **warnings;
+	zend_error_info **warnings;
 
 	void          *mem;                    /* shared memory area used by script \
structures */  size_t         size;                   /* size of used shared memory \
*/ @@ -227,9 +220,9 @@ typedef struct _zend_accel_globals {
 	void                   *mem;
 	zend_persistent_script *current_persistent_script;
 	/* Temporary storage for warnings before they are moved into persistent_script. */
-	bool               record_warnings;
+	bool                    record_warnings;
 	uint32_t                num_warnings;
-	zend_recorded_warning **warnings;
+	zend_error_info       **warnings;
 	/* cache to save hash lookup on the same INCLUDE opcode */
 	const zend_op          *cache_opline;
 	zend_persistent_script *cache_persistent_script;
diff --git a/ext/opcache/zend_file_cache.c b/ext/opcache/zend_file_cache.c
index f138163ae17e..826d777fa5f0 100644
--- a/ext/opcache/zend_file_cache.c
+++ b/ext/opcache/zend_file_cache.c
@@ -884,18 +884,18 @@ static void zend_file_cache_serialize_warnings(
 		zend_persistent_script *script, zend_file_cache_metainfo *info, void *buf)
 {
 	if (script->warnings) {
-		zend_recorded_warning **warnings;
+		zend_error_info **warnings;
 		SERIALIZE_PTR(script->warnings);
 		warnings = script->warnings;
 		UNSERIALIZE_PTR(warnings);
 
 		for (uint32_t i = 0; i < script->num_warnings; i++) {
-			zend_recorded_warning *warning;
+			zend_error_info *warning;
 			SERIALIZE_PTR(warnings[i]);
 			warning = warnings[i];
 			UNSERIALIZE_PTR(warning);
-			SERIALIZE_STR(warning->error_filename);
-			SERIALIZE_STR(warning->error_message);
+			SERIALIZE_STR(warning->filename);
+			SERIALIZE_STR(warning->message);
 		}
 	}
 }
@@ -1678,8 +1678,8 @@ static void \
zend_file_cache_unserialize_warnings(zend_persistent_script *script,  \
UNSERIALIZE_PTR(script->warnings);  for (uint32_t i = 0; i < script->num_warnings; \
i++) {  UNSERIALIZE_PTR(script->warnings[i]);
-			UNSERIALIZE_STR(script->warnings[i]->error_filename);
-			UNSERIALIZE_STR(script->warnings[i]->error_message);
+			UNSERIALIZE_STR(script->warnings[i]->filename);
+			UNSERIALIZE_STR(script->warnings[i]->message);
 		}
 	}
 }
diff --git a/ext/opcache/zend_persist.c b/ext/opcache/zend_persist.c
index 74764c45ca47..ecabcc2f21dc 100644
--- a/ext/opcache/zend_persist.c
+++ b/ext/opcache/zend_persist.c
@@ -1271,12 +1271,12 @@ static void zend_accel_persist_class_table(HashTable \
*class_table)  static void zend_persist_warnings(zend_persistent_script *script) {
 	if (script->warnings) {
 		script->warnings = zend_shared_memdup_free(
-			script->warnings, script->num_warnings * sizeof(zend_recorded_warning *));
+			script->warnings, script->num_warnings * sizeof(zend_error_info *));
 		for (uint32_t i = 0; i < script->num_warnings; i++) {
 			script->warnings[i] = zend_shared_memdup_free(
-				script->warnings[i], sizeof(zend_recorded_warning));
-			zend_accel_store_string(script->warnings[i]->error_filename);
-			zend_accel_store_string(script->warnings[i]->error_message);
+				script->warnings[i], sizeof(zend_error_info));
+			zend_accel_store_string(script->warnings[i]->filename);
+			zend_accel_store_string(script->warnings[i]->message);
 		}
 	}
 }
diff --git a/ext/opcache/zend_persist_calc.c b/ext/opcache/zend_persist_calc.c
index 313c3d2fa3d0..e3df7c99cf79 100644
--- a/ext/opcache/zend_persist_calc.c
+++ b/ext/opcache/zend_persist_calc.c
@@ -562,11 +562,11 @@ static void zend_accel_persist_class_table_calc(HashTable \
*class_table)  }
 
 static void zend_persist_warnings_calc(zend_persistent_script *script) {
-	ADD_SIZE(script->num_warnings * sizeof(zend_recorded_warning *));
+	ADD_SIZE(script->num_warnings * sizeof(zend_error_info *));
 	for (uint32_t i = 0; i < script->num_warnings; i++) {
-		ADD_SIZE(sizeof(zend_recorded_warning));
-		ADD_STRING(script->warnings[i]->error_filename);
-		ADD_STRING(script->warnings[i]->error_message);
+		ADD_SIZE(sizeof(zend_error_info));
+		ADD_STRING(script->warnings[i]->filename);
+		ADD_STRING(script->warnings[i]->message);
 	}
 }
 

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic