Skip to content

Commit fba0b18

Browse files
committed
ext/pdo: Remove mostly useless retval field in statement struct
1 parent bd83f86 commit fba0b18

File tree

2 files changed

+18
-19
lines changed

2 files changed

+18
-19
lines changed

ext/pdo/pdo_stmt.c

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,6 @@ static bool do_fetch_class_prepare(pdo_stmt_t *stmt) /* {{{ */
625625

626626
if (ce->constructor) {
627627
ZVAL_UNDEF(&fci->function_name);
628-
fci->retval = &stmt->fetch.cls.retval;
629628
fci->param_count = 0;
630629
fci->params = NULL;
631630

@@ -839,18 +838,18 @@ static bool do_fetch(pdo_stmt_t *stmt, zval *return_value, enum pdo_fetch_type h
839838
}
840839
}
841840
if (ce->constructor && (flags & PDO_FETCH_PROPS_LATE)) {
841+
zval retval_constructor_call;
842+
stmt->fetch.cls.fci.retval = &retval_constructor_call;
842843
stmt->fetch.cls.fci.object = Z_OBJ_P(return_value);
843844
stmt->fetch.cls.fcc.object = Z_OBJ_P(return_value);
844-
if (zend_call_function(&stmt->fetch.cls.fci, &stmt->fetch.cls.fcc) == FAILURE) {
845-
/* TODO Error? */
846-
pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "could not call class constructor");
847-
return 0;
848-
} else {
849-
if (!Z_ISUNDEF(stmt->fetch.cls.retval)) {
850-
zval_ptr_dtor(&stmt->fetch.cls.retval);
851-
ZVAL_UNDEF(&stmt->fetch.cls.retval);
852-
}
845+
zend_call_function(&stmt->fetch.cls.fci, &stmt->fetch.cls.fcc);
846+
if (Z_TYPE(retval_constructor_call) == IS_UNDEF) {
847+
/* Exception has happened */
848+
zval_ptr_dtor(return_value);
849+
return false;
853850
}
851+
zval_ptr_dtor(&retval_constructor_call);
852+
ZVAL_UNDEF(stmt->fetch.cls.fci.retval);
854853
}
855854
}
856855
break;
@@ -985,17 +984,18 @@ static bool do_fetch(pdo_stmt_t *stmt, zval *return_value, enum pdo_fetch_type h
985984
switch (how) {
986985
case PDO_FETCH_CLASS:
987986
if (ce->constructor && !(flags & (PDO_FETCH_PROPS_LATE | PDO_FETCH_SERIALIZE))) {
987+
zval retval_constructor_call;
988+
stmt->fetch.cls.fci.retval = &retval_constructor_call;
988989
stmt->fetch.cls.fci.object = Z_OBJ_P(return_value);
989990
stmt->fetch.cls.fcc.object = Z_OBJ_P(return_value);
990-
if (zend_call_function(&stmt->fetch.cls.fci, &stmt->fetch.cls.fcc) == FAILURE) {
991-
/* TODO Error? */
992-
pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "could not call class constructor");
993-
return 0;
994-
} else {
995-
if (!Z_ISUNDEF(stmt->fetch.cls.retval)) {
996-
zval_ptr_dtor(&stmt->fetch.cls.retval);
997-
}
991+
zend_call_function(&stmt->fetch.cls.fci, &stmt->fetch.cls.fcc);
992+
if (Z_TYPE(retval_constructor_call) == IS_UNDEF) {
993+
/* Exception has happened */
994+
zval_ptr_dtor(return_value);
995+
return false;
998996
}
997+
zval_ptr_dtor(&retval_constructor_call);
998+
ZVAL_UNDEF(stmt->fetch.cls.fci.retval);
999999
}
10001000
if (flags & PDO_FETCH_CLASSTYPE) {
10011001
do_fetch_opt_finish(stmt, 0);

ext/pdo/php_pdo_driver.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,6 @@ struct _pdo_stmt_t {
615615
zval ctor_args; /* freed */
616616
zend_fcall_info fci;
617617
zend_fcall_info_cache fcc;
618-
zval retval;
619618
zend_class_entry *ce;
620619
} cls;
621620
struct {

0 commit comments

Comments
 (0)