Skip to content

Improved zend_string API #1367

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions Zend/zend_API.c
Original file line number Diff line number Diff line change
Expand Up @@ -1653,7 +1653,7 @@ ZEND_API int array_set_zval_key(HashTable *ht, zval *key, zval *value) /* {{{ */
result = zend_symtable_update(ht, Z_STR_P(key), value);
break;
case IS_NULL:
result = zend_symtable_update(ht, STR_EMPTY_ALLOC(), value);
result = zend_symtable_update(ht, ZSTR_EMPTY_ALLOC(), value);
break;
case IS_RESOURCE:
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));
Expand Down Expand Up @@ -2842,7 +2842,7 @@ static int zend_is_callable_check_class(zend_string *name, zend_fcall_info_cache
zend_string *lcname;
ALLOCA_FLAG(use_heap);

STR_ALLOCA_ALLOC(lcname, name_len, use_heap);
ZSTR_ALLOCA_ALLOC(lcname, name_len, use_heap);
zend_str_tolower_copy(lcname->val, name->val, name_len);

*strict_class = 0;
Expand Down Expand Up @@ -2913,7 +2913,7 @@ static int zend_is_callable_check_class(zend_string *name, zend_fcall_info_cache
} else {
if (error) zend_spprintf(error, 0, "class '%.*s' not found", name_len, name->val);
}
STR_ALLOCA_FREE(lcname, use_heap);
ZSTR_ALLOCA_FREE(lcname, use_heap);
return ret;
}
/* }}} */
Expand Down Expand Up @@ -2943,31 +2943,31 @@ static int zend_is_callable_check_func(int check_flags, zval *callable, zend_fca

/* Skip leading \ */
if (UNEXPECTED(Z_STRVAL_P(callable)[0] == '\\')) {
STR_ALLOCA_INIT(lmname, Z_STRVAL_P(callable) + 1, Z_STRLEN_P(callable) - 1, use_heap);
ZSTR_ALLOCA_INIT(lmname, Z_STRVAL_P(callable) + 1, Z_STRLEN_P(callable) - 1, use_heap);
} else {
lmname = Z_STR_P(callable);
}
/* Check if function with given name exists.
* This may be a compound name that includes namespace name */
if (EXPECTED((fcc->function_handler = zend_hash_find_ptr(EG(function_table), lmname)) != NULL)) {
if (lmname != Z_STR_P(callable)) {
STR_ALLOCA_FREE(lmname, use_heap);
ZSTR_ALLOCA_FREE(lmname, use_heap);
}
return 1;
} else {
if (lmname == Z_STR_P(callable)) {
STR_ALLOCA_INIT(lmname, Z_STRVAL_P(callable), Z_STRLEN_P(callable), use_heap);
ZSTR_ALLOCA_INIT(lmname, Z_STRVAL_P(callable), Z_STRLEN_P(callable), use_heap);
} else {
zend_string_forget_hash_val(lmname);
}
zend_str_tolower(lmname->val, lmname->len);
if ((fcc->function_handler = zend_hash_find_ptr(EG(function_table), lmname)) != NULL) {
STR_ALLOCA_FREE(lmname, use_heap);
ZSTR_ALLOCA_FREE(lmname, use_heap);
return 1;
}
}
if (lmname != Z_STR_P(callable)) {
STR_ALLOCA_FREE(lmname, use_heap);
ZSTR_ALLOCA_FREE(lmname, use_heap);
}
}

Expand Down
24 changes: 18 additions & 6 deletions Zend/zend_API.h
Original file line number Diff line number Diff line change
Expand Up @@ -572,8 +572,20 @@ END_EXTERN_C()
ZVAL_STRINGL(z, _s, strlen(_s)); \
} while (0)

#define ZVAL_STR_LEN(z, l) do { \
zend_string_set_len(Z_STR_P(z), l); \
} while (0)

#define ZVAL_STR_DEC_LEN(z) do { \
zend_string_dec_len(Z_STR_P(z)); \
} while (0)

#define ZVAL_STR_INC_LEN(z) do { \
zend_string_inc_len(Z_STR_P(z)); \
} while (0)

#define ZVAL_EMPTY_STRING(z) do { \
ZVAL_INTERNED_STR(z, STR_EMPTY_ALLOC()); \
ZVAL_INTERNED_STR(z, ZSTR_EMPTY_ALLOC()); \
} while (0)

#define ZVAL_PSTRINGL(z, s, l) do { \
Expand Down Expand Up @@ -1126,16 +1138,16 @@ static zend_always_inline int zend_parse_arg_string(zval *arg, char **dest, size
*dest = NULL;
*dest_len = 0;
} else {
*dest = str->val;
*dest_len = str->len;
*dest = ZSTR_VAL(str);
*dest_len = ZSTR_LEN(str);
}
return 1;
}

static zend_always_inline int zend_parse_arg_path_str(zval *arg, zend_string **dest, int check_null)
{
if (!zend_parse_arg_str(arg, dest, check_null) ||
(*dest && UNEXPECTED(CHECK_NULL_PATH((*dest)->val, (*dest)->len)))) {
(*dest && UNEXPECTED(CHECK_NULL_PATH(ZSTR_VAL(*dest), ZSTR_LEN(*dest))))) {
return 0;
}
return 1;
Expand All @@ -1152,8 +1164,8 @@ static zend_always_inline int zend_parse_arg_path(zval *arg, char **dest, size_t
*dest = NULL;
*dest_len = 0;
} else {
*dest = str->val;
*dest_len = str->len;
*dest = ZSTR_VAL(str);
*dest_len = ZSTR_LEN(str);
}
return 1;
}
Expand Down
2 changes: 1 addition & 1 deletion Zend/zend_ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ static int zend_ast_add_array_element(zval *result, zval *offset, zval *expr)
zval_dtor(offset);
break;
case IS_NULL:
zend_symtable_update(Z_ARRVAL_P(result), STR_EMPTY_ALLOC(), expr);
zend_symtable_update(Z_ARRVAL_P(result), ZSTR_EMPTY_ALLOC(), expr);
break;
case IS_LONG:
zend_hash_index_update(Z_ARRVAL_P(result), Z_LVAL_P(offset), expr);
Expand Down
8 changes: 4 additions & 4 deletions Zend/zend_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ static inline void zend_insert_literal(zend_op_array *op_array, zval *zv, int li
if (Z_TYPE_P(zv) == IS_STRING || Z_TYPE_P(zv) == IS_CONSTANT) {
zend_string_hash_val(Z_STR_P(zv));
Z_STR_P(zv) = zend_new_interned_string(Z_STR_P(zv));
if (IS_INTERNED(Z_STR_P(zv))) {
if (ZSTR_IS_INTERNED(Z_STR_P(zv))) {
Z_TYPE_FLAGS_P(zv) &= ~ (IS_TYPE_REFCOUNTED | IS_TYPE_COPYABLE);
}
}
Expand Down Expand Up @@ -725,10 +725,10 @@ void *zend_hash_find_ptr_lc(HashTable *ht, const char *str, size_t len) {
zend_string *lcname;
ALLOCA_FLAG(use_heap);

STR_ALLOCA_ALLOC(lcname, len, use_heap);
ZSTR_ALLOCA_ALLOC(lcname, len, use_heap);
zend_str_tolower_copy(lcname->val, str, len);
result = zend_hash_find_ptr(ht, lcname);
STR_ALLOCA_FREE(lcname, use_heap);
ZSTR_ALLOCA_FREE(lcname, use_heap);

return result;
}
Expand Down Expand Up @@ -5708,7 +5708,7 @@ static zend_bool zend_try_ct_eval_array(zval *result, zend_ast *ast) /* {{{ */
zend_hash_index_update(Z_ARRVAL_P(result), 1, value);
break;
case IS_NULL:
zend_hash_update(Z_ARRVAL_P(result), STR_EMPTY_ALLOC(), value);
zend_hash_update(Z_ARRVAL_P(result), ZSTR_EMPTY_ALLOC(), value);
break;
default:
zend_error_noreturn(E_COMPILE_ERROR, "Illegal offset type");
Expand Down
2 changes: 1 addition & 1 deletion Zend/zend_exceptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ ZEND_METHOD(exception, __toString)

DEFAULT_0_PARAMS;

str = STR_EMPTY_ALLOC();
str = ZSTR_EMPTY_ALLOC();

exception = getThis();
ZVAL_STRINGL(&fname, "gettraceasstring", sizeof("gettraceasstring")-1);
Expand Down
6 changes: 3 additions & 3 deletions Zend/zend_execute.c
Original file line number Diff line number Diff line change
Expand Up @@ -573,9 +573,9 @@ ZEND_API char * zend_verify_internal_arg_class_kind(const zend_internal_arg_info
zend_string *key;
ALLOCA_FLAG(use_heap);

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

*class_name = (*pce) ? (*pce)->name->val : (char*)cur_arg_info->class_name;
if (*pce && (*pce)->ce_flags & ZEND_ACC_INTERFACE) {
Expand Down Expand Up @@ -1564,7 +1564,7 @@ static zend_always_inline zval *zend_fetch_dimension_address_inner(HashTable *ht
} else {
switch (Z_TYPE_P(dim)) {
case IS_NULL:
offset_key = STR_EMPTY_ALLOC();
offset_key = ZSTR_EMPTY_ALLOC();
goto str_index;
case IS_DOUBLE:
hval = zend_dval_to_lval(Z_DVAL_P(dim));
Expand Down
2 changes: 1 addition & 1 deletion Zend/zend_hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ static zend_always_inline zval *_zend_hash_add_or_update_i(HashTable *ht, zend_s
zend_hash_iterators_update(ht, HT_INVALID_IDX, idx);
p = ht->arData + idx;
p->key = key;
if (!IS_INTERNED(key)) {
if (!ZSTR_IS_INTERNED(key)) {
zend_string_addref(key);
ht->u.flags &= ~HASH_FLAG_STATIC_KEYS;
zend_string_hash_val(key);
Expand Down
6 changes: 3 additions & 3 deletions Zend/zend_hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -894,7 +894,7 @@ static zend_always_inline zval *_zend_hash_append(HashTable *ht, zend_string *ke
Bucket *p = ht->arData + idx;

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

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

ZVAL_INDIRECT(&p->val, ptr);
if (!IS_INTERNED(key)) {
if (!ZSTR_IS_INTERNED(key)) {
ht->u.flags &= ~HASH_FLAG_STATIC_KEYS;
zend_string_addref(key);
zend_string_hash_val(key);
Expand Down
4 changes: 2 additions & 2 deletions Zend/zend_language_parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -1014,7 +1014,7 @@ exit_expr:

backticks_expr:
/* empty */
{ $$ = zend_ast_create_zval_from_str(STR_EMPTY_ALLOC()); }
{ $$ = zend_ast_create_zval_from_str(ZSTR_EMPTY_ALLOC()); }
| T_ENCAPSED_AND_WHITESPACE { $$ = $1; }
| encaps_list { $$ = $1; }
;
Expand Down Expand Up @@ -1045,7 +1045,7 @@ scalar:
| T_CLASS_C { $$ = zend_ast_create_ex(ZEND_AST_MAGIC_CONST, T_CLASS_C); }
| T_START_HEREDOC T_ENCAPSED_AND_WHITESPACE T_END_HEREDOC { $$ = $2; }
| T_START_HEREDOC T_END_HEREDOC
{ $$ = zend_ast_create_zval_from_str(STR_EMPTY_ALLOC()); }
{ $$ = zend_ast_create_zval_from_str(ZSTR_EMPTY_ALLOC()); }
| '"' encaps_list '"' { $$ = $2; }
| T_START_HEREDOC encaps_list T_END_HEREDOC { $$ = $2; }
| dereferencable_scalar { $$ = $1; }
Expand Down
8 changes: 4 additions & 4 deletions Zend/zend_object_handlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -1048,7 +1048,7 @@ ZEND_API zend_function *zend_get_call_trampoline_func(zend_class_entry *ce, zend

func->prototype = fbc;
func->scope = fbc->common.scope;
func->filename = (fbc->type == ZEND_USER_FUNCTION)? fbc->op_array.filename : STR_EMPTY_ALLOC();
func->filename = (fbc->type == ZEND_USER_FUNCTION)? fbc->op_array.filename : ZSTR_EMPTY_ALLOC();
func->line_start = (fbc->type == ZEND_USER_FUNCTION)? fbc->op_array.line_start : 0;
func->line_end = (fbc->type == ZEND_USER_FUNCTION)? fbc->op_array.line_end : 0;

Expand Down Expand Up @@ -1084,13 +1084,13 @@ static union _zend_function *zend_std_get_method(zend_object **obj_ptr, zend_str
use_heap = 0;
#endif
} else {
STR_ALLOCA_ALLOC(lc_method_name, method_name->len, use_heap);
ZSTR_ALLOCA_ALLOC(lc_method_name, method_name->len, use_heap);
zend_str_tolower_copy(lc_method_name->val, method_name->val, method_name->len);
}

if (UNEXPECTED((func = zend_hash_find(&zobj->ce->function_table, lc_method_name)) == NULL)) {
if (UNEXPECTED(!key)) {
STR_ALLOCA_FREE(lc_method_name, use_heap);
ZSTR_ALLOCA_FREE(lc_method_name, use_heap);
}
if (zobj->ce->__call) {
return zend_get_user_call_function(zobj->ce, method_name);
Expand Down Expand Up @@ -1149,7 +1149,7 @@ static union _zend_function *zend_std_get_method(zend_object **obj_ptr, zend_str
}

if (UNEXPECTED(!key)) {
STR_ALLOCA_FREE(lc_method_name, use_heap);
ZSTR_ALLOCA_FREE(lc_method_name, use_heap);
}
return fbc;
}
Expand Down
4 changes: 2 additions & 2 deletions Zend/zend_operators.c
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,7 @@ ZEND_API zend_string* ZEND_FASTCALL _zval_get_string_func(zval *op) /* {{{ */
case IS_UNDEF:
case IS_NULL:
case IS_FALSE:
return STR_EMPTY_ALLOC();
return ZSTR_EMPTY_ALLOC();
case IS_TRUE:
return zend_string_init("1", 1, 0);
case IS_RESOURCE: {
Expand Down Expand Up @@ -838,7 +838,7 @@ ZEND_API zend_string* ZEND_FASTCALL _zval_get_string_func(zval *op) /* {{{ */
zval_ptr_dtor(z);
}
zend_error(EG(exception) ? E_ERROR : E_RECOVERABLE_ERROR, "Object of class %s could not be converted to string", Z_OBJCE_P(op)->name->val);
return STR_EMPTY_ALLOC();
return ZSTR_EMPTY_ALLOC();
}
case IS_REFERENCE:
op = Z_REFVAL_P(op);
Expand Down
6 changes: 3 additions & 3 deletions Zend/zend_smart_str.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <zend.h>
#include "zend_smart_str_public.h"

#define SMART_STR_OVERHEAD (ZEND_MM_OVERHEAD + _STR_HEADER_SIZE)
#define SMART_STR_OVERHEAD (ZEND_MM_OVERHEAD + _ZSTR_HEADER_SIZE)

#ifndef SMART_STR_PAGE
# define SMART_STR_PAGE 4096
Expand All @@ -42,7 +42,7 @@ ZEND_API void ZEND_FASTCALL smart_str_erealloc(smart_str *str, size_t len)
str->s->len = 0;
} else {
str->a = SMART_STR_NEW_SIZE(len);
str->s = (zend_string *) erealloc2(str->s, _STR_HEADER_SIZE + str->a + 1, _STR_HEADER_SIZE + str->s->len + 1);
str->s = (zend_string *) erealloc2(str->s, _ZSTR_HEADER_SIZE + str->a + 1, _ZSTR_HEADER_SIZE + str->s->len + 1);
}
}

Expand All @@ -56,6 +56,6 @@ ZEND_API void ZEND_FASTCALL smart_str_realloc(smart_str *str, size_t len)
str->s->len = 0;
} else {
str->a = SMART_STR_NEW_SIZE(len);
str->s = (zend_string *) realloc(str->s, _STR_HEADER_SIZE + str->a + 1);
str->s = (zend_string *) realloc(str->s, _ZSTR_HEADER_SIZE + str->a + 1);
}
}
2 changes: 1 addition & 1 deletion Zend/zend_string.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ static zend_string *zend_new_interned_string_int(zend_string *str)
uint idx;
Bucket *p;

if (IS_INTERNED(str)) {
if (ZSTR_IS_INTERNED(str)) {
return str;
}

Expand Down
Loading