From 36e214c88b6bdaeecc883b3a80cf7fb3511ec0ac Mon Sep 17 00:00:00 2001 From: Xinchen Hui Date: Fri, 25 Apr 2014 10:27:23 +0800 Subject: [PATCH] Fixed refcount of dbh (we don't need another refcount anymore) --- ext/pdo/pdo_dbh.c | 27 ++++++--------------------- ext/pdo/pdo_stmt.c | 7 ++----- 2 files changed, 8 insertions(+), 26 deletions(-) diff --git a/ext/pdo/pdo_dbh.c b/ext/pdo/pdo_dbh.c index 90ee44f108..f75738cab3 100644 --- a/ext/pdo/pdo_dbh.c +++ b/ext/pdo/pdo_dbh.c @@ -579,9 +579,8 @@ static PHP_METHOD(PDO, prepare) stmt->default_fetch_type = dbh->default_fetch_type; stmt->dbh = dbh; /* give it a reference to me */ - Z_ADDREF_P(getThis()); - php_pdo_dbh_addref(dbh TSRMLS_CC); - ZVAL_COPY_VALUE(&stmt->database_object_handle, getThis()); + ZVAL_OBJ(&stmt->database_object_handle, &dbh->std); + Z_ADDREF(stmt->database_object_handle); /* we haven't created a lazy object yet */ ZVAL_UNDEF(&stmt->lazy_object_ref); @@ -1118,9 +1117,8 @@ static PHP_METHOD(PDO, query) stmt->active_query_stringlen = statement_len; stmt->dbh = dbh; /* give it a reference to me */ - Z_ADDREF_P(getThis()); - php_pdo_dbh_addref(dbh TSRMLS_CC); - stmt->database_object_handle = *getThis(); + ZVAL_OBJ(&stmt->database_object_handle, &dbh->std); + Z_ADDREF(stmt->database_object_handle); /* we haven't created a lazy object yet */ ZVAL_UNDEF(&stmt->lazy_object_ref); @@ -1150,7 +1148,7 @@ static PHP_METHOD(PDO, query) PDO_HANDLE_STMT_ERR(); } else { PDO_HANDLE_DBH_ERR(); - zval_dtor(return_value); + zval_ptr_dtor(return_value); } RETURN_FALSE; @@ -1507,11 +1505,8 @@ static void dbh_free(pdo_dbh_t *dbh TSRMLS_DC) { int i; - if (--dbh->refcount) - return; - if (dbh->query_stmt) { - zval_dtor(&dbh->query_stmt_zval); + zval_ptr_dtor(&dbh->query_stmt_zval); dbh->query_stmt = NULL; } @@ -1547,16 +1542,6 @@ static void dbh_free(pdo_dbh_t *dbh TSRMLS_DC) //???pefree(dbh, dbh->is_persistent); } -PDO_API void php_pdo_dbh_addref(pdo_dbh_t *dbh TSRMLS_DC) -{ - dbh->refcount++; -} - -PDO_API void php_pdo_dbh_delref(pdo_dbh_t *dbh TSRMLS_DC) -{ - dbh_free(dbh TSRMLS_CC); -} - static void pdo_dbh_free_storage(zend_object *std TSRMLS_DC) { pdo_dbh_t *dbh = php_pdo_dbh_fetch_object(std); diff --git a/ext/pdo/pdo_stmt.c b/ext/pdo/pdo_stmt.c index 65ac8a8359..689de9bd03 100644 --- a/ext/pdo/pdo_stmt.c +++ b/ext/pdo/pdo_stmt.c @@ -2271,8 +2271,6 @@ static zend_object *dbstmt_clone_obj(zval *zobject TSRMLS_DC) zend_objects_clone_members(&stmt->std, &old_stmt->std TSRMLS_CC); - ZVAL_COPY(&stmt->database_object_handle, &old_stmt->database_object_handle); - return &stmt->std; } @@ -2352,9 +2350,8 @@ static void free_statement(pdo_stmt_t *stmt TSRMLS_DC) do_fetch_opt_finish(stmt, 1 TSRMLS_CC); - zval_ptr_dtor(&stmt->database_object_handle); - if (stmt->dbh) { - php_pdo_dbh_delref(stmt->dbh TSRMLS_CC); + if (!ZVAL_IS_UNDEF(&stmt->database_object_handle)) { + zval_ptr_dtor(&stmt->database_object_handle); } zend_object_std_dtor(&stmt->std TSRMLS_CC); } -- 2.50.1