]> granicus.if.org Git - php/commitdiff
Fixed refcount of dbh (we don't need another refcount anymore)
authorXinchen Hui <laruence@gmail.com>
Fri, 25 Apr 2014 02:27:23 +0000 (10:27 +0800)
committerXinchen Hui <laruence@gmail.com>
Fri, 25 Apr 2014 02:27:23 +0000 (10:27 +0800)
ext/pdo/pdo_dbh.c
ext/pdo/pdo_stmt.c

index 90ee44f1084733b8efa36974c653e97072330cf5..f75738cab3785d490b55bb5228c847546715405b 100644 (file)
@@ -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);
index 65ac8a835935018e23947e74c274a255a932088b..689de9bd032b7bcbb6b62047dd9e4e191995f45a 100644 (file)
@@ -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);
 }