[php-src] master: main: convert sys_temp_dir global to zend_string* (#22812)

Gina Peter Banyard via GitHub <[email protected]> Sun, 19 Jul 2026 18:17:53 +0000
Newsgroups gmane.comp.php.cvs.general
Message-ID <[email protected]>
Author: Gina Peter Banyard (Girgias)
Committer: GitHub (web-flow)
Pusher: Girgias
Date: 2026-07-19T19:17:50+01:00

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

main: convert sys_temp_dir global to zend_string* (#22812)

This removes a strlen() call when we already know the length of the string

Changed paths:
  M  main/main.c
  M  main/php_globals.h
  M  main/php_open_temporary_file.c


Diff:

diff --git a/main/main.c b/main/main.c
index 4348ec410920..e29770a909eb 100644
--- a/main/main.c
+++ b/main/main.c
@@ -839,7 +839,7 @@ PHP_INI_BEGIN()
 	STD_PHP_INI_ENTRY("error_log",				NULL,			PHP_INI_ALL,		OnUpdateErrorLog,				error_log,				php_core_globals,	core_globals)
 	STD_PHP_INI_ENTRY("error_log_mode",			"0644",			PHP_INI_ALL,		OnUpdateLong,					error_log_mode,			php_core_globals,	core_globals)
 	STD_PHP_INI_ENTRY("extension_dir",			PHP_EXTENSION_DIR,		PHP_INI_SYSTEM,		OnUpdateStringUnempty,	extension_dir,			php_core_globals,	core_globals)
-	STD_PHP_INI_ENTRY("sys_temp_dir",			NULL,		PHP_INI_SYSTEM,		OnUpdateStringUnempty,	sys_temp_dir,			php_core_globals,	core_globals)
+	STD_PHP_INI_ENTRY("sys_temp_dir",			NULL,		PHP_INI_SYSTEM,		OnUpdateStrNotEmpty,	sys_temp_dir,			php_core_globals,	core_globals)
 	STD_PHP_INI_ENTRY("include_path",			PHP_INCLUDE_PATH,		PHP_INI_ALL,		OnUpdateStringUnempty,	include_path,			php_core_globals,	core_globals)
 	PHP_INI_ENTRY("max_execution_time",			"30",		PHP_INI_ALL,			OnUpdateTimeout)
 	STD_PHP_INI_ENTRY("open_basedir",			NULL,		PHP_INI_ALL,		OnUpdateBaseDir,			open_basedir,			php_core_globals,	core_globals)
diff --git a/main/php_globals.h b/main/php_globals.h
index 8a032e9edb13..0bab9fc95c14 100644
--- a/main/php_globals.h
+++ b/main/php_globals.h
@@ -83,7 +83,7 @@ struct _php_core_globals {
 	bool open_basedir_modified;
 	char *extension_dir;
 	char *php_binary;
-	char *sys_temp_dir;
+	zend_string *sys_temp_dir;
 
 	char *upload_tmp_dir;
 	zend_long upload_max_filesize;
diff --git a/main/php_open_temporary_file.c b/main/php_open_temporary_file.c
index ffc1c754d9e6..7a33fa3ce192 100644
--- a/main/php_open_temporary_file.c
+++ b/main/php_open_temporary_file.c
@@ -240,14 +240,14 @@ PHPAPI const char* php_get_temporary_directory(void)
 
 	/* Is there a temporary directory "sys_temp_dir" in .ini defined? */
 	{
-		char *sys_temp_dir = PG(sys_temp_dir);
+		const zend_string *sys_temp_dir = PG(sys_temp_dir);
 		if (sys_temp_dir) {
-			size_t len = strlen(sys_temp_dir);
-			if (len >= 2 && sys_temp_dir[len - 1] == DEFAULT_SLASH) {
-				PG(php_sys_temp_dir) = estrndup(sys_temp_dir, len - 1);
+			size_t len = ZSTR_LEN(sys_temp_dir);
+			if (len >= 2 && ZSTR_VAL(sys_temp_dir)[len - 1] == DEFAULT_SLASH) {
+				PG(php_sys_temp_dir) = estrndup(ZSTR_VAL(sys_temp_dir), len - 1);
 				return PG(php_sys_temp_dir);
-			} else if (len >= 1 && sys_temp_dir[len - 1] != DEFAULT_SLASH) {
-				PG(php_sys_temp_dir) = estrndup(sys_temp_dir, len);
+			} else if (len >= 1 && ZSTR_VAL(sys_temp_dir)[len - 1] != DEFAULT_SLASH) {
+				PG(php_sys_temp_dir) = estrndup(ZSTR_VAL(sys_temp_dir), len);
 				return PG(php_sys_temp_dir);
 			}
 		}