Skip to content

Commit 47e26cf

Browse files
committed
fix known interned strings init with TS per request
1 parent f3998d2 commit 47e26cf

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

Zend/zend.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,8 @@ static void compiler_globals_ctor(zend_compiler_globals *compiler_globals) /* {{
504504
compiler_globals->empty_string = zend_zts_interned_string_init("", sizeof("")-1);
505505

506506
memset(compiler_globals->one_char_string, 0, sizeof(compiler_globals->one_char_string));
507+
508+
zend_known_interned_strings_init(&compiler_globals->known_strings, &compiler_globals->known_strings_count);
507509
}
508510
/* }}} */
509511

@@ -530,6 +532,9 @@ static void compiler_globals_dtor(zend_compiler_globals *compiler_globals) /* {{
530532
compiler_globals->last_static_member = 0;
531533

532534
zend_zts_interned_string_free(&compiler_globals->empty_string);
535+
536+
compiler_globals->known_strings = NULL;
537+
compiler_globals->known_strings_count = 0;
533538
}
534539
/* }}} */
535540

Zend/zend_string.c

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,26 @@ static void _str_dtor(zval *zv)
4242
}
4343
#endif
4444

45+
/* Readonly, so assigned also per thread. */
46+
static const zend_string **known_interned_strings = NULL;
47+
static uint32_t known_interned_strings_count = 0;
48+
4549
ZEND_API uint32_t zend_intern_known_strings(const char **strings, uint32_t count)
4650
{
47-
uint32_t i, old_count = CG(known_strings_count);
51+
uint32_t i, old_count = known_interned_strings_count;
4852

49-
CG(known_strings) = perealloc(CG(known_strings), sizeof(char*) * (old_count + count), 1);
53+
known_interned_strings = perealloc(known_interned_strings, sizeof(char*) * (old_count + count), 1);
5054
for (i = 0; i < count; i++) {
5155
#ifndef ZTS
5256
zend_string *str = zend_string_init(strings[i], strlen(strings[i]), 1);
53-
CG(known_strings)[CG(known_strings_count) + i] =
57+
known_interned_strings[known_interned_strings_count + i] =
5458
zend_new_interned_string_int(str);
5559
#else
56-
CG(known_strings)[CG(known_strings_count) + i] =
60+
known_interned_strings[known_interned_strings_count + i] =
5761
zend_zts_interned_string_init(strings[i], strlen(strings[i]));
5862
#endif
5963
}
60-
CG(known_strings_count) = old_count + count;
64+
known_interned_strings_count = old_count + count;
6165
return old_count;
6266
}
6367

@@ -68,6 +72,12 @@ ZEND_KNOWN_STRINGS(_ZEND_STR_DSC)
6872
NULL
6973
};
7074

75+
void zend_known_interned_strings_init(zend_string ***strings, uint32_t *count)
76+
{
77+
*strings = known_interned_strings;
78+
*count = known_interned_strings_count;
79+
}
80+
7181
void zend_interned_strings_init(void)
7282
{
7383
#ifndef ZTS
@@ -90,9 +100,8 @@ void zend_interned_strings_init(void)
90100
memset(CG(one_char_string), 0, sizeof(CG(one_char_string)));
91101

92102
/* known strings */
93-
CG(known_strings) = NULL;
94-
CG(known_strings_count) = 0;
95103
zend_intern_known_strings(known_strings, (sizeof(known_strings) / sizeof(known_strings[0])) - 1);
104+
zend_known_interned_strings_init(&CG(known_strings), &CG(known_strings_count));
96105

97106
zend_new_interned_string = zend_new_interned_string_int;
98107
zend_interned_strings_snapshot = zend_interned_strings_snapshot_int;

Zend/zend_string.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ ZEND_API extern void (*zend_interned_strings_restore)(void);
3232
ZEND_API zend_ulong zend_hash_func(const char *str, size_t len);
3333
void zend_interned_strings_init(void);
3434
void zend_interned_strings_dtor(void);
35+
void zend_known_interned_strings_init(zend_string ***, uint32_t *);
3536

3637
END_EXTERN_C()
3738

0 commit comments

Comments
 (0)