Skip to content

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

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

Merged
merged 1 commit into from
Sep 8, 2023
Merged
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
39 changes: 12 additions & 27 deletions ext/pdo/pdo_dbh.c
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ static zval *pdo_stmt_instantiate(pdo_dbh_t *dbh, zval *object, zend_class_entry
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;
zend_string *key;
Expand All @@ -466,32 +466,9 @@ static void pdo_stmt_construct(zend_execute_data *execute_data, pdo_stmt_t *stmt
zend_string_release_ex(key, 0);

if (dbstmt_ce->constructor) {
zend_fcall_info fci;
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);
zend_call_known_function(dbstmt_ce->constructor, Z_OBJ_P(object), Z_OBJCE_P(object), NULL, 0, NULL, ctor_args);
}
}
/* }}} */

/* {{{ Prepares a statement for execution and returns a statement object */
PHP_METHOD(PDO, prepare)
Expand Down Expand Up @@ -572,7 +549,11 @@ PHP_METHOD(PDO, prepare)
ZVAL_UNDEF(&stmt->lazy_object_ref);

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;
}

Expand Down Expand Up @@ -1141,7 +1122,11 @@ PHP_METHOD(PDO, query)
stmt->executed = 1;
}
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;
}
}
Expand Down