Skip to content

Commit 3a8f0b1

Browse files
committed
Merge branch 'master' of https://git.php.net/repository/php-src
* 'master' of https://git.php.net/repository/php-src: Fix two warnings Provide more macros for handling of interned strings Make use of Z_*VAL and ZVAL_* in language scanner Make consistent use of Z_*VAL macros in compiler
2 parents e75171e + 91a9569 commit 3a8f0b1

14 files changed

+750
-1151
lines changed

Zend/zend.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -670,8 +670,8 @@ END_EXTERN_C()
670670

671671
/* FIXME: Check if we can save if (ptr) too */
672672

673-
#define STR_FREE(ptr) if (ptr && !IS_INTERNED(ptr)) { efree(ptr); }
674-
#define STR_FREE_REL(ptr) if (ptr && !IS_INTERNED(ptr)) { efree_rel(ptr); }
673+
#define STR_FREE(ptr) if (ptr) { str_efree(ptr); }
674+
#define STR_FREE_REL(ptr) if (ptr) { str_efree_rel(ptr); }
675675

676676
#define STR_EMPTY_ALLOC() estrndup("", sizeof("")-1)
677677

Zend/zend_API.c

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2029,14 +2029,15 @@ ZEND_API int zend_register_functions(zend_class_entry *scope, const zend_functio
20292029
const zend_function_entry *ptr = functions;
20302030
zend_function function, *reg_function;
20312031
zend_internal_function *internal_function = (zend_internal_function *)&function;
2032-
int count=0, unload=0, result=0;
2032+
int count=0, unload=0;
20332033
HashTable *target_function_table = function_table;
20342034
int error_type;
20352035
zend_function *ctor = NULL, *dtor = NULL, *clone = NULL, *__get = NULL, *__set = NULL, *__unset = NULL, *__isset = NULL, *__call = NULL, *__callstatic = NULL, *__tostring = NULL;
20362036
const char *lowercase_name;
20372037
int fname_len;
20382038
const char *lc_class_name = NULL;
20392039
int class_name_len = 0;
2040+
zend_ulong hash;
20402041

20412042
if (type==MODULE_PERSISTENT) {
20422043
error_type = E_CORE_WARNING;
@@ -2135,12 +2136,8 @@ ZEND_API int zend_register_functions(zend_class_entry *scope, const zend_functio
21352136
}
21362137
fname_len = strlen(ptr->fname);
21372138
lowercase_name = zend_new_interned_string(zend_str_tolower_dup(ptr->fname, fname_len), fname_len + 1, 1 TSRMLS_CC);
2138-
if (IS_INTERNED(lowercase_name)) {
2139-
result = zend_hash_quick_add(target_function_table, lowercase_name, fname_len+1, INTERNED_HASH(lowercase_name), &function, sizeof(zend_function), (void**)&reg_function);
2140-
} else {
2141-
result = zend_hash_add(target_function_table, lowercase_name, fname_len+1, &function, sizeof(zend_function), (void**)&reg_function);
2142-
}
2143-
if (result == FAILURE) {
2139+
hash = str_hash(lowercase_name, fname_len);
2140+
if (zend_hash_quick_add(target_function_table, lowercase_name, fname_len+1, hash, &function, sizeof(zend_function), (void**)&reg_function) == FAILURE) {
21442141
unload=1;
21452142
str_efree(lowercase_name);
21462143
break;
@@ -2493,6 +2490,7 @@ static zend_class_entry *do_register_internal_class(zend_class_entry *orig_class
24932490
{
24942491
zend_class_entry *class_entry = malloc(sizeof(zend_class_entry));
24952492
char *lowercase_name = emalloc(orig_class_entry->name_length + 1);
2493+
zend_ulong hash;
24962494
*class_entry = *orig_class_entry;
24972495

24982496
class_entry->type = ZEND_INTERNAL_CLASS;
@@ -2506,11 +2504,8 @@ static zend_class_entry *do_register_internal_class(zend_class_entry *orig_class
25062504

25072505
zend_str_tolower_copy(lowercase_name, orig_class_entry->name, class_entry->name_length);
25082506
lowercase_name = (char*)zend_new_interned_string(lowercase_name, class_entry->name_length + 1, 1 TSRMLS_CC);
2509-
if (IS_INTERNED(lowercase_name)) {
2510-
zend_hash_quick_update(CG(class_table), lowercase_name, class_entry->name_length+1, INTERNED_HASH(lowercase_name), &class_entry, sizeof(zend_class_entry *), NULL);
2511-
} else {
2512-
zend_hash_update(CG(class_table), lowercase_name, class_entry->name_length+1, &class_entry, sizeof(zend_class_entry *), NULL);
2513-
}
2507+
hash = str_hash(lowercase_name, class_entry->name_length);
2508+
zend_hash_quick_update(CG(class_table), lowercase_name, class_entry->name_length+1, hash, &class_entry, sizeof(zend_class_entry *), NULL);
25142509
str_efree(lowercase_name);
25152510
return class_entry;
25162511
}

Zend/zend_builtin_functions.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,7 @@ ZEND_FUNCTION(define)
706706
zval_ptr_dtor(&val_free);
707707
}
708708
c.flags = case_sensitive; /* non persistent */
709-
c.name = IS_INTERNED(name) ? name : zend_strndup(name, name_len);
709+
c.name = str_strndup(name, name_len);
710710
if(c.name == NULL) {
711711
RETURN_FALSE;
712712
}
@@ -1388,12 +1388,11 @@ ZEND_FUNCTION(function_exists)
13881388
Creates an alias for user defined class */
13891389
ZEND_FUNCTION(class_alias)
13901390
{
1391-
char *class_name, *lc_name, *alias_name;
1391+
char *class_name, *alias_name;
13921392
zend_class_entry **ce;
13931393
int class_name_len, alias_name_len;
13941394
int found;
13951395
zend_bool autoload = 1;
1396-
ALLOCA_FLAG(use_heap)
13971396

13981397
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|b", &class_name, &class_name_len, &alias_name, &alias_name_len, &autoload) == FAILURE) {
13991398
return;

Zend/zend_compile.c

Lines changed: 80 additions & 100 deletions
Large diffs are not rendered by default.

Zend/zend_constants.c

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@ void free_zend_constant(zend_constant *c)
3838

3939
void copy_zend_constant(zend_constant *c)
4040
{
41-
if (!IS_INTERNED(c->name)) {
42-
c->name = zend_strndup(c->name, c->name_len - 1);
43-
}
41+
c->name = str_strndup(c->name, c->name_len - 1);
4442
if (!(c->flags & CONST_PERSISTENT)) {
4543
zval_copy_ctor(&c->value);
4644
}
@@ -474,7 +472,7 @@ ZEND_API int zend_register_constant(zend_constant *c TSRMLS_DC)
474472
char *lowercase_name = NULL;
475473
char *name;
476474
int ret = SUCCESS;
477-
ulong chash = 0;
475+
ulong chash;
478476

479477
#if 0
480478
printf("Registering constant for module %d\n", c->module_number);
@@ -486,23 +484,18 @@ ZEND_API int zend_register_constant(zend_constant *c TSRMLS_DC)
486484
zend_str_tolower(lowercase_name, c->name_len-1);
487485
lowercase_name = (char*)zend_new_interned_string(lowercase_name, c->name_len, 1 TSRMLS_CC);
488486
name = lowercase_name;
489-
chash = IS_INTERNED(lowercase_name) ? INTERNED_HASH(lowercase_name) : 0;
490487
} else {
491488
char *slash = strrchr(c->name, '\\');
492-
if(slash) {
489+
if (slash) {
493490
lowercase_name = estrndup(c->name, c->name_len-1);
494491
zend_str_tolower(lowercase_name, slash-c->name);
495492
lowercase_name = (char*)zend_new_interned_string(lowercase_name, c->name_len, 1 TSRMLS_CC);
496493
name = lowercase_name;
497-
498-
chash = IS_INTERNED(lowercase_name) ? INTERNED_HASH(lowercase_name) : 0;
499494
} else {
500495
name = c->name;
501496
}
502497
}
503-
if (chash == 0) {
504-
chash = zend_hash_func(name, c->name_len);
505-
}
498+
chash = str_hash(name, c->name_len-1);
506499

507500
/* Check if the user is trying to define the internal pseudo constant name __COMPILER_HALT_OFFSET__ */
508501
if ((c->name_len == sizeof("__COMPILER_HALT_OFFSET__")
@@ -521,8 +514,8 @@ ZEND_API int zend_register_constant(zend_constant *c TSRMLS_DC)
521514
}
522515
ret = FAILURE;
523516
}
524-
if (lowercase_name && !IS_INTERNED(lowercase_name)) {
525-
efree(lowercase_name);
517+
if (lowercase_name) {
518+
str_efree(lowercase_name);
526519
}
527520
return ret;
528521
}

Zend/zend_execute.c

Lines changed: 17 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -767,32 +767,21 @@ static inline void zend_assign_to_object(zval **retval, zval **object_ptr, zval
767767

768768
static inline int zend_assign_to_string_offset(const temp_variable *T, const zval *value, int value_type TSRMLS_DC)
769769
{
770-
if (Z_TYPE_P(T->str_offset.str) == IS_STRING) {
771-
772-
if (((int)T->str_offset.offset < 0)) {
773-
zend_error(E_WARNING, "Illegal string offset: %d", T->str_offset.offset);
770+
zval *str = T->str_offset.str;
771+
zend_uint offset = T->str_offset.offset;
772+
if (Z_TYPE_P(str) == IS_STRING) {
773+
if ((int)offset < 0) {
774+
zend_error(E_WARNING, "Illegal string offset: %d", offset);
774775
return 0;
775776
}
776777

777-
if (T->str_offset.offset >= Z_STRLEN_P(T->str_offset.str)) {
778-
if (IS_INTERNED(Z_STRVAL_P(T->str_offset.str))) {
779-
char *tmp = (char *) emalloc(T->str_offset.offset+1+1);
780-
781-
memcpy(tmp, Z_STRVAL_P(T->str_offset.str), Z_STRLEN_P(T->str_offset.str)+1);
782-
Z_STRVAL_P(T->str_offset.str) = tmp;
783-
} else {
784-
Z_STRVAL_P(T->str_offset.str) = (char *) erealloc(Z_STRVAL_P(T->str_offset.str), T->str_offset.offset+1+1);
785-
}
786-
memset(Z_STRVAL_P(T->str_offset.str) + Z_STRLEN_P(T->str_offset.str),
787-
' ',
788-
T->str_offset.offset - Z_STRLEN_P(T->str_offset.str));
789-
Z_STRVAL_P(T->str_offset.str)[T->str_offset.offset+1] = 0;
790-
Z_STRLEN_P(T->str_offset.str) = T->str_offset.offset+1;
791-
} else if (IS_INTERNED(Z_STRVAL_P(T->str_offset.str))) {
792-
char *tmp = (char *) emalloc(Z_STRLEN_P(T->str_offset.str) + 1);
793-
794-
memcpy(tmp, Z_STRVAL_P(T->str_offset.str), Z_STRLEN_P(T->str_offset.str) + 1);
795-
Z_STRVAL_P(T->str_offset.str) = tmp;
778+
if (offset >= Z_STRLEN_P(str)) {
779+
Z_STRVAL_P(str) = str_erealloc(Z_STRVAL_P(str), offset+1+1);
780+
memset(Z_STRVAL_P(str) + Z_STRLEN_P(str), ' ', offset - Z_STRLEN_P(str));
781+
Z_STRVAL_P(str)[offset+1] = 0;
782+
Z_STRLEN_P(str) = offset+1;
783+
} else if (IS_INTERNED(Z_STRVAL_P(str))) {
784+
Z_STRVAL_P(str) = estrndup(Z_STRVAL_P(str), Z_STRLEN_P(str));
796785
}
797786

798787
if (Z_TYPE_P(value) != IS_STRING) {
@@ -803,15 +792,15 @@ static inline int zend_assign_to_string_offset(const temp_variable *T, const zva
803792
zval_copy_ctor(&tmp);
804793
}
805794
convert_to_string(&tmp);
806-
Z_STRVAL_P(T->str_offset.str)[T->str_offset.offset] = Z_STRVAL(tmp)[0];
807-
STR_FREE(Z_STRVAL(tmp));
795+
Z_STRVAL_P(str)[offset] = Z_STRVAL(tmp)[0];
796+
str_efree(Z_STRVAL(tmp));
808797
} else {
809-
Z_STRVAL_P(T->str_offset.str)[T->str_offset.offset] = Z_STRVAL_P(value)[0];
798+
Z_STRVAL_P(str)[offset] = Z_STRVAL_P(value)[0];
810799
if (value_type == IS_TMP_VAR) {
811800
/* we can safely free final_value here
812801
* because separation is done only
813802
* in case value_type == IS_VAR */
814-
STR_FREE(Z_STRVAL_P(value));
803+
str_efree(Z_STRVAL_P(value));
815804
}
816805
}
817806
/*
@@ -1024,11 +1013,7 @@ static inline zval **zend_fetch_dimension_address_inner(HashTable *ht, const zva
10241013
hval = Z_HASH_P(dim);
10251014
} else {
10261015
ZEND_HANDLE_NUMERIC_EX(offset_key, offset_key_length+1, hval, goto num_index);
1027-
if (IS_INTERNED(offset_key)) {
1028-
hval = INTERNED_HASH(offset_key);
1029-
} else {
1030-
hval = zend_hash_func(offset_key, offset_key_length+1);
1031-
}
1016+
hval = str_hash(offset_key, offset_key_length);
10321017
}
10331018
fetch_string_dim:
10341019
if (zend_hash_quick_find(ht, offset_key, offset_key_length+1, hval, (void **) &retval) == FAILURE) {

Zend/zend_execute_API.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -533,13 +533,13 @@ ZEND_API int zval_update_constant_ex(zval **pp, void *arg, zend_class_entry *sco
533533
if (fix_save) {
534534
save--;
535535
}
536-
if (inline_change && !IS_INTERNED(save)) {
537-
efree(save);
536+
if (inline_change) {
537+
str_efree(save);
538538
}
539539
save = NULL;
540540
}
541-
if (inline_change && save && save != actual && !IS_INTERNED(save)) {
542-
efree(save);
541+
if (inline_change && save && save != actual) {
542+
str_efree(save);
543543
}
544544
zend_error(E_NOTICE, "Use of undefined constant %s - assumed '%s'", actual, actual);
545545
p->type = IS_STRING;
@@ -551,7 +551,7 @@ ZEND_API int zval_update_constant_ex(zval **pp, void *arg, zend_class_entry *sco
551551
}
552552
} else {
553553
if (inline_change) {
554-
STR_FREE(Z_STRVAL_P(p));
554+
str_efree(Z_STRVAL_P(p));
555555
}
556556
*p = const_value;
557557
}

0 commit comments

Comments
 (0)