Skip to content

Expose more string APIs #15075

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

Draft
wants to merge 14 commits into
base: master
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion Zend/Optimizer/dfa_pass.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ static bool safe_instanceof(zend_class_entry *ce1, zend_class_entry *ce2) {
return instanceof_function(ce1, ce2);
}

static inline bool can_elide_list_type(
static bool can_elide_list_type(
const zend_script *script, const zend_op_array *op_array,
const zend_ssa_var_info *use_info, zend_type type)
{
Expand Down
2 changes: 1 addition & 1 deletion Zend/Optimizer/zend_inference.c
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ static inline zend_long safe_shift_left(zend_long n, zend_long s) {
return (zend_long) ((zend_ulong) n << (zend_ulong) s);
}

static inline bool shift_left_overflows(zend_long n, zend_long s) {
static bool shift_left_overflows(zend_long n, zend_long s) {
/* This considers shifts that shift in the sign bit to be overflowing as well */
if (n >= 0) {
return s >= SIZEOF_ZEND_LONG * 8 - 1 || safe_shift_left(n, s) < n;
Expand Down
2 changes: 1 addition & 1 deletion Zend/Optimizer/zend_optimizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ static inline int zend_optimizer_add_literal_string(zend_op_array *op_array, zen
return zend_optimizer_add_literal(op_array, &zv);
}

static inline void drop_leading_backslash(zval *val) {
static void drop_leading_backslash(zval *val) {
if (Z_STRVAL_P(val)[0] == '\\') {
zend_string *str = zend_string_init(Z_STRVAL_P(val) + 1, Z_STRLEN_P(val) - 1, 0);
zval_ptr_dtor_nogc(val);
Expand Down
10 changes: 9 additions & 1 deletion Zend/zend.c
Original file line number Diff line number Diff line change
Expand Up @@ -1573,7 +1573,7 @@ static ZEND_COLD void zend_error_va_list(
{
zend_string *message = zend_vstrpprintf(0, format, args);
zend_error_zstr_at(orig_type, error_filename, error_lineno, message);
zend_string_release(message);
zend_string_release_noinline(message);
}

static ZEND_COLD void get_filename_lineno(int type, zend_string **filename, uint32_t *lineno) {
Expand Down Expand Up @@ -2047,3 +2047,11 @@ ZEND_API void zend_alloc_ce_cache(zend_string *type_name)
GC_ADD_FLAGS(type_name, IS_STR_CLASS_NAME_MAP_PTR);
GC_SET_REFCOUNT(type_name, ret);
}


ZEND_API extern inline uint32_t zend_gc_delref(zend_refcounted_h *p);
ZEND_API extern inline uint32_t zval_gc_flags(uint32_t gc_type_info);
ZEND_API extern inline uint32_t zval_gc_info(uint32_t gc_type_info);
ZEND_API extern inline uint32_t zend_gc_refcount(const zend_refcounted_h *p);
ZEND_API extern inline uint32_t zend_gc_set_refcount(zend_refcounted_h *p, uint32_t rc);
ZEND_API extern inline uint8_t zval_gc_type(uint32_t gc_type_info);
20 changes: 10 additions & 10 deletions Zend/zend_API.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ ZEND_API ZEND_COLD void zend_wrong_property_read(zval *object, zval *property)
zend_string *tmp_property_name;
zend_string *property_name = zval_get_tmp_string(property, &tmp_property_name);
zend_error(E_WARNING, "Attempt to read property \"%s\" on %s", ZSTR_VAL(property_name), zend_zval_value_name(object));
zend_tmp_string_release(tmp_property_name);
zend_tmp_string_release_noinline(tmp_property_name);
}

/* Argument parsing API -- andrei */
Expand Down Expand Up @@ -217,7 +217,7 @@ ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameters_none_error(void) /*

zend_argument_count_error("%s() expects exactly 0 arguments, %d given", ZSTR_VAL(func_name), num_args);

zend_string_release(func_name);
zend_string_release_noinline(func_name);
}
/* }}} */

Expand All @@ -235,7 +235,7 @@ ZEND_API ZEND_COLD void ZEND_FASTCALL zend_wrong_parameters_count_error(uint32_t
num_args
);

zend_string_release(func_name);
zend_string_release_noinline(func_name);
}
/* }}} */

Expand Down Expand Up @@ -405,7 +405,7 @@ ZEND_API ZEND_COLD void ZEND_FASTCALL zend_argument_error_variadic(zend_class_en
arg_name ? " ($" : "", arg_name ? arg_name : "", arg_name ? ")" : "", message
);
efree(message);
zend_string_release(func_name);
zend_string_release_noinline(func_name);
}
/* }}} */

Expand Down Expand Up @@ -510,9 +510,9 @@ static ZEND_COLD bool zend_null_arg_deprecated(const char *fallback_type, uint32
ZSTR_VAL(func_name), arg_num,
arg_name ? " ($" : "", arg_name ? arg_name : "", arg_name ? ")" : "",
type);
zend_string_release(func_name);
zend_string_release_noinline(func_name);
if (type_str) {
zend_string_release(type_str);
zend_string_release_noinline(type_str);
}
return !EG(exception);
}
Expand Down Expand Up @@ -1225,7 +1225,7 @@ static zend_result zend_parse_va_args(uint32_t num_args, const char *type_spec,
num_args
);

zend_string_release(func_name);
zend_string_release_noinline(func_name);
}
return FAILURE;
}
Expand Down Expand Up @@ -1873,7 +1873,7 @@ ZEND_API zend_result object_init_with_constructor(zval *arg, zend_class_entry *c
zend_hash_get_current_key(named_params, &arg_name, /* num_index */ NULL);
ZEND_ASSERT(arg_name != NULL);
zend_throw_error(NULL, "Unknown named parameter $%s", ZSTR_VAL(arg_name));
zend_string_release(arg_name);
zend_string_release_noinline(arg_name);
/* Do not call destructor, free object, and set arg to IS_UNDEF */
zend_object_store_ctor_failed(obj);
zval_ptr_dtor(arg);
Expand Down Expand Up @@ -2619,7 +2619,7 @@ ZEND_API zend_module_entry* zend_register_module_ex(zend_module_entry *module, i
lcname = zend_new_interned_string(lcname);
if ((module_ptr = zend_hash_add_ptr(&module_registry, lcname, module)) == NULL) {
zend_error(E_CORE_WARNING, "Module \"%s\" is already loaded", module->name);
zend_string_release(lcname);
zend_string_release_noinline(lcname);
return NULL;
}
module = module_ptr;
Expand All @@ -2630,7 +2630,7 @@ ZEND_API zend_module_entry* zend_register_module_ex(zend_module_entry *module, i

if (module->functions && zend_register_functions(NULL, module->functions, NULL, module_type)==FAILURE) {
zend_hash_del(&module_registry, lcname);
zend_string_release(lcname);
zend_string_release_noinline(lcname);
EG(current_module) = NULL;
zend_error(E_CORE_WARNING,"%s: Unable to register functions, unable to load", module->name);
return NULL;
Expand Down
2 changes: 1 addition & 1 deletion Zend/zend_API.h
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,7 @@ static zend_always_inline zend_result zend_forbid_dynamic_call(void)
zend_string *function_or_method_name = get_active_function_or_method_name();
zend_throw_error(NULL, "Cannot call %.*s() dynamically",
(int) ZSTR_LEN(function_or_method_name), ZSTR_VAL(function_or_method_name));
zend_string_release(function_or_method_name);
zend_string_release_noinline(function_or_method_name);
return FAILURE;
}

Expand Down
6 changes: 3 additions & 3 deletions Zend/zend_ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

ZEND_API zend_ast_process_t zend_ast_process = NULL;

static inline void *zend_ast_alloc(size_t size) {
static void *zend_ast_alloc(size_t size) {
return zend_arena_alloc(&CG(ast_arena), size);
}

Expand Down Expand Up @@ -1193,10 +1193,10 @@ ZEND_API void ZEND_FASTCALL zend_ast_destroy(zend_ast *ast)
zend_ast_decl *decl = (zend_ast_decl *) ast;

if (decl->name) {
zend_string_release_ex(decl->name, 0);
zend_string_release_ex_noinline(decl->name, 0);
}
if (decl->doc_comment) {
zend_string_release_ex(decl->doc_comment, 0);
zend_string_release_ex_noinline(decl->doc_comment, 0);
}
zend_ast_destroy(decl->child[0]);
zend_ast_destroy(decl->child[1]);
Expand Down
4 changes: 2 additions & 2 deletions Zend/zend_builtin_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -1053,7 +1053,7 @@ flf_clean:;
Z_FLF_PARAM_FREE_STR(2, property_tmp)
}

static inline void _class_exists_impl(zval *return_value, zend_string *name, bool autoload, int flags, int skip_flags) /* {{{ */
static void _class_exists_impl(zval *return_value, zend_string *name, bool autoload, int flags, int skip_flags) /* {{{ */
{
zend_string *lcname;
zend_class_entry *ce;
Expand Down Expand Up @@ -1368,7 +1368,7 @@ ZEND_FUNCTION(restore_exception_handler)
}
/* }}} */

static inline void get_declared_class_impl(INTERNAL_FUNCTION_PARAMETERS, int flags) /* {{{ */
static void get_declared_class_impl(INTERNAL_FUNCTION_PARAMETERS, int flags) /* {{{ */
{
zend_string *key;
zval *zv;
Expand Down
10 changes: 5 additions & 5 deletions Zend/zend_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -4116,7 +4116,7 @@ static zend_result zend_compile_func_defined(znode *result, zend_ast_list *args)

name = zval_get_string(zend_ast_get_zval(args->child[0]));
if (zend_memrchr(ZSTR_VAL(name), '\\', ZSTR_LEN(name)) || zend_memrchr(ZSTR_VAL(name), ':', ZSTR_LEN(name))) {
zend_string_release_ex(name, 0);
zend_string_release_ex_noinline(name, 0);
return FAILURE;
}

Expand Down Expand Up @@ -4285,7 +4285,7 @@ static zend_result zend_compile_func_cufa(znode *result, zend_ast_list *args, ze
opline = zend_emit_op(NULL, ZEND_SEND_ARRAY, &arg_node, &len_node);
opline->extended_value = Z_LVAL_P(zv);
zend_emit_op(result, ZEND_DO_FCALL, NULL, NULL);
zend_string_release_ex(name, 0);
zend_string_release_ex_noinline(name, 0);
return SUCCESS;
}
}
Expand Down Expand Up @@ -7538,7 +7538,7 @@ static void zend_compile_params(zend_ast *ast, zend_ast *return_type_ast, uint32
&& (op_array->fn_flags & ZEND_ACC_RETURN_REFERENCE)) {
zend_string *func_name = get_function_or_method_name((zend_function *) op_array);
zend_error(E_DEPRECATED, "%s(): Returning by reference from a void function is deprecated", ZSTR_VAL(func_name));
zend_string_release(func_name);
zend_string_release_noinline(func_name);
}
} else {
if (list->children == 0) {
Expand Down Expand Up @@ -7674,7 +7674,7 @@ static void zend_compile_params(zend_ast *ast, zend_ast *return_type_ast, uint32
"%s(): Optional parameter $%s declared before required parameter $%s "
"is implicitly treated as a required parameter",
ZSTR_VAL(func_name), ZSTR_VAL(name), ZSTR_VAL(zend_ast_get_str(required_param_ast->child[1])));
zend_string_release(func_name);
zend_string_release_noinline(func_name);
}

/* Regardless of whether we issue a deprecation, convert this parameter into
Expand Down Expand Up @@ -10742,7 +10742,7 @@ static void zend_compile_class_const(znode *result, zend_ast *ast) /* {{{ */
zend_string *resolved_name = zend_resolve_class_name_ast(class_ast);
if (zend_try_ct_eval_class_const(&result->u.constant, resolved_name, const_str)) {
result->op_type = IS_CONST;
zend_string_release_ex(resolved_name, 0);
zend_string_release_ex_noinline(resolved_name, 0);
return;
}
zend_string_release_ex(resolved_name, 0);
Expand Down
2 changes: 1 addition & 1 deletion Zend/zend_constants.c
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ ZEND_API zend_result zend_register_constant(zend_constant *c)
|| zend_hash_add_constant(EG(zend_constants), name, c) == NULL
) {
zend_error(E_WARNING, "Constant %s already defined", ZSTR_VAL(name));
zend_string_release(c->name);
zend_string_release_noinline(c->name);
if (!persistent) {
zval_ptr_dtor_nogc(&c->value);
}
Expand Down
37 changes: 21 additions & 16 deletions Zend/zend_exceptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ static inline zend_class_entry *i_get_exception_base(zend_object *object) /* {{{
}
/* }}} */

ZEND_API zend_class_entry *zend_get_exception_base(zend_object *object) /* {{{ */
ZEND_API zend_never_inline zend_class_entry *zend_get_exception_base(zend_object *object) /* {{{ */
{
return i_get_exception_base(object);
}
Expand Down Expand Up @@ -403,6 +403,11 @@ ZEND_METHOD(ErrorException, __construct)
#define GET_PROPERTY_SILENT(object, id) \
zend_read_property_ex(i_get_exception_base(Z_OBJ_P(object)), Z_OBJ_P(object), ZSTR_KNOWN(id), 1, &rv)

#define GET_PROPERTY_NOINLINE(object, id) \
zend_read_property_ex(zend_get_exception_base(Z_OBJ_P(object)), Z_OBJ_P(object), ZSTR_KNOWN(id), 0, &rv)
#define GET_PROPERTY_SILENT_NOINLINE(object, id) \
zend_read_property_ex(zend_get_exception_base(Z_OBJ_P(object)), Z_OBJ_P(object), ZSTR_KNOWN(id), 1, &rv)

/* {{{ Get the file in which the exception occurred */
ZEND_METHOD(Exception, getFile)
{
Expand Down Expand Up @@ -844,7 +849,7 @@ ZEND_API ZEND_COLD zend_object *zend_throw_exception(zend_class_entry *exception
zend_string *msg_str = message ? zend_string_init(message, strlen(message), 0) : NULL;
zend_object *ex = zend_throw_exception_zstr(exception_ce, msg_str, code);
if (msg_str) {
zend_string_release(msg_str);
zend_string_release_noinline(msg_str);
}
return ex;
}
Expand Down Expand Up @@ -884,7 +889,7 @@ static void zend_error_va(int type, zend_string *file, uint32_t lineno, const ch
zend_string *message = zend_vstrpprintf(0, format, args);
zend_observer_error_notify(type, file, lineno, message);
zend_error_cb(type, file, lineno, message);
zend_string_release(message);
zend_string_release_noinline(message);
va_end(args);
}
/* }}} */
Expand All @@ -900,16 +905,16 @@ ZEND_API ZEND_COLD zend_result zend_exception_error(zend_object *ex, int severit
ce_exception = ex->ce;
EG(exception) = NULL;
if (ce_exception == zend_ce_parse_error || ce_exception == zend_ce_compile_error) {
zend_string *message = zval_get_string(GET_PROPERTY(&exception, ZEND_STR_MESSAGE));
zend_string *file = zval_get_string(GET_PROPERTY_SILENT(&exception, ZEND_STR_FILE));
zend_long line = zval_get_long(GET_PROPERTY_SILENT(&exception, ZEND_STR_LINE));
zend_string *message = zval_get_string(GET_PROPERTY_NOINLINE(&exception, ZEND_STR_MESSAGE));
zend_string *file = zval_get_string(GET_PROPERTY_SILENT_NOINLINE(&exception, ZEND_STR_FILE));
zend_long line = zval_get_long(GET_PROPERTY_SILENT_NOINLINE(&exception, ZEND_STR_LINE));
int type = (ce_exception == zend_ce_parse_error ? E_PARSE : E_COMPILE_ERROR) | E_DONT_BAIL;

zend_observer_error_notify(type, file, line, message);
zend_error_cb(type, file, line, message);

zend_string_release_ex(file, 0);
zend_string_release_ex(message, 0);
zend_string_release_ex_noinline(file, 0);
zend_string_release_ex_noinline(message, 0);
} else if (instanceof_function(ce_exception, zend_ce_throwable)) {
zval tmp;
zend_string *str, *file = NULL;
Expand All @@ -931,29 +936,29 @@ ZEND_API ZEND_COLD zend_result zend_exception_error(zend_object *ex, int severit
ZVAL_OBJ(&zv, EG(exception));
/* do the best we can to inform about the inner exception */
if (instanceof_function(ce_exception, zend_ce_exception) || instanceof_function(ce_exception, zend_ce_error)) {
file = zval_get_string(GET_PROPERTY_SILENT(&zv, ZEND_STR_FILE));
line = zval_get_long(GET_PROPERTY_SILENT(&zv, ZEND_STR_LINE));
file = zval_get_string(GET_PROPERTY_SILENT_NOINLINE(&zv, ZEND_STR_FILE));
line = zval_get_long(GET_PROPERTY_SILENT_NOINLINE(&zv, ZEND_STR_LINE));
}

zend_error_va(E_WARNING, (file && ZSTR_LEN(file) > 0) ? file : NULL, line,
"Uncaught %s in exception handling during call to %s::__toString()",
ZSTR_VAL(Z_OBJCE(zv)->name), ZSTR_VAL(ce_exception->name));

if (file) {
zend_string_release_ex(file, 0);
zend_string_release_ex_noinline(file, 0);
}
}

str = zval_get_string(GET_PROPERTY_SILENT(&exception, ZEND_STR_STRING));
file = zval_get_string(GET_PROPERTY_SILENT(&exception, ZEND_STR_FILE));
line = zval_get_long(GET_PROPERTY_SILENT(&exception, ZEND_STR_LINE));
str = zval_get_string(GET_PROPERTY_SILENT_NOINLINE(&exception, ZEND_STR_STRING));
file = zval_get_string(GET_PROPERTY_SILENT_NOINLINE(&exception, ZEND_STR_FILE));
line = zval_get_long(GET_PROPERTY_SILENT_NOINLINE(&exception, ZEND_STR_LINE));

zend_error_va(severity | E_DONT_BAIL,
(file && ZSTR_LEN(file) > 0) ? file : NULL, line,
"Uncaught %S\n thrown", str);

zend_string_release_ex(str, 0);
zend_string_release_ex(file, 0);
zend_string_release_ex_noinline(str, 0);
zend_string_release_ex_noinline(file, 0);
} else if (ce_exception == &zend_ce_unwind_exit || ce_exception == &zend_ce_graceful_exit) {
/* We successfully unwound, nothing more to do.
* We still return FAILURE in this case, as further execution should still be aborted. */
Expand Down
Loading
Loading