diff options
| author | Anatol Belski <ab@php.net> | 2016-06-02 17:55:48 +0200 |
|---|---|---|
| committer | Anatol Belski <ab@php.net> | 2016-06-02 17:55:48 +0200 |
| commit | 47e26cf9dbe9c9650f2d33280845b8794db03910 (patch) | |
| tree | 010dbbc70e65acc51ae8bf9f07c7a963e361ae78 | |
| parent | f3998d2303d571d815eb0e4b3cc04917369396c8 (diff) | |
| download | php-git-47e26cf9dbe9c9650f2d33280845b8794db03910.tar.gz | |
fix known interned strings init with TS per request
| -rw-r--r-- | Zend/zend.c | 5 | ||||
| -rw-r--r-- | Zend/zend_string.c | 23 | ||||
| -rw-r--r-- | Zend/zend_string.h | 1 |
3 files changed, 22 insertions, 7 deletions
diff --git a/Zend/zend.c b/Zend/zend.c index c4b91ce31a..f2fa4b12d9 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 4866b64949..3da95bd674 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 05bf4ef7b8..8a1ac6f506 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() |
