ext/pdo: Refactor pdo_stmt_construct() to use newer FCI/FCC API (#12142)

This commit is contained in:
George Peter Banyard 2023-09-08 12:32:44 +01:00 committed by GitHub
parent e04ddb32c8
commit 7723718502
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -455,7 +455,7 @@ static zval *pdo_stmt_instantiate(pdo_dbh_t *dbh, zval *object, zend_class_entry
return object; return object;
} /* }}} */ } /* }}} */
static void pdo_stmt_construct(zend_execute_data *execute_data, pdo_stmt_t *stmt, zval *object, zend_class_entry *dbstmt_ce, zval *ctor_args) /* {{{ */ static void pdo_stmt_construct(pdo_stmt_t *stmt, zval *object, zend_class_entry *dbstmt_ce, HashTable *ctor_args)
{ {
zval query_string; zval query_string;
zend_string *key; zend_string *key;
@ -466,32 +466,9 @@ static void pdo_stmt_construct(zend_execute_data *execute_data, pdo_stmt_t *stmt
zend_string_release_ex(key, 0); zend_string_release_ex(key, 0);
if (dbstmt_ce->constructor) { if (dbstmt_ce->constructor) {
zend_fcall_info fci; zend_call_known_function(dbstmt_ce->constructor, Z_OBJ_P(object), Z_OBJCE_P(object), NULL, 0, NULL, ctor_args);
zend_fcall_info_cache fcc;
zval retval;
fci.size = sizeof(zend_fcall_info);
ZVAL_UNDEF(&fci.function_name);
fci.object = Z_OBJ_P(object);
fci.retval = &retval;
fci.param_count = 0;
fci.params = NULL;
fci.named_params = NULL;
zend_fcall_info_args(&fci, ctor_args);
fcc.function_handler = dbstmt_ce->constructor;
fcc.called_scope = Z_OBJCE_P(object);
fcc.object = Z_OBJ_P(object);
if (zend_call_function(&fci, &fcc) != FAILURE) {
zval_ptr_dtor(&retval);
}
zend_fcall_info_args_clear(&fci, 1);
} }
} }
/* }}} */
/* {{{ Prepares a statement for execution and returns a statement object */ /* {{{ Prepares a statement for execution and returns a statement object */
PHP_METHOD(PDO, prepare) PHP_METHOD(PDO, prepare)
@ -572,7 +549,11 @@ PHP_METHOD(PDO, prepare)
ZVAL_UNDEF(&stmt->lazy_object_ref); ZVAL_UNDEF(&stmt->lazy_object_ref);
if (dbh->methods->preparer(dbh, statement, stmt, options)) { if (dbh->methods->preparer(dbh, statement, stmt, options)) {
pdo_stmt_construct(execute_data, stmt, return_value, dbstmt_ce, &ctor_args); if (Z_TYPE(ctor_args) == IS_ARRAY) {
pdo_stmt_construct(stmt, return_value, dbstmt_ce, Z_ARRVAL(ctor_args));
} else {
pdo_stmt_construct(stmt, return_value, dbstmt_ce, /* ctor_args */ NULL);
}
return; return;
} }
@ -1141,7 +1122,11 @@ PHP_METHOD(PDO, query)
stmt->executed = 1; stmt->executed = 1;
} }
if (ret) { if (ret) {
pdo_stmt_construct(execute_data, stmt, return_value, dbh->def_stmt_ce, &dbh->def_stmt_ctor_args); if (Z_TYPE(dbh->def_stmt_ctor_args) == IS_ARRAY) {
pdo_stmt_construct(stmt, return_value, dbh->def_stmt_ce, Z_ARRVAL(dbh->def_stmt_ctor_args));
} else {
pdo_stmt_construct(stmt, return_value, dbh->def_stmt_ce, /* ctor_args */ NULL);
}
return; return;
} }
} }