Skip to content

Commit 1f56a2f

Browse files
Deduplicate zend_constant filename setting in zend_register_constant()
1 parent 7d05765 commit 1f56a2f

File tree

7 files changed

+7
-38
lines changed

7 files changed

+7
-38
lines changed

Zend/zend_builtin_functions.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -549,13 +549,6 @@ ZEND_FUNCTION(define)
549549
/* non persistent */
550550
ZEND_CONSTANT_SET_FLAGS(&c, 0, PHP_USER_CONSTANT);
551551
c.name = zend_string_copy(name);
552-
553-
zend_string *filename = zend_get_executed_filename_ex();
554-
if (filename == NULL) {
555-
c.filename = NULL;
556-
} else {
557-
c.filename = zend_string_copy(filename);
558-
}
559552
if (zend_register_constant(&c) == SUCCESS) {
560553
RETURN_TRUE;
561554
} else {

Zend/zend_constants.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ ZEND_API void zend_register_null_constant(const char *name, size_t name_len, int
132132
ZVAL_NULL(&c.value);
133133
ZEND_CONSTANT_SET_FLAGS(&c, flags, module_number);
134134
c.name = zend_string_init_interned(name, name_len, flags & CONST_PERSISTENT);
135-
c.filename = NULL;
136135
zend_register_constant(&c);
137136
}
138137

@@ -143,7 +142,6 @@ ZEND_API void zend_register_bool_constant(const char *name, size_t name_len, boo
143142
ZVAL_BOOL(&c.value, bval);
144143
ZEND_CONSTANT_SET_FLAGS(&c, flags, module_number);
145144
c.name = zend_string_init_interned(name, name_len, flags & CONST_PERSISTENT);
146-
c.filename = NULL;
147145
zend_register_constant(&c);
148146
}
149147

@@ -154,7 +152,6 @@ ZEND_API void zend_register_long_constant(const char *name, size_t name_len, zen
154152
ZVAL_LONG(&c.value, lval);
155153
ZEND_CONSTANT_SET_FLAGS(&c, flags, module_number);
156154
c.name = zend_string_init_interned(name, name_len, flags & CONST_PERSISTENT);
157-
c.filename = NULL;
158155
zend_register_constant(&c);
159156
}
160157

@@ -166,7 +163,6 @@ ZEND_API void zend_register_double_constant(const char *name, size_t name_len, d
166163
ZVAL_DOUBLE(&c.value, dval);
167164
ZEND_CONSTANT_SET_FLAGS(&c, flags, module_number);
168165
c.name = zend_string_init_interned(name, name_len, flags & CONST_PERSISTENT);
169-
c.filename = NULL;
170166
zend_register_constant(&c);
171167
}
172168

@@ -178,7 +174,6 @@ ZEND_API void zend_register_stringl_constant(const char *name, size_t name_len,
178174
ZVAL_STR(&c.value, zend_string_init_interned(strval, strlen, flags & CONST_PERSISTENT));
179175
ZEND_CONSTANT_SET_FLAGS(&c, flags, module_number);
180176
c.name = zend_string_init_interned(name, name_len, flags & CONST_PERSISTENT);
181-
c.filename = NULL;
182177
zend_register_constant(&c);
183178
}
184179

@@ -509,6 +504,13 @@ ZEND_API zend_result zend_register_constant(zend_constant *c)
509504
name = c->name;
510505
}
511506

507+
zend_string *filename = zend_get_executed_filename_ex();
508+
if (filename == NULL) {
509+
c->filename = NULL;
510+
} else {
511+
c->filename = zend_string_copy(filename);
512+
}
513+
512514
/* Check if the user is trying to define any special constant */
513515
if (zend_string_equals_literal(name, "__COMPILER_HALT_OFFSET__")
514516
|| (!persistent && zend_get_special_const(ZSTR_VAL(name), ZSTR_LEN(name)))

Zend/zend_vm_def.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8232,13 +8232,6 @@ ZEND_VM_HANDLER(143, ZEND_DECLARE_CONST, CONST, CONST)
82328232
ZEND_CONSTANT_SET_FLAGS(&c, 0, PHP_USER_CONSTANT);
82338233
c.name = zend_string_copy(Z_STR_P(name));
82348234

8235-
zend_string *filename = zend_get_executed_filename_ex();
8236-
if (filename == NULL) {
8237-
c.filename = NULL;
8238-
} else {
8239-
c.filename = zend_string_copy(filename);
8240-
}
8241-
82428235
if (zend_register_constant(&c) == FAILURE) {
82438236
}
82448237

Zend/zend_vm_execute.h

Lines changed: 0 additions & 7 deletions
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: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -233,12 +233,6 @@ PHP_COM_DOTNET_API zend_result php_com_import_typelib(ITypeLib *TL, int mode, in
233233
} else {
234234
c.name = const_name;
235235
}
236-
zend_string *filename = zend_get_executed_filename_ex();
237-
if (filename == NULL) {
238-
c.filename = NULL;
239-
} else {
240-
c.filename = zend_string_copy(filename);
241-
}
242236
zend_register_constant(&c);
243237
}
244238
ITypeInfo_ReleaseVarDesc(TypeInfo, pVarDesc);

sapi/cli/php_cli.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -546,17 +546,14 @@ static void cli_register_file_handles(void)
546546

547547
Z_CONSTANT_FLAGS(ic.value) = 0;
548548
ic.name = zend_string_init_interned("STDIN", sizeof("STDIN")-1, 0);
549-
ic.filename = NULL;
550549
zend_register_constant(&ic);
551550

552551
Z_CONSTANT_FLAGS(oc.value) = 0;
553552
oc.name = zend_string_init_interned("STDOUT", sizeof("STDOUT")-1, 0);
554-
oc.filename = NULL;
555553
zend_register_constant(&oc);
556554

557555
Z_CONSTANT_FLAGS(ec.value) = 0;
558556
ec.name = zend_string_init_interned("STDERR", sizeof("STDERR")-1, 0);
559-
ec.filename = NULL;
560557
zend_register_constant(&ec);
561558
}
562559

sapi/phpdbg/phpdbg.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -914,21 +914,18 @@ void phpdbg_register_file_handles(void) /* {{{ */
914914
ic.value = zin;
915915
Z_CONSTANT_FLAGS(ic.value) = 0;
916916
ic.name = zend_string_init(ZEND_STRL("STDIN"), 0);
917-
ic.filename = NULL;
918917
zend_hash_del(EG(zend_constants), ic.name);
919918
zend_register_constant(&ic);
920919

921920
oc.value = zout;
922921
Z_CONSTANT_FLAGS(oc.value) = 0;
923922
oc.name = zend_string_init(ZEND_STRL("STDOUT"), 0);
924-
oc.filename = NULL;
925923
zend_hash_del(EG(zend_constants), oc.name);
926924
zend_register_constant(&oc);
927925

928926
ec.value = zerr;
929927
Z_CONSTANT_FLAGS(ec.value) = 0;
930928
ec.name = zend_string_init(ZEND_STRL("STDERR"), 0);
931-
ec.filename = NULL;
932929
zend_hash_del(EG(zend_constants), ec.name);
933930
zend_register_constant(&ec);
934931
}

0 commit comments

Comments
 (0)