diff --git a/ext/pdo/pdo_dbh.c b/ext/pdo/pdo_dbh.c index 377615f2fe0..10af61fa2b0 100644 --- a/ext/pdo/pdo_dbh.c +++ b/ext/pdo/pdo_dbh.c @@ -67,9 +67,9 @@ void pdo_throw_exception(unsigned int driver_errcode, char *driver_errmsg, pdo_e PDO_API bool php_pdo_stmt_valid_db_obj_handle(const pdo_stmt_t *stmt) { - return !Z_ISUNDEF(stmt->database_object_handle) - && IS_OBJ_VALID(EG(objects_store).object_buckets[Z_OBJ_HANDLE(stmt->database_object_handle)]) - && !(OBJ_FLAGS(Z_OBJ(stmt->database_object_handle)) & IS_OBJ_FREE_CALLED); + return stmt->database_object_handle != NULL + && IS_OBJ_VALID(EG(objects_store).object_buckets[stmt->database_object_handle->handle]) + && !(OBJ_FLAGS(stmt->database_object_handle) & IS_OBJ_FREE_CALLED); } void pdo_raise_impl_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, pdo_error_type sqlstate, const char *supp) /* {{{ */ @@ -657,7 +657,8 @@ PHP_METHOD(PDO, prepare) stmt->default_fetch_type = dbh->default_fetch_type; stmt->dbh = dbh; /* give it a reference to me */ - ZVAL_OBJ_COPY(&stmt->database_object_handle, &dbh_obj->std); + GC_ADDREF(&dbh_obj->std); + stmt->database_object_handle = &dbh_obj->std; /* we haven't created a lazy object yet */ ZVAL_UNDEF(&stmt->lazy_object_ref); @@ -1222,7 +1223,8 @@ PHP_METHOD(PDO, query) stmt->default_fetch_type = dbh->default_fetch_type; stmt->dbh = dbh; /* give it a reference to me */ - ZVAL_OBJ_COPY(&stmt->database_object_handle, &dbh_obj->std); + GC_ADDREF(&dbh_obj->std); + stmt->database_object_handle = &dbh_obj->std; /* we haven't created a lazy object yet */ ZVAL_UNDEF(&stmt->lazy_object_ref); @@ -1252,8 +1254,8 @@ PHP_METHOD(PDO, query) /* something broke */ dbh->query_stmt = stmt; ZVAL_OBJ(&dbh->query_stmt_zval, Z_OBJ_P(return_value)); - Z_DELREF(stmt->database_object_handle); - ZVAL_UNDEF(&stmt->database_object_handle); + GC_DELREF(stmt->database_object_handle); + stmt->database_object_handle = NULL; PDO_HANDLE_STMT_ERR(); } else { PDO_HANDLE_DBH_ERR(); diff --git a/ext/pdo/pdo_stmt.c b/ext/pdo/pdo_stmt.c index 88b7af51b2d..cb9fdf957af 100644 --- a/ext/pdo/pdo_stmt.c +++ b/ext/pdo/pdo_stmt.c @@ -2021,7 +2021,7 @@ static zend_function *dbstmt_method_get(zend_object **object_pp, zend_string *me /* not a pre-defined method, nor a user-defined method; check * the driver specific methods */ if (!stmt->dbh->cls_methods[PDO_DBH_DRIVER_METHOD_KIND_STMT]) { - if (!pdo_hash_methods(Z_PDO_OBJECT_P(&stmt->database_object_handle), + if (!pdo_hash_methods(php_pdo_dbh_fetch_object(stmt->database_object_handle), PDO_DBH_DRIVER_METHOD_KIND_STMT) || !stmt->dbh->cls_methods[PDO_DBH_DRIVER_METHOD_KIND_STMT]) { goto out; @@ -2048,7 +2048,7 @@ static HashTable *dbstmt_get_gc(zend_object *object, zval **gc_data, int *gc_cou enum pdo_fetch_type default_fetch_mode = stmt->default_fetch_type & ~PDO_FETCH_FLAGS; zend_get_gc_buffer *gc_buffer = zend_get_gc_buffer_create(); - zend_get_gc_buffer_add_zval(gc_buffer, &stmt->database_object_handle); + zend_get_gc_buffer_add_obj(gc_buffer, stmt->database_object_handle); if (default_fetch_mode == PDO_FETCH_INTO) { zend_get_gc_buffer_add_obj(gc_buffer, stmt->fetch.into); } else if (default_fetch_mode == PDO_FETCH_CLASS) { @@ -2107,8 +2107,9 @@ PDO_API void php_pdo_free_statement(pdo_stmt_t *stmt) do_fetch_opt_finish(stmt, 1); - if (!Z_ISUNDEF(stmt->database_object_handle)) { - zval_ptr_dtor(&stmt->database_object_handle); + if (stmt->database_object_handle != NULL) { + OBJ_RELEASE(stmt->database_object_handle); + stmt->database_object_handle = NULL; } zend_object_std_dtor(&stmt->std); } diff --git a/ext/pdo/php_pdo_driver.h b/ext/pdo/php_pdo_driver.h index cb483a6bf6b..94e7c805bfd 100644 --- a/ext/pdo/php_pdo_driver.h +++ b/ext/pdo/php_pdo_driver.h @@ -578,7 +578,7 @@ struct _pdo_stmt_t { struct pdo_column_data *columns; /* we want to keep the dbh alive while we live, so we own a reference */ - zval database_object_handle; + zend_object *database_object_handle; pdo_dbh_t *dbh; /* keep track of bound input parameters. Some drivers support diff --git a/ext/pdo_pgsql/pgsql_driver.c b/ext/pdo_pgsql/pgsql_driver.c index c7944373fa7..1a46cafd8f5 100644 --- a/ext/pdo_pgsql/pgsql_driver.c +++ b/ext/pdo_pgsql/pgsql_driver.c @@ -200,13 +200,13 @@ const php_stream_ops pdo_pgsql_lob_stream_ops = { NULL }; -php_stream *pdo_pgsql_create_lob_stream(zval *dbh, int lfd, Oid oid) +php_stream *pdo_pgsql_create_lob_stream(zend_object *dbh, int lfd, Oid oid) { php_stream *stm; struct pdo_pgsql_lob_self *self = ecalloc(1, sizeof(*self)); - pdo_pgsql_db_handle *H = (pdo_pgsql_db_handle *)(Z_PDO_DBH_P(dbh))->driver_data; + pdo_pgsql_db_handle *H = (pdo_pgsql_db_handle *)(php_pdo_dbh_fetch_inner(dbh))->driver_data; - ZVAL_COPY_VALUE(&self->dbh, dbh); + ZVAL_OBJ(&self->dbh, dbh); self->lfd = lfd; self->oid = oid; self->conn = H->server; @@ -214,7 +214,7 @@ php_stream *pdo_pgsql_create_lob_stream(zval *dbh, int lfd, Oid oid) stm = php_stream_alloc(&pdo_pgsql_lob_stream_ops, self, 0, "r+b"); if (stm) { - Z_ADDREF_P(dbh); + GC_ADDREF(dbh); zend_hash_index_add_ptr(H->lob_streams, php_stream_get_resource_id(stm), stm->res); return stm; } @@ -1116,7 +1116,7 @@ void pgsqlLOBOpen_internal(INTERNAL_FUNCTION_PARAMETERS) lfd = lo_open(H->server, oid, mode); if (lfd >= 0) { - php_stream *stream = pdo_pgsql_create_lob_stream(ZEND_THIS, lfd, oid); + php_stream *stream = pdo_pgsql_create_lob_stream(Z_OBJ_P(ZEND_THIS), lfd, oid); if (stream) { php_stream_to_zval(stream, return_value); return; diff --git a/ext/pdo_pgsql/pgsql_statement.c b/ext/pdo_pgsql/pgsql_statement.c index 1d5e188cf54..3485bd8df00 100644 --- a/ext/pdo_pgsql/pgsql_statement.c +++ b/ext/pdo_pgsql/pgsql_statement.c @@ -661,7 +661,7 @@ static int pgsql_stmt_get_col(pdo_stmt_t *stmt, int colno, zval *result, enum pd /* If column was bound as LOB, return a stream. */ int loid = lo_open(S->H->server, oid, INV_READ); if (loid >= 0) { - php_stream *stream = pdo_pgsql_create_lob_stream(&stmt->database_object_handle, loid, oid); + php_stream *stream = pdo_pgsql_create_lob_stream(stmt->database_object_handle, loid, oid); if (stream) { php_stream_to_zval(stream, result); return 1; diff --git a/ext/pdo_pgsql/php_pdo_pgsql_int.h b/ext/pdo_pgsql/php_pdo_pgsql_int.h index 7dee249cbb1..881b4e70465 100644 --- a/ext/pdo_pgsql/php_pdo_pgsql_int.h +++ b/ext/pdo_pgsql/php_pdo_pgsql_int.h @@ -112,7 +112,7 @@ enum pdo_pgsql_specific_constants { PGSQL_TRANSACTION_UNKNOWN = PQTRANS_UNKNOWN }; -php_stream *pdo_pgsql_create_lob_stream(zval *pdh, int lfd, Oid oid); +php_stream *pdo_pgsql_create_lob_stream(zend_object *pdh, int lfd, Oid oid); extern const php_stream_ops pdo_pgsql_lob_stream_ops; void pdo_pgsql_cleanup_notice_callback(pdo_pgsql_db_handle *H);