com php-src: fix known interned strings init with TS per request: Zend/zend.c Zend/zend_string.c Zend/zend_string.h
| From: | Anatol Belski | Date: | Thu, 02 Jun 2016 15:55:48 +0000 |
| Subject: | com php-src: fix known interned strings init with TS per request: Zend/zend.c Zend/zend_string.c Zend/zend_string.h | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-92281@lists.php.net to get a copy of this message | ||
Commit: 47e26cf9dbe9c9650f2d33280845b8794db03910
Author: Anatol Belski <ab@php.net> Thu, 2 Jun 2016 17:55:48 +0200
Parents: f3998d2303d571d815eb0e4b3cc04917369396c8
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=47e26cf9dbe9c9650f2d33280845b8794db03910
Log:
fix known interned strings init with TS per request
Changed paths:
M Zend/zend.c
M Zend/zend_string.c
M Zend/zend_string.h
Diff:
diff --git a/Zend/zend.c b/Zend/zend..c
index c4b91ce..f2fa4b1 100644
--- a/Zend/zend.c
+++ b/Zend/zend.c
@@ -504,6 +504,8 @@ static void compiler_globals_ctor(zend_compiler_globals *compiler_globals) /* {{
compiler_globals->empty_string = zend_zts_interned_string_init("",
sizeof("")-1);
memset(compiler_globals->one_char_string, 0, sizeof(compiler_globals->one_char_string));
+
+ zend_known_interned_strings_init(&compiler_globals->known_strings,
&compiler_globals->known_strings_count);
}
/* }}} */
@@ -530,6 +532,9 @@ static void compiler_globals_dtor(zend_compiler_globals *compiler_globals) /* {{
compiler_globals->last_static_member = 0;
zend_zts_interned_string_free(&compiler_globals->empty_string);
+
+ compiler_globals->known_strings = NULL;
+ compiler_globals->known_strings_count = 0;
}
/* }}} */
diff --git a/Zend/zend_string.c b/Zend/zend_string.c
index 4866b64..3da95bd 100644
--- a/Zend/zend_string.c
+++ b/Zend/zend_string.c
@@ -42,22 +42,26 @@ static void _str_dtor(zval *zv)
}
#endif
+/* Readonly, so assigned also per thread. */
+static const zend_string **known_interned_strings = NULL;
+static uint32_t known_interned_strings_count = 0;
+
ZEND_API uint32_t zend_intern_known_strings(const char **strings, uint32_t count)
{
- uint32_t i, old_count = CG(known_strings_count);
+ uint32_t i, old_count = known_interned_strings_count;
- CG(known_strings) = perealloc(CG(known_strings), sizeof(char*) * (old_count + count), 1);
+ known_interned_strings = perealloc(known_interned_strings, sizeof(char*) * (old_count + count),
1);
for (i = 0; i < count; i++) {
#ifndef ZTS
zend_string *str = zend_string_init(strings[i], strlen(strings[i]), 1);
- CG(known_strings)[CG(known_strings_count) + i] =
+ known_interned_strings[known_interned_strings_count + i] =
zend_new_interned_string_int(str);
#else
- CG(known_strings)[CG(known_strings_count) + i] =
+ known_interned_strings[known_interned_strings_count + i] =
zend_zts_interned_string_init(strings[i], strlen(strings[i]));
#endif
}
- CG(known_strings_count) = old_count + count;
+ known_interned_strings_count = old_count + count;
return old_count;
}
@@ -68,6 +72,12 @@ ZEND_KNOWN_STRINGS(_ZEND_STR_DSC)
NULL
};
+void zend_known_interned_strings_init(zend_string ***strings, uint32_t *count)
+{
+ *strings = known_interned_strings;
+ *count = known_interned_strings_count;
+}
+
void zend_interned_strings_init(void)
{
#ifndef ZTS
@@ -90,9 +100,8 @@ void zend_interned_strings_init(void)
memset(CG(one_char_string), 0, sizeof(CG(one_char_string)));
/* known strings */
- CG(known_strings) = NULL;
- CG(known_strings_count) = 0;
zend_intern_known_strings(known_strings, (sizeof(known_strings) / sizeof(known_strings[0])) - 1);
+ zend_known_interned_strings_init(&CG(known_strings), &CG(known_strings_count));
zend_new_interned_string = zend_new_interned_string_int;
zend_interned_strings_snapshot = zend_interned_strings_snapshot_int;
diff --git a/Zend/zend_string.h b/Zend/zend_string.h
index 05bf4ef..8a1ac6f 100644
--- a/Zend/zend_string.h
+++ b/Zend/zend_string.h
@@ -32,6 +32,7 @@ ZEND_API extern void (*zend_interned_strings_restore)(void);
ZEND_API zend_ulong zend_hash_func(const char *str, size_t len);
void zend_interned_strings_init(void);
void zend_interned_strings_dtor(void);
+void zend_known_interned_strings_init(zend_string ***, uint32_t *);
END_EXTERN_C()