Commit 247a689a66d for php
commit 247a689a66d8dea8daf455e626aa827d3b8d8168
Author: Daniel Scherzer <daniel.e.scherzer@gmail.com>
Date: Sat Nov 14 08:31:59 2026 -0800
[`%pS` migration] Use `%pS` in ext/ffi (#23154)
diff --git a/ext/ffi/ffi.c b/ext/ffi/ffi.c
index f0ba22f96c3..9b3be5b92b8 100644
--- a/ext/ffi/ffi.c
+++ b/ext/ffi/ffi.c
@@ -880,15 +880,15 @@ static zend_always_inline zend_string *zend_ffi_mangled_func_name(zend_string *n
switch (type->func.abi) {
# ifdef HAVE_FFI_FASTCALL
case FFI_FASTCALL:
- return strpprintf(0, "@%s@%zu", ZSTR_VAL(name), zend_ffi_arg_size(type));
+ return strpprintf(0, "@%pS@%zu", name, zend_ffi_arg_size(type));
# endif
# ifdef HAVE_FFI_STDCALL
case FFI_STDCALL:
- return strpprintf(0, "_%s@%zu", ZSTR_VAL(name), zend_ffi_arg_size(type));
+ return strpprintf(0, "_%pS@%zu", name, zend_ffi_arg_size(type));
# endif
# ifdef HAVE_FFI_VECTORCALL_PARTIAL
case FFI_VECTORCALL_PARTIAL:
- return strpprintf(0, "%s@@%zu", ZSTR_VAL(name), zend_ffi_arg_size(type));
+ return strpprintf(0, "%pS@@%zu", name, zend_ffi_arg_size(type));
# endif
default:
/* other calling conventions don't apply name mangling */
@@ -1241,13 +1241,13 @@ static zval *zend_ffi_cdata_read_field(zend_object *obj, zend_string *field_name
type = ZEND_FFI_TYPE(type->pointer.type);
}
if (UNEXPECTED(type->kind != ZEND_FFI_TYPE_STRUCT)) {
- zend_throw_error(zend_ffi_exception_ce, "Attempt to read field '%s' of non C struct/union", ZSTR_VAL(field_name));
+ zend_throw_error(zend_ffi_exception_ce, "Attempt to read field '%pS' of non C struct/union", field_name);
return &EG(uninitialized_zval);
}
field = zend_hash_find_ptr(&type->record.fields, field_name);
if (UNEXPECTED(!field)) {
- zend_throw_error(zend_ffi_exception_ce, "Attempt to read undefined field '%s' of C struct/union", ZSTR_VAL(field_name));
+ zend_throw_error(zend_ffi_exception_ce, "Attempt to read undefined field '%pS' of C struct/union", field_name);
return &EG(uninitialized_zval);
}
@@ -1310,20 +1310,20 @@ static zval *zend_ffi_cdata_write_field(zend_object *obj, zend_string *field_nam
field = *(cache_slot + 1);
} else {
if (UNEXPECTED(type == NULL)) {
- zend_throw_error(zend_ffi_exception_ce, "Attempt to assign field '%s' to uninitialized FFI\\CData object", ZSTR_VAL(field_name));
+ zend_throw_error(zend_ffi_exception_ce, "Attempt to assign field '%pS' to uninitialized FFI\\CData object", field_name);
return value;
}
if (type->kind == ZEND_FFI_TYPE_POINTER) {
type = ZEND_FFI_TYPE(type->pointer.type);
}
if (UNEXPECTED(type->kind != ZEND_FFI_TYPE_STRUCT)) {
- zend_throw_error(zend_ffi_exception_ce, "Attempt to assign field '%s' of non C struct/union", ZSTR_VAL(field_name));
+ zend_throw_error(zend_ffi_exception_ce, "Attempt to assign field '%pS' of non C struct/union", field_name);
return value;
}
field = zend_hash_find_ptr(&type->record.fields, field_name);
if (UNEXPECTED(!field)) {
- zend_throw_error(zend_ffi_exception_ce, "Attempt to assign undefined field '%s' of C struct/union", ZSTR_VAL(field_name));
+ zend_throw_error(zend_ffi_exception_ce, "Attempt to assign undefined field '%pS' of C struct/union", field_name);
return value;
}
@@ -1357,7 +1357,7 @@ static zval *zend_ffi_cdata_write_field(zend_object *obj, zend_string *field_nam
zend_throw_error(zend_ffi_exception_ce, "Attempt to assign read-only location");
return value;
} else if (UNEXPECTED(field->is_const)) {
- zend_throw_error(zend_ffi_exception_ce, "Attempt to assign read-only field '%s'", ZSTR_VAL(field_name));
+ zend_throw_error(zend_ffi_exception_ce, "Attempt to assign read-only field '%pS'", field_name);
return value;
}
@@ -1684,7 +1684,7 @@ static ZEND_COLD void zend_ffi_pass_incompatible(const zval *arg, const zend_ffi
buf1.start = buf1.end = buf1.buf + ((MAX_TYPE_NAME_LEN * 3) / 4);
if (!zend_ffi_ctype_name(&buf1, type)) {
- zend_throw_error(zend_ffi_exception_ce, "Passing incompatible argument %d of C function '%s'", n + 1, ZSTR_VAL(EX(func)->internal_function.function_name));
+ zend_throw_error(zend_ffi_exception_ce, "Passing incompatible argument %d of C function '%pS'", n + 1, EX(func)->internal_function.function_name);
} else {
*buf1.end = 0;
if (Z_TYPE_P(arg) == IS_OBJECT && Z_OBJCE_P(arg) == zend_ffi_cdata_ce) {
@@ -1693,13 +1693,13 @@ static ZEND_COLD void zend_ffi_pass_incompatible(const zval *arg, const zend_ffi
type = ZEND_FFI_TYPE(cdata->type);
buf2.start = buf2.end = buf2.buf + ((MAX_TYPE_NAME_LEN * 3) / 4);
if (!zend_ffi_ctype_name(&buf2, type)) {
- zend_throw_error(zend_ffi_exception_ce, "Passing incompatible argument %d of C function '%s', expecting '%s'", n + 1, ZSTR_VAL(EX(func)->internal_function.function_name), buf1.start);
+ zend_throw_error(zend_ffi_exception_ce, "Passing incompatible argument %d of C function '%pS', expecting '%s'", n + 1, EX(func)->internal_function.function_name, buf1.start);
} else {
*buf2.end = 0;
- zend_throw_error(zend_ffi_exception_ce, "Passing incompatible argument %d of C function '%s', expecting '%s', found '%s'", n + 1, ZSTR_VAL(EX(func)->internal_function.function_name), buf1.start, buf2.start);
+ zend_throw_error(zend_ffi_exception_ce, "Passing incompatible argument %d of C function '%pS', expecting '%s', found '%s'", n + 1, EX(func)->internal_function.function_name, buf1.start, buf2.start);
}
} else {
- zend_throw_error(zend_ffi_exception_ce, "Passing incompatible argument %d of C function '%s', expecting '%s', found PHP '%s'", n + 1, ZSTR_VAL(EX(func)->internal_function.function_name), buf1.start, zend_zval_value_name(arg));
+ zend_throw_error(zend_ffi_exception_ce, "Passing incompatible argument %d of C function '%pS', expecting '%s', found PHP '%s'", n + 1, EX(func)->internal_function.function_name, buf1.start, zend_zval_value_name(arg));
}
}
}
@@ -2493,7 +2493,7 @@ static zval *zend_ffi_read_var(zend_object *obj, zend_string *var_name, int read
}
}
if (!sym) {
- zend_throw_error(zend_ffi_exception_ce, "Attempt to read undefined C variable '%s'", ZSTR_VAL(var_name));
+ zend_throw_error(zend_ffi_exception_ce, "Attempt to read undefined C variable '%pS'", var_name);
return &EG(uninitialized_zval);
}
@@ -2537,12 +2537,12 @@ static zval *zend_ffi_write_var(zend_object *obj, zend_string *var_name, zval *v
}
}
if (!sym) {
- zend_throw_error(zend_ffi_exception_ce, "Attempt to assign undefined C variable '%s'", ZSTR_VAL(var_name));
+ zend_throw_error(zend_ffi_exception_ce, "Attempt to assign undefined C variable '%pS'", var_name);
return value;
}
if (sym->is_const) {
- zend_throw_error(zend_ffi_exception_ce, "Attempt to assign read-only C variable '%s'", ZSTR_VAL(var_name));
+ zend_throw_error(zend_ffi_exception_ce, "Attempt to assign read-only C variable '%pS'", var_name);
return value;
}
@@ -2762,7 +2762,7 @@ static ZEND_FUNCTION(ffi_trampoline) /* {{{ */
arg_count = type->func.args ? zend_hash_num_elements(type->func.args) : 0;
if (type->attr & ZEND_FFI_ATTR_VARIADIC) {
if (arg_count > EX_NUM_ARGS()) {
- zend_throw_error(zend_ffi_exception_ce, "Incorrect number of arguments for C function '%s', expecting at least %d parameter%s", ZSTR_VAL(EX(func)->internal_function.function_name), arg_count, (arg_count != 1) ? "s" : "");
+ zend_throw_error(zend_ffi_exception_ce, "Incorrect number of arguments for C function '%pS', expecting at least %d parameter%s", EX(func)->internal_function.function_name, arg_count, (arg_count != 1) ? "s" : "");
goto exit;
}
if (EX_NUM_ARGS()) {
@@ -2807,7 +2807,7 @@ static ZEND_FUNCTION(ffi_trampoline) /* {{{ */
}
} else {
if (arg_count != EX_NUM_ARGS()) {
- zend_throw_error(zend_ffi_exception_ce, "Incorrect number of arguments for C function '%s', expecting exactly %d parameter%s", ZSTR_VAL(EX(func)->internal_function.function_name), arg_count, (arg_count != 1) ? "s" : "");
+ zend_throw_error(zend_ffi_exception_ce, "Incorrect number of arguments for C function '%pS', expecting exactly %d parameter%s", EX(func)->internal_function.function_name, arg_count, (arg_count != 1) ? "s" : "");
goto exit;
}
if (EX_NUM_ARGS()) {
@@ -2935,7 +2935,7 @@ static zend_function *zend_ffi_get_func(zend_object **obj, zend_string *name, co
}
}
if (!sym) {
- zend_throw_error(zend_ffi_exception_ce, "Attempt to call undefined C function '%s'", ZSTR_VAL(name));
+ zend_throw_error(zend_ffi_exception_ce, "Attempt to call undefined C function '%pS'", name);
return NULL;
}
@@ -3062,13 +3062,13 @@ ZEND_METHOD(FFI, cdef) /* {{{ */
char *err = GET_DL_ERROR();
#ifdef PHP_WIN32
if (err && err[0]) {
- zend_throw_error(zend_ffi_exception_ce, "Failed loading '%s' (%s)", ZSTR_VAL(lib), err);
+ zend_throw_error(zend_ffi_exception_ce, "Failed loading '%pS' (%s)", lib, err);
php_win32_error_msg_free(err);
} else {
- zend_throw_error(zend_ffi_exception_ce, "Failed loading '%s' (Unknown reason)", ZSTR_VAL(lib));
+ zend_throw_error(zend_ffi_exception_ce, "Failed loading '%pS' (Unknown reason)", lib);
}
#else
- zend_throw_error(zend_ffi_exception_ce, "Failed loading '%s' (%s)", ZSTR_VAL(lib), err);
+ zend_throw_error(zend_ffi_exception_ce, "Failed loading '%pS' (%s)", lib, err);
GET_DL_ERROR(); /* free the buffer storing the error */
#endif
RETURN_THROWS();
@@ -3101,7 +3101,7 @@ ZEND_METHOD(FFI, cdef) /* {{{ */
if (sym->kind == ZEND_FFI_SYM_VAR) {
addr = DL_FETCH_SYMBOL(handle, ZSTR_VAL(name));
if (!addr) {
- zend_throw_error(zend_ffi_exception_ce, "Failed resolving C variable '%s'", ZSTR_VAL(name));
+ zend_throw_error(zend_ffi_exception_ce, "Failed resolving C variable '%pS'", name);
goto cleanup;
}
sym->addr = addr;
@@ -3111,7 +3111,7 @@ ZEND_METHOD(FFI, cdef) /* {{{ */
addr = DL_FETCH_SYMBOL(handle, ZSTR_VAL(mangled_name));
zend_string_release(mangled_name);
if (!addr) {
- zend_throw_error(zend_ffi_exception_ce, "Failed resolving C function '%s'", ZSTR_VAL(name));
+ zend_throw_error(zend_ffi_exception_ce, "Failed resolving C function '%pS'", name);
goto cleanup;
}
sym->addr = addr;
@@ -3452,9 +3452,9 @@ static zend_ffi *zend_ffi_load(const char *filename, bool preload) /* {{{ */
addr = DL_FETCH_SYMBOL(handle, ZSTR_VAL(name));
if (!addr) {
if (preload) {
- zend_error(E_WARNING, "FFI: failed pre-loading '%s', cannot resolve C variable '%s'", filename, ZSTR_VAL(name));
+ zend_error(E_WARNING, "FFI: failed pre-loading '%s', cannot resolve C variable '%pS'", filename, name);
} else {
- zend_throw_error(zend_ffi_exception_ce, "Failed resolving C variable '%s'", ZSTR_VAL(name));
+ zend_throw_error(zend_ffi_exception_ce, "Failed resolving C variable '%pS'", name);
}
if (lib) {
DL_UNLOAD(handle);
@@ -3469,9 +3469,9 @@ static zend_ffi *zend_ffi_load(const char *filename, bool preload) /* {{{ */
zend_string_release(mangled_name);
if (!addr) {
if (preload) {
- zend_error(E_WARNING, "failed pre-loading '%s', cannot resolve C function '%s'", filename, ZSTR_VAL(name));
+ zend_error(E_WARNING, "failed pre-loading '%s', cannot resolve C function '%pS'", filename, name);
} else {
- zend_throw_error(zend_ffi_exception_ce, "Failed resolving C function '%s'", ZSTR_VAL(name));
+ zend_throw_error(zend_ffi_exception_ce, "Failed resolving C function '%pS'", name);
}
if (lib) {
DL_UNLOAD(handle);
@@ -3492,7 +3492,7 @@ static zend_ffi *zend_ffi_load(const char *filename, bool preload) /* {{{ */
zend_ffi_type_dtor(type);
}
} else {
- zend_error(E_WARNING, "FFI: failed pre-loading '%s', redefinition of '%s'", filename, ZSTR_VAL(name));
+ zend_error(E_WARNING, "FFI: failed pre-loading '%s', redefinition of '%pS'", filename, name);
if (lib) {
DL_UNLOAD(handle);
}
@@ -3517,7 +3517,7 @@ static zend_ffi *zend_ffi_load(const char *filename, bool preload) /* {{{ */
zend_ffi_type_dtor(type);
}
} else {
- zend_error(E_WARNING, "FFI: failed pre-loading '%s', redefinition of '%s %s'", filename, zend_ffi_tag_kind_name[tag->kind], ZSTR_VAL(name));
+ zend_error(E_WARNING, "FFI: failed pre-loading '%s', redefinition of '%s %pS'", filename, zend_ffi_tag_kind_name[tag->kind], name);
if (lib) {
DL_UNLOAD(handle);
}
@@ -3649,7 +3649,7 @@ ZEND_METHOD(FFI, scope) /* {{{ */
}
if (!scope) {
- zend_throw_error(zend_ffi_exception_ce, "Failed loading scope '%s'", ZSTR_VAL(scope_name));
+ zend_throw_error(zend_ffi_exception_ce, "Failed loading scope '%pS'", scope_name);
RETURN_THROWS();
}
@@ -3675,7 +3675,6 @@ void zend_ffi_cleanup_dcl(zend_ffi_dcl *dcl) /* {{{ */
static void zend_ffi_throw_parser_error(const char *format, ...) /* {{{ */
{
va_list va;
- char *message = NULL;
if (FFI_G(parse_failed)) {
/* An error was already reported, parsing only continues to unwind cleanly */
@@ -3683,15 +3682,15 @@ static void zend_ffi_throw_parser_error(const char *format, ...) /* {{{ */
}
va_start(va, format);
- zend_vspprintf(&message, 0, format, va);
+ zend_string *message = zend_vstrpprintf(0, format, va);
if (EG(current_execute_data)) {
- zend_throw_exception(zend_ffi_parser_exception_ce, message, 0);
+ zend_throw_exception_ex(zend_ffi_parser_exception_ce, 0, "%pS", message);
} else {
- zend_error(E_WARNING, "FFI Parser: %s", message);
+ zend_error(E_WARNING, "FFI Parser: %pS", message);
}
- efree(message);
+ zend_string_release(message);
va_end(va);
}
/* }}} */
@@ -3716,11 +3715,11 @@ static zend_result zend_ffi_validate_incomplete_type(const zend_ffi_type *type,
ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(FFI_G(tags), key, tag) {
if (ZEND_FFI_TYPE(tag->type) == type) {
if (type->kind == ZEND_FFI_TYPE_ENUM) {
- zend_ffi_throw_parser_error("Incomplete enum \"%s\" at line %d", ZSTR_VAL(key), FFI_G(line));
+ zend_ffi_throw_parser_error("Incomplete enum \"%pS\" at line %d", key, FFI_G(line));
} else if (type->attr & ZEND_FFI_ATTR_UNION) {
- zend_ffi_throw_parser_error("Incomplete union \"%s\" at line %d", ZSTR_VAL(key), FFI_G(line));
+ zend_ffi_throw_parser_error("Incomplete union \"%pS\" at line %d", key, FFI_G(line));
} else {
- zend_ffi_throw_parser_error("Incomplete struct \"%s\" at line %d", ZSTR_VAL(key), FFI_G(line));
+ zend_ffi_throw_parser_error("Incomplete struct \"%pS\" at line %d", key, FFI_G(line));
}
return FAILURE;
}
@@ -3732,7 +3731,7 @@ static zend_result zend_ffi_validate_incomplete_type(const zend_ffi_type *type,
ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(FFI_G(symbols), key, sym) {
if (type == ZEND_FFI_TYPE(sym->type)) {
- zend_ffi_throw_parser_error("Incomplete C type %s at line %d", ZSTR_VAL(key), FFI_G(line));
+ zend_ffi_throw_parser_error("Incomplete C type %pS at line %d", key, FFI_G(line));
return FAILURE;
}
} ZEND_HASH_FOREACH_END();
@@ -5119,14 +5118,14 @@ static char *zend_ffi_parse_directives(const char *filename, char *code_pos, cha
static ZEND_COLD zend_function *zend_fake_get_constructor(zend_object *object) /* {{{ */
{
- zend_throw_error(NULL, "Instantiation of %s is not allowed", ZSTR_VAL(object->ce->name));
+ zend_throw_error(NULL, "Instantiation of %pS is not allowed", object->ce->name);
return NULL;
}
/* }}} */
static ZEND_COLD zend_never_inline void zend_bad_array_access(zend_class_entry *ce) /* {{{ */
{
- zend_throw_error(NULL, "Cannot use object of type %s as array", ZSTR_VAL(ce->name));
+ zend_throw_error(NULL, "Cannot use object of type %pS as array", ce->name);
}
/* }}} */
@@ -5158,7 +5157,7 @@ static ZEND_COLD void zend_fake_unset_dimension(zend_object *obj, zval *offset)
static ZEND_COLD zend_never_inline void zend_bad_property_access(zend_class_entry *ce) /* {{{ */
{
- zend_throw_error(NULL, "Cannot access property of object of type %s", ZSTR_VAL(ce->name));
+ zend_throw_error(NULL, "Cannot access property of object of type %pS", ce->name);
}
/* }}} */
@@ -5198,7 +5197,7 @@ static zval *zend_fake_get_property_ptr_ptr(zend_object *obj, zend_string *membe
static ZEND_COLD zend_function *zend_fake_get_method(zend_object **obj_ptr, zend_string *method_name, const zval *key) /* {{{ */
{
zend_class_entry *ce = (*obj_ptr)->ce;
- zend_throw_error(NULL, "Object of type %s does not support method calls", ZSTR_VAL(ce->name));
+ zend_throw_error(NULL, "Object of type %pS does not support method calls", ce->name);
return NULL;
}
/* }}} */
@@ -5759,18 +5758,17 @@ void zend_ffi_parser_error(const char *format, ...) /* {{{ */
{
if (!FFI_G(parse_failed)) {
va_list va;
- char *message = NULL;
va_start(va, format);
- zend_vspprintf(&message, 0, format, va);
+ zend_string *message = zend_vstrpprintf(0, format, va);
if (EG(current_execute_data)) {
- zend_throw_exception(zend_ffi_parser_exception_ce, message, 0);
+ zend_throw_exception_ex(zend_ffi_parser_exception_ce, 0, "%pS", message);
} else {
- zend_error(E_WARNING, "FFI Parser: %s", message);
+ zend_error(E_WARNING, "FFI Parser: %pS", message);
}
- efree(message);
+ zend_string_release(message);
va_end(va);
}
@@ -6232,7 +6230,7 @@ void zend_ffi_add_anonymous_field(zend_ffi_dcl *struct_dcl, zend_ffi_dcl *field_
if (!zend_hash_add_ptr(&struct_type->record.fields, key, new_field)) {
zend_ffi_type_dtor(new_field->type);
pefree(new_field, FFI_G(persistent));
- zend_ffi_parser_error("Duplicate field name \"%s\" at line %d", ZSTR_VAL(key), FFI_G(line));
+ zend_ffi_parser_error("Duplicate field name \"%pS\" at line %d", key, FFI_G(line));
return;
}
} else {