Skip to content

Commit 4bd22cf

Browse files
committed
Improved zend_string API (Francois Laupretre)
Squashed commit of the following: commit d96eab8 Author: Francois Laupretre <[email protected]> Date: Fri Jun 26 01:23:31 2015 +0200 Use the new 'ZSTR' macros in the rest of the code. Does not change anything to the generated code (thanks to compat macros) but cleaner. commit b352643 Author: Francois Laupretre <[email protected]> Date: Thu Jun 25 13:45:06 2015 +0200 Improve zend_string API Add missing methods
1 parent 667e9bd commit 4bd22cf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+292
-260
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ PHP NEWS
33
09 Jul 2015, PHP 7.0.0 Beta 1
44

55
- Core:
6+
. Improved zend_string API (Francois Laupretre)
67
. Fixed bug #69768 (escapeshell*() doesn't cater to !). (cmb)
78
. Fixed bug #69955 (Segfault when trying to combine [] and assign-op on
89
ArrayAccess object). (Laruence)

Zend/zend_API.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1644,7 +1644,7 @@ ZEND_API int array_set_zval_key(HashTable *ht, zval *key, zval *value) /* {{{ */
16441644
result = zend_symtable_update(ht, Z_STR_P(key), value);
16451645
break;
16461646
case IS_NULL:
1647-
result = zend_symtable_update(ht, STR_EMPTY_ALLOC(), value);
1647+
result = zend_symtable_update(ht, ZSTR_EMPTY_ALLOC(), value);
16481648
break;
16491649
case IS_RESOURCE:
16501650
zend_error(E_NOTICE, "Resource ID#" ZEND_LONG_FMT " used as offset, casting to integer (%pd)", Z_RES_HANDLE_P(key), Z_RES_HANDLE_P(key));
@@ -2833,7 +2833,7 @@ static int zend_is_callable_check_class(zend_string *name, zend_fcall_info_cache
28332833
zend_string *lcname;
28342834
ALLOCA_FLAG(use_heap);
28352835

2836-
STR_ALLOCA_ALLOC(lcname, name_len, use_heap);
2836+
ZSTR_ALLOCA_ALLOC(lcname, name_len, use_heap);
28372837
zend_str_tolower_copy(lcname->val, name->val, name_len);
28382838

28392839
*strict_class = 0;
@@ -2904,7 +2904,7 @@ static int zend_is_callable_check_class(zend_string *name, zend_fcall_info_cache
29042904
} else {
29052905
if (error) zend_spprintf(error, 0, "class '%.*s' not found", name_len, name->val);
29062906
}
2907-
STR_ALLOCA_FREE(lcname, use_heap);
2907+
ZSTR_ALLOCA_FREE(lcname, use_heap);
29082908
return ret;
29092909
}
29102910
/* }}} */
@@ -2934,31 +2934,31 @@ static int zend_is_callable_check_func(int check_flags, zval *callable, zend_fca
29342934

29352935
/* Skip leading \ */
29362936
if (UNEXPECTED(Z_STRVAL_P(callable)[0] == '\\')) {
2937-
STR_ALLOCA_INIT(lmname, Z_STRVAL_P(callable) + 1, Z_STRLEN_P(callable) - 1, use_heap);
2937+
ZSTR_ALLOCA_INIT(lmname, Z_STRVAL_P(callable) + 1, Z_STRLEN_P(callable) - 1, use_heap);
29382938
} else {
29392939
lmname = Z_STR_P(callable);
29402940
}
29412941
/* Check if function with given name exists.
29422942
* This may be a compound name that includes namespace name */
29432943
if (EXPECTED((fcc->function_handler = zend_hash_find_ptr(EG(function_table), lmname)) != NULL)) {
29442944
if (lmname != Z_STR_P(callable)) {
2945-
STR_ALLOCA_FREE(lmname, use_heap);
2945+
ZSTR_ALLOCA_FREE(lmname, use_heap);
29462946
}
29472947
return 1;
29482948
} else {
29492949
if (lmname == Z_STR_P(callable)) {
2950-
STR_ALLOCA_INIT(lmname, Z_STRVAL_P(callable), Z_STRLEN_P(callable), use_heap);
2950+
ZSTR_ALLOCA_INIT(lmname, Z_STRVAL_P(callable), Z_STRLEN_P(callable), use_heap);
29512951
} else {
29522952
zend_string_forget_hash_val(lmname);
29532953
}
29542954
zend_str_tolower(lmname->val, lmname->len);
29552955
if ((fcc->function_handler = zend_hash_find_ptr(EG(function_table), lmname)) != NULL) {
2956-
STR_ALLOCA_FREE(lmname, use_heap);
2956+
ZSTR_ALLOCA_FREE(lmname, use_heap);
29572957
return 1;
29582958
}
29592959
}
29602960
if (lmname != Z_STR_P(callable)) {
2961-
STR_ALLOCA_FREE(lmname, use_heap);
2961+
ZSTR_ALLOCA_FREE(lmname, use_heap);
29622962
}
29632963
}
29642964

Zend/zend_API.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ END_EXTERN_C()
573573
} while (0)
574574

575575
#define ZVAL_EMPTY_STRING(z) do { \
576-
ZVAL_INTERNED_STR(z, STR_EMPTY_ALLOC()); \
576+
ZVAL_INTERNED_STR(z, ZSTR_EMPTY_ALLOC()); \
577577
} while (0)
578578

579579
#define ZVAL_PSTRINGL(z, s, l) do { \
@@ -1126,16 +1126,16 @@ static zend_always_inline int zend_parse_arg_string(zval *arg, char **dest, size
11261126
*dest = NULL;
11271127
*dest_len = 0;
11281128
} else {
1129-
*dest = str->val;
1130-
*dest_len = str->len;
1129+
*dest = ZSTR_VAL(str);
1130+
*dest_len = ZSTR_LEN(str);
11311131
}
11321132
return 1;
11331133
}
11341134

11351135
static zend_always_inline int zend_parse_arg_path_str(zval *arg, zend_string **dest, int check_null)
11361136
{
11371137
if (!zend_parse_arg_str(arg, dest, check_null) ||
1138-
(*dest && UNEXPECTED(CHECK_NULL_PATH((*dest)->val, (*dest)->len)))) {
1138+
(*dest && UNEXPECTED(CHECK_NULL_PATH(ZSTR_VAL(*dest), ZSTR_LEN(*dest))))) {
11391139
return 0;
11401140
}
11411141
return 1;
@@ -1152,8 +1152,8 @@ static zend_always_inline int zend_parse_arg_path(zval *arg, char **dest, size_t
11521152
*dest = NULL;
11531153
*dest_len = 0;
11541154
} else {
1155-
*dest = str->val;
1156-
*dest_len = str->len;
1155+
*dest = ZSTR_VAL(str);
1156+
*dest_len = ZSTR_LEN(str);
11571157
}
11581158
return 1;
11591159
}

Zend/zend_ast.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ static int zend_ast_add_array_element(zval *result, zval *offset, zval *expr)
188188
zval_dtor(offset);
189189
break;
190190
case IS_NULL:
191-
zend_symtable_update(Z_ARRVAL_P(result), STR_EMPTY_ALLOC(), expr);
191+
zend_symtable_update(Z_ARRVAL_P(result), ZSTR_EMPTY_ALLOC(), expr);
192192
break;
193193
case IS_LONG:
194194
zend_hash_index_update(Z_ARRVAL_P(result), Z_LVAL_P(offset), expr);

Zend/zend_compile.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ static inline void zend_insert_literal(zend_op_array *op_array, zval *zv, int li
413413
if (Z_TYPE_P(zv) == IS_STRING || Z_TYPE_P(zv) == IS_CONSTANT) {
414414
zend_string_hash_val(Z_STR_P(zv));
415415
Z_STR_P(zv) = zend_new_interned_string(Z_STR_P(zv));
416-
if (IS_INTERNED(Z_STR_P(zv))) {
416+
if (ZSTR_IS_INTERNED(Z_STR_P(zv))) {
417417
Z_TYPE_FLAGS_P(zv) &= ~ (IS_TYPE_REFCOUNTED | IS_TYPE_COPYABLE);
418418
}
419419
}
@@ -725,10 +725,10 @@ void *zend_hash_find_ptr_lc(HashTable *ht, const char *str, size_t len) {
725725
zend_string *lcname;
726726
ALLOCA_FLAG(use_heap);
727727

728-
STR_ALLOCA_ALLOC(lcname, len, use_heap);
728+
ZSTR_ALLOCA_ALLOC(lcname, len, use_heap);
729729
zend_str_tolower_copy(lcname->val, str, len);
730730
result = zend_hash_find_ptr(ht, lcname);
731-
STR_ALLOCA_FREE(lcname, use_heap);
731+
ZSTR_ALLOCA_FREE(lcname, use_heap);
732732

733733
return result;
734734
}
@@ -5717,7 +5717,7 @@ static zend_bool zend_try_ct_eval_array(zval *result, zend_ast *ast) /* {{{ */
57175717
zend_hash_index_update(Z_ARRVAL_P(result), 1, value);
57185718
break;
57195719
case IS_NULL:
5720-
zend_hash_update(Z_ARRVAL_P(result), STR_EMPTY_ALLOC(), value);
5720+
zend_hash_update(Z_ARRVAL_P(result), ZSTR_EMPTY_ALLOC(), value);
57215721
break;
57225722
default:
57235723
zend_error_noreturn(E_COMPILE_ERROR, "Illegal offset type");

Zend/zend_exceptions.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ ZEND_METHOD(exception, __toString)
678678

679679
DEFAULT_0_PARAMS;
680680

681-
str = STR_EMPTY_ALLOC();
681+
str = ZSTR_EMPTY_ALLOC();
682682

683683
exception = getThis();
684684
ZVAL_STRINGL(&fname, "gettraceasstring", sizeof("gettraceasstring")-1);

Zend/zend_execute.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -573,9 +573,9 @@ ZEND_API char * zend_verify_internal_arg_class_kind(const zend_internal_arg_info
573573
zend_string *key;
574574
ALLOCA_FLAG(use_heap);
575575

576-
STR_ALLOCA_INIT(key, cur_arg_info->class_name, strlen(cur_arg_info->class_name), use_heap);
576+
ZSTR_ALLOCA_INIT(key, cur_arg_info->class_name, strlen(cur_arg_info->class_name), use_heap);
577577
*pce = zend_fetch_class(key, (ZEND_FETCH_CLASS_AUTO | ZEND_FETCH_CLASS_NO_AUTOLOAD));
578-
STR_ALLOCA_FREE(key, use_heap);
578+
ZSTR_ALLOCA_FREE(key, use_heap);
579579

580580
*class_name = (*pce) ? (*pce)->name->val : (char*)cur_arg_info->class_name;
581581
if (*pce && (*pce)->ce_flags & ZEND_ACC_INTERFACE) {
@@ -1568,7 +1568,7 @@ static zend_always_inline zval *zend_fetch_dimension_address_inner(HashTable *ht
15681568
} else {
15691569
switch (Z_TYPE_P(dim)) {
15701570
case IS_NULL:
1571-
offset_key = STR_EMPTY_ALLOC();
1571+
offset_key = ZSTR_EMPTY_ALLOC();
15721572
goto str_index;
15731573
case IS_DOUBLE:
15741574
hval = zend_dval_to_lval(Z_DVAL_P(dim));

Zend/zend_hash.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ static zend_always_inline zval *_zend_hash_add_or_update_i(HashTable *ht, zend_s
524524
zend_hash_iterators_update(ht, HT_INVALID_IDX, idx);
525525
p = ht->arData + idx;
526526
p->key = key;
527-
if (!IS_INTERNED(key)) {
527+
if (!ZSTR_IS_INTERNED(key)) {
528528
zend_string_addref(key);
529529
ht->u.flags &= ~HASH_FLAG_STATIC_KEYS;
530530
zend_string_hash_val(key);

Zend/zend_hash.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -894,7 +894,7 @@ static zend_always_inline zval *_zend_hash_append(HashTable *ht, zend_string *ke
894894
Bucket *p = ht->arData + idx;
895895

896896
ZVAL_COPY_VALUE(&p->val, zv);
897-
if (!IS_INTERNED(key)) {
897+
if (!ZSTR_IS_INTERNED(key)) {
898898
ht->u.flags &= ~HASH_FLAG_STATIC_KEYS;
899899
zend_string_addref(key);
900900
zend_string_hash_val(key);
@@ -916,7 +916,7 @@ static zend_always_inline zval *_zend_hash_append_ptr(HashTable *ht, zend_string
916916
Bucket *p = ht->arData + idx;
917917

918918
ZVAL_PTR(&p->val, ptr);
919-
if (!IS_INTERNED(key)) {
919+
if (!ZSTR_IS_INTERNED(key)) {
920920
ht->u.flags &= ~HASH_FLAG_STATIC_KEYS;
921921
zend_string_addref(key);
922922
zend_string_hash_val(key);
@@ -938,7 +938,7 @@ static zend_always_inline void _zend_hash_append_ind(HashTable *ht, zend_string
938938
Bucket *p = ht->arData + idx;
939939

940940
ZVAL_INDIRECT(&p->val, ptr);
941-
if (!IS_INTERNED(key)) {
941+
if (!ZSTR_IS_INTERNED(key)) {
942942
ht->u.flags &= ~HASH_FLAG_STATIC_KEYS;
943943
zend_string_addref(key);
944944
zend_string_hash_val(key);

Zend/zend_language_parser.y

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,7 +1014,7 @@ exit_expr:
10141014

10151015
backticks_expr:
10161016
/* empty */
1017-
{ $$ = zend_ast_create_zval_from_str(STR_EMPTY_ALLOC()); }
1017+
{ $$ = zend_ast_create_zval_from_str(ZSTR_EMPTY_ALLOC()); }
10181018
| T_ENCAPSED_AND_WHITESPACE { $$ = $1; }
10191019
| encaps_list { $$ = $1; }
10201020
;
@@ -1045,7 +1045,7 @@ scalar:
10451045
| T_CLASS_C { $$ = zend_ast_create_ex(ZEND_AST_MAGIC_CONST, T_CLASS_C); }
10461046
| T_START_HEREDOC T_ENCAPSED_AND_WHITESPACE T_END_HEREDOC { $$ = $2; }
10471047
| T_START_HEREDOC T_END_HEREDOC
1048-
{ $$ = zend_ast_create_zval_from_str(STR_EMPTY_ALLOC()); }
1048+
{ $$ = zend_ast_create_zval_from_str(ZSTR_EMPTY_ALLOC()); }
10491049
| '"' encaps_list '"' { $$ = $2; }
10501050
| T_START_HEREDOC encaps_list T_END_HEREDOC { $$ = $2; }
10511051
| dereferencable_scalar { $$ = $1; }

0 commit comments

Comments
 (0)