Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 246d294

Browse files
Revert "Remove name field from the zend_constant struct (#10954)"
This reverts commit f42992f.
1 parent 1c76da6 commit 246d294

File tree

15 files changed

+84
-67
lines changed

15 files changed

+84
-67
lines changed

‎Zend/zend_builtin_functions.c‎

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,8 @@ ZEND_FUNCTION(define)
517517
register_constant:
518518
/* non persistent */
519519
ZEND_CONSTANT_SET_FLAGS(&c, 0, PHP_USER_CONSTANT);
520-
if (zend_register_constant(name, &c) == SUCCESS) {
520+
c.name = zend_string_copy(name);
521+
if (zend_register_constant(&c) == SUCCESS) {
521522
RETURN_TRUE;
522523
} else {
523524
RETURN_FALSE;
@@ -1485,7 +1486,6 @@ ZEND_FUNCTION(get_defined_constants)
14851486
zend_constant *val;
14861487
int module_number;
14871488
zval *modules, const_val;
1488-
zend_string *const_name;
14891489
char **module_names;
14901490
zend_module_entry *module;
14911491
int i = 1;
@@ -1500,7 +1500,12 @@ ZEND_FUNCTION(get_defined_constants)
15001500
} ZEND_HASH_FOREACH_END();
15011501
module_names[i] = "user";
15021502

1503-
ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(EG(zend_constants), const_name, val) {
1503+
ZEND_HASH_MAP_FOREACH_PTR(EG(zend_constants), val) {
1504+
if (!val->name) {
1505+
/* skip special constants */
1506+
continue;
1507+
}
1508+
15041509
if (ZEND_CONSTANT_MODULE_NUMBER(val) == PHP_USER_CONSTANT) {
15051510
module_number = i;
15061511
} else if (ZEND_CONSTANT_MODULE_NUMBER(val) > i) {
@@ -1516,19 +1521,22 @@ ZEND_FUNCTION(get_defined_constants)
15161521
}
15171522

15181523
ZVAL_COPY_OR_DUP(&const_val, &val->value);
1519-
zend_hash_add_new(Z_ARRVAL(modules[module_number]), const_name, &const_val);
1524+
zend_hash_add_new(Z_ARRVAL(modules[module_number]), val->name, &const_val);
15201525
} ZEND_HASH_FOREACH_END();
15211526

15221527
efree(module_names);
15231528
efree(modules);
15241529
} else {
15251530
zend_constant *constant;
1526-
zend_string *const_name;
15271531
zval const_val;
15281532

1529-
ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(EG(zend_constants), const_name, constant) {
1533+
ZEND_HASH_MAP_FOREACH_PTR(EG(zend_constants), constant) {
1534+
if (!constant->name) {
1535+
/* skip special constants */
1536+
continue;
1537+
}
15301538
ZVAL_COPY_OR_DUP(&const_val, &constant->value);
1531-
zend_hash_add_new(Z_ARRVAL_P(return_value), const_name, &const_val);
1539+
zend_hash_add_new(Z_ARRVAL_P(return_value), constant->name, &const_val);
15321540
} ZEND_HASH_FOREACH_END();
15331541
}
15341542
}

‎Zend/zend_constants.c‎

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,15 @@ void free_zend_constant(zval *zv)
4343

4444
if (!(ZEND_CONSTANT_FLAGS(c) & CONST_PERSISTENT)) {
4545
zval_ptr_dtor_nogc(&c->value);
46+
if (c->name) {
47+
zend_string_release_ex(c->name, 0);
48+
}
4649
efree(c);
4750
} else {
4851
zval_internal_ptr_dtor(&c->value);
52+
if (c->name) {
53+
zend_string_release_ex(c->name, 1);
54+
}
4955
free(c);
5056
}
5157
}
@@ -61,6 +67,7 @@ static void copy_zend_constant(zval *zv)
6167
memcpy(Z_PTR_P(zv), c, sizeof(zend_constant));
6268

6369
c = Z_PTR_P(zv);
70+
c->name = zend_string_copy(c->name);
6471
if (Z_TYPE(c->value) == IS_STRING) {
6572
Z_STR(c->value) = zend_string_dup(Z_STR(c->value), 1);
6673
}
@@ -122,7 +129,8 @@ ZEND_API void zend_register_null_constant(const char *name, size_t name_len, int
122129

123130
ZVAL_NULL(&c.value);
124131
ZEND_CONSTANT_SET_FLAGS(&c, flags, module_number);
125-
zend_register_internal_constant(name, name_len, &c);
132+
c.name = zend_string_init_interned(name, name_len, flags & CONST_PERSISTENT);
133+
zend_register_constant(&c);
126134
}
127135

128136
ZEND_API void zend_register_bool_constant(const char *name, size_t name_len, bool bval, int flags, int module_number)
@@ -131,7 +139,8 @@ ZEND_API void zend_register_bool_constant(const char *name, size_t name_len, boo
131139

132140
ZVAL_BOOL(&c.value, bval);
133141
ZEND_CONSTANT_SET_FLAGS(&c, flags, module_number);
134-
zend_register_internal_constant(name, name_len, &c);
142+
c.name = zend_string_init_interned(name, name_len, flags & CONST_PERSISTENT);
143+
zend_register_constant(&c);
135144
}
136145

137146
ZEND_API void zend_register_long_constant(const char *name, size_t name_len, zend_long lval, int flags, int module_number)
@@ -140,7 +149,8 @@ ZEND_API void zend_register_long_constant(const char *name, size_t name_len, zen
140149

141150
ZVAL_LONG(&c.value, lval);
142151
ZEND_CONSTANT_SET_FLAGS(&c, flags, module_number);
143-
zend_register_internal_constant(name, name_len, &c);
152+
c.name = zend_string_init_interned(name, name_len, flags & CONST_PERSISTENT);
153+
zend_register_constant(&c);
144154
}
145155

146156

@@ -150,7 +160,8 @@ ZEND_API void zend_register_double_constant(const char *name, size_t name_len, d
150160

151161
ZVAL_DOUBLE(&c.value, dval);
152162
ZEND_CONSTANT_SET_FLAGS(&c, flags, module_number);
153-
zend_register_internal_constant(name, name_len, &c);
163+
c.name = zend_string_init_interned(name, name_len, flags & CONST_PERSISTENT);
164+
zend_register_constant(&c);
154165
}
155166

156167

@@ -160,7 +171,8 @@ ZEND_API void zend_register_stringl_constant(const char *name, size_t name_len,
160171

161172
ZVAL_STR(&c.value, zend_string_init_interned(strval, strlen, flags & CONST_PERSISTENT));
162173
ZEND_CONSTANT_SET_FLAGS(&c, flags, module_number);
163-
zend_register_internal_constant(name, name_len, &c);
174+
c.name = zend_string_init_interned(name, name_len, flags & CONST_PERSISTENT);
175+
zend_register_constant(&c);
164176
}
165177

166178

@@ -541,22 +553,25 @@ static void* zend_hash_add_constant(HashTable *ht, zend_string *key, zend_consta
541553
return ret;
542554
}
543555

544-
ZEND_API zend_result zend_register_constant(zend_string*name, zend_constant *c)
556+
ZEND_API zend_result zend_register_constant(zend_constant *c)
545557
{
546558
zend_string *lowercase_name = NULL;
559+
zend_string *name;
547560
zend_result ret = SUCCESS;
548561
bool persistent = (ZEND_CONSTANT_FLAGS(c) & CONST_PERSISTENT) != 0;
549562

550563
#if 0
551564
printf("Registering constant for module %d\n", c->module_number);
552565
#endif
553566

554-
const char *slash = strrchr(ZSTR_VAL(name), '\\');
567+
const char *slash = strrchr(ZSTR_VAL(c->name), '\\');
555568
if (slash) {
556-
lowercase_name = zend_string_init(ZSTR_VAL(name), ZSTR_LEN(name), persistent);
557-
zend_str_tolower(ZSTR_VAL(lowercase_name), slash - ZSTR_VAL(name));
569+
lowercase_name = zend_string_init(ZSTR_VAL(c->name), ZSTR_LEN(c->name), persistent);
570+
zend_str_tolower(ZSTR_VAL(lowercase_name), slash - ZSTR_VAL(c->name));
558571
lowercase_name = zend_new_interned_string(lowercase_name);
559572
name = lowercase_name;
573+
} else {
574+
name = c->name;
560575
}
561576

562577
/* Check if the user is trying to define any special constant */
@@ -565,6 +580,7 @@ ZEND_API zend_result zend_register_constant(zend_string *name, zend_constant *c)
565580
|| zend_hash_add_constant(EG(zend_constants), name, c) == NULL
566581
) {
567582
zend_error(E_WARNING, "Constant %s already defined", ZSTR_VAL(name));
583+
zend_string_release(c->name);
568584
if (!persistent) {
569585
zval_ptr_dtor_nogc(&c->value);
570586
}
@@ -575,13 +591,3 @@ ZEND_API zend_result zend_register_constant(zend_string *name, zend_constant *c)
575591
}
576592
return ret;
577593
}
578-
579-
ZEND_API zend_result zend_register_internal_constant(const char *name, size_t name_len, zend_constant *c) {
580-
zend_string *name_str = zend_string_init_interned(name, name_len, ZEND_CONSTANT_FLAGS(c) & CONST_PERSISTENT);
581-
582-
zend_result result = zend_register_constant(name_str, c);
583-
584-
zend_string_release(name_str);
585-
586-
return result;
587-
}

‎Zend/zend_constants.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
typedef struct _zend_constant {
3434
zval value;
35+
zend_string *name;
3536
} zend_constant;
3637

3738
#define ZEND_CONSTANT_FLAGS(c) \
@@ -83,8 +84,7 @@ ZEND_API void zend_register_long_constant(const char *name, size_t name_len, zen
8384
ZEND_API void zend_register_double_constant(const char *name, size_t name_len, double dval, int flags, int module_number);
8485
ZEND_API void zend_register_string_constant(const char *name, size_t name_len, const char *strval, int flags, int module_number);
8586
ZEND_API void zend_register_stringl_constant(const char *name, size_t name_len, const char *strval, size_t strlen, int flags, int module_number);
86-
ZEND_API zend_result zend_register_internal_constant(const char *name, size_t name_len, zend_constant *c);
87-
ZEND_API zend_result zend_register_constant(zend_string *name, zend_constant *c);
87+
ZEND_API zend_result zend_register_constant(zend_constant *c);
8888
#ifdef ZTS
8989
void zend_copy_constants(HashTable *target, HashTable *source);
9090
#endif

‎Zend/zend_execute.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5008,7 +5008,7 @@ static zend_always_inline zend_result _zend_quick_get_constant(
50085008
if (!check_defined_only) {
50095009
ZVAL_COPY_OR_DUP(EX_VAR(opline->result.var), &c->value);
50105010
if (ZEND_CONSTANT_FLAGS(c) & CONST_DEPRECATED) {
5011-
zend_error(E_DEPRECATED, "Constant %s is deprecated", ZSTR_VAL(Z_STR_P(key)));
5011+
zend_error(E_DEPRECATED, "Constant %s is deprecated", ZSTR_VAL(c->name));
50125012
return SUCCESS;
50135013
}
50145014
}

‎Zend/zend_execute_API.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,9 @@ ZEND_API void zend_shutdown_executor_values(bool fast_shutdown)
294294
break;
295295
}
296296
zval_ptr_dtor_nogc(&c->value);
297+
if (c->name) {
298+
zend_string_release_ex(c->name, 0);
299+
}
297300
efree(c);
298301
zend_string_release_ex(key, 0);
299302
} ZEND_HASH_MAP_FOREACH_END_DEL();

‎Zend/zend_vm_def.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8138,8 +8138,9 @@ ZEND_VM_HANDLER(143, ZEND_DECLARE_CONST, CONST, CONST)
81388138
}
81398139
/* non persistent, case sensitive */
81408140
ZEND_CONSTANT_SET_FLAGS(&c, 0, PHP_USER_CONSTANT);
8141+
c.name = zend_string_copy(Z_STR_P(name));
81418142

8142-
if (zend_register_constant(Z_STR_P(name), &c) == FAILURE) {
8143+
if (zend_register_constant(&c) == FAILURE) {
81438144
}
81448145

81458146
FREE_OP1();

‎Zend/zend_vm_execute.h‎

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎ext/com_dotnet/com_typeinfo.c‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ PHP_COM_DOTNET_API zend_result php_com_import_typelib(ITypeLib *TL, int mode, in
197197
if (pTKind == TKIND_ENUM) {
198198
ITypeLib_GetTypeInfo(TL, i, &TypeInfo);
199199
for (j = 0; ; j++) {
200-
zend_string *const_name, *name;
200+
zend_string *const_name;
201201

202202
if (FAILED(ITypeInfo_GetVarDesc(TypeInfo, j, &pVarDesc))) {
203203
break;
@@ -228,13 +228,12 @@ PHP_COM_DOTNET_API zend_result php_com_import_typelib(ITypeLib *TL, int mode, in
228228
ZVAL_LONG(&c.value, Z_LVAL(value));
229229
if (mode & CONST_PERSISTENT) {
230230
/* duplicate string in a persistent manner */
231-
name = zend_string_dup(const_name, /* persistent */ true);
231+
c.name = zend_string_dup(const_name, /* persistent */ true);
232232
zend_string_release_ex(const_name, /* persistent */ false);
233233
} else {
234-
name = const_name;
234+
c.name = const_name;
235235
}
236-
zend_register_constant(name, &c);
237-
zend_string_release(name);
236+
zend_register_constant(&c);
238237
}
239238
ITypeInfo_ReleaseVarDesc(TypeInfo, pVarDesc);
240239
}

‎ext/opcache/ZendAccelerator.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,9 @@ static void accel_copy_permanent_strings(zend_new_interned_string_func_t new_int
735735
p->key = new_interned_string(p->key);
736736
}
737737
c = (zend_constant*)Z_PTR(p->val);
738+
if (c->name) {
739+
c->name = new_interned_string(c->name);
740+
}
738741
if (Z_TYPE(c->value) == IS_STRING) {
739742
ZVAL_STR(&c->value, new_interned_string(Z_STR(c->value)));
740743
}

‎ext/opcache/jit/zend_jit_vm_helpers.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ static zend_always_inline zend_constant* _zend_quick_get_constant(
282282

283283
if (!check_defined_only) {
284284
if (ZEND_CONSTANT_FLAGS(c) & CONST_DEPRECATED) {
285-
zend_error(E_DEPRECATED, "Constant %s is deprecated", ZSTR_VAL(Z_STR_P(key)));
285+
zend_error(E_DEPRECATED, "Constant %s is deprecated", ZSTR_VAL(c->name));
286286
if (EG(exception)) {
287287
return NULL;
288288
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /