Skip to content

Commit 842f8ef

Browse files
committed
ext/pdo: Convert FETCH_INTO zval to a zend_object pointer
1 parent 8ed0d7f commit 842f8ef

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

ext/pdo/pdo_stmt.c

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -836,14 +836,14 @@ static bool do_fetch(pdo_stmt_t *stmt, zval *return_value, enum pdo_fetch_type h
836836

837837
case PDO_FETCH_INTO:
838838
/* TODO: Make this an assertion and ensure this is true higher up? */
839-
if (Z_ISUNDEF(stmt->fetch.into)) {
839+
if (stmt->fetch.into == NULL) {
840840
/* TODO ArgumentCountError? */
841841
pdo_raise_impl_error(stmt->dbh, stmt, "HY000", "No fetch-into object specified.");
842842
return 0;
843843
break;
844844
}
845845

846-
ZVAL_COPY(return_value, &stmt->fetch.into);
846+
ZVAL_OBJ_COPY(return_value, stmt->fetch.into);
847847

848848
if (Z_OBJ_P(return_value)->ce == ZEND_STANDARD_CLASS_DEF_PTR) {
849849
how = PDO_FETCH_OBJ;
@@ -1655,9 +1655,9 @@ bool pdo_stmt_setup_fetch_mode(pdo_stmt_t *stmt, zend_long mode, uint32_t mode_a
16551655

16561656
switch (stmt->default_fetch_type) {
16571657
case PDO_FETCH_INTO:
1658-
if (!Z_ISUNDEF(stmt->fetch.into)) {
1659-
zval_ptr_dtor(&stmt->fetch.into);
1660-
ZVAL_UNDEF(&stmt->fetch.into);
1658+
if (stmt->fetch.into) {
1659+
OBJ_RELEASE(stmt->fetch.into);
1660+
stmt->fetch.into = NULL;
16611661
}
16621662
break;
16631663
default:
@@ -1786,7 +1786,8 @@ bool pdo_stmt_setup_fetch_mode(pdo_stmt_t *stmt, zend_long mode, uint32_t mode_a
17861786
return false;
17871787
}
17881788

1789-
ZVAL_COPY(&stmt->fetch.into, &args[0]);
1789+
GC_ADDREF(Z_OBJ(args[0]));
1790+
stmt->fetch.into = Z_OBJ(args[0]);
17901791
break;
17911792
default:
17921793
zend_argument_value_error(mode_arg_num, "must be one of the PDO::FETCH_* constants");
@@ -2030,7 +2031,11 @@ static HashTable *dbstmt_get_gc(zend_object *object, zval **gc_data, int *gc_cou
20302031

20312032
zend_get_gc_buffer *gc_buffer = zend_get_gc_buffer_create();
20322033
zend_get_gc_buffer_add_zval(gc_buffer, &stmt->database_object_handle);
2033-
zend_get_gc_buffer_add_zval(gc_buffer, &stmt->fetch.into);
2034+
if ((stmt->default_fetch_type & PDO_FETCH_INTO) == PDO_FETCH_INTO) {
2035+
zend_get_gc_buffer_add_obj(gc_buffer, stmt->fetch.into);
2036+
} else if ((stmt->default_fetch_type & PDO_FETCH_CLASS) == PDO_FETCH_CLASS) {
2037+
zend_get_gc_buffer_add_zval(gc_buffer, &stmt->fetch.cls.ctor_args);
2038+
}
20342039
zend_get_gc_buffer_use(gc_buffer, gc_data, gc_count);
20352040

20362041
/**
@@ -2077,9 +2082,9 @@ PDO_API void php_pdo_free_statement(pdo_stmt_t *stmt)
20772082

20782083
pdo_stmt_reset_columns(stmt);
20792084

2080-
if (!Z_ISUNDEF(stmt->fetch.into) && stmt->default_fetch_type == PDO_FETCH_INTO) {
2081-
zval_ptr_dtor(&stmt->fetch.into);
2082-
ZVAL_UNDEF(&stmt->fetch.into);
2085+
if (stmt->fetch.into && stmt->default_fetch_type == PDO_FETCH_INTO) {
2086+
OBJ_RELEASE(stmt->fetch.into);
2087+
stmt->fetch.into = NULL;
20832088
}
20842089

20852090
do_fetch_opt_finish(stmt, 1);
@@ -2168,7 +2173,6 @@ static void pdo_stmt_iter_move_forwards(zend_object_iterator *iter)
21682173

21692174
if (!do_fetch(stmt, &I->fetch_ahead, PDO_FETCH_USE_DEFAULT,
21702175
PDO_FETCH_ORI_NEXT, /* offset */ 0, NULL)) {
2171-
21722176
PDO_HANDLE_STMT_ERR();
21732177
I->key = (zend_ulong)-1;
21742178
ZVAL_UNDEF(&I->fetch_ahead);

ext/pdo/php_pdo_driver.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ struct _pdo_stmt_t {
621621
zval dummy; /* This exists due to alignment reasons with fetch.into and fetch.cls.ctor_args */
622622
zend_fcall_info_cache fcc;
623623
} func;
624-
zval into;
624+
zend_object *into;
625625
} fetch;
626626

627627
/* used by the query parser for driver specific

0 commit comments

Comments
 (0)