Skip to content

Commit 5eae6d1

Browse files
committed
Don't store the object zval directly
1 parent c0d910d commit 5eae6d1

File tree

2 files changed

+13
-22
lines changed

2 files changed

+13
-22
lines changed

ext/sqlite3/php_sqlite3_structs.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ typedef struct _php_sqlite3_result_object php_sqlite3_result;
9393
struct _php_sqlite3_result_object {
9494
php_sqlite3_db_object *db_obj;
9595
php_sqlite3_stmt *stmt_obj;
96-
zval stmt_obj_zval;
9796

9897
/* Cache of column names to speed up repeated fetchArray(SQLITE3_ASSOC) calls.
9998
* Cache is cleared on reset() and finalize() calls. */
@@ -114,7 +113,6 @@ static inline php_sqlite3_result *php_sqlite3_result_from_obj(zend_object *obj)
114113
struct _php_sqlite3_stmt_object {
115114
sqlite3_stmt *stmt;
116115
php_sqlite3_db_object *db_obj;
117-
zval db_obj_zval;
118116

119117
int initialised;
120118

ext/sqlite3/sqlite3.c

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ ZEND_DECLARE_MODULE_GLOBALS(sqlite3)
3535
static PHP_GINIT_FUNCTION(sqlite3);
3636
static int php_sqlite3_authorizer(void *autharg, int action, const char *arg1, const char *arg2, const char *arg3, const char *arg4);
3737
static void sqlite3_param_dtor(zval *data);
38-
static int php_sqlite3_compare_stmt_zval_free(php_sqlite3_stmt **stmt_obj_ptr, zval *statement);
38+
static int php_sqlite3_compare_stmt_free(php_sqlite3_stmt **stmt_obj_ptr, sqlite3_stmt *statement);
3939

4040
#define SQLITE3_CHECK_INITIALIZED(db_obj, member, class_name) \
4141
if (!(db_obj) || !(member)) { \
@@ -525,7 +525,7 @@ PHP_METHOD(SQLite3, prepare)
525525
object_init_ex(return_value, php_sqlite3_stmt_entry);
526526
stmt_obj = Z_SQLITE3_STMT_P(return_value);
527527
stmt_obj->db_obj = db_obj;
528-
ZVAL_OBJ_COPY(&stmt_obj->db_obj_zval, Z_OBJ_P(object));
528+
Z_ADDREF_P(object);
529529

530530
errcode = sqlite3_prepare_v2(db_obj->db, ZSTR_VAL(sql), ZSTR_LEN(sql), &(stmt_obj->stmt), NULL);
531531
if (errcode != SQLITE_OK) {
@@ -577,7 +577,7 @@ PHP_METHOD(SQLite3, query)
577577
object_init_ex(&stmt, php_sqlite3_stmt_entry);
578578
stmt_obj = Z_SQLITE3_STMT_P(&stmt);
579579
stmt_obj->db_obj = db_obj;
580-
ZVAL_OBJ_COPY(&stmt_obj->db_obj_zval, Z_OBJ_P(object));
580+
Z_ADDREF_P(object);
581581

582582
return_code = sqlite3_prepare_v2(db_obj->db, ZSTR_VAL(sql), ZSTR_LEN(sql), &(stmt_obj->stmt), NULL);
583583
if (return_code != SQLITE_OK) {
@@ -594,7 +594,6 @@ PHP_METHOD(SQLite3, query)
594594
result->stmt_obj = stmt_obj;
595595
result->column_names = NULL;
596596
result->column_count = -1;
597-
ZVAL_OBJ(&result->stmt_obj_zval, Z_OBJ(stmt));
598597

599598
return_code = sqlite3_step(result->stmt_obj->stmt);
600599

@@ -1407,7 +1406,7 @@ PHP_METHOD(SQLite3Stmt, close)
14071406

14081407
SQLITE3_CHECK_INITIALIZED(stmt_obj->db_obj, stmt_obj->initialised, SQLite3);
14091408

1410-
zend_llist_del_element(&(stmt_obj->db_obj->free_list), object, (int (*)(void *, void *)) php_sqlite3_compare_stmt_zval_free);
1409+
zend_llist_del_element(&(stmt_obj->db_obj->free_list), stmt_obj, (int (*)(void *, void *)) php_sqlite3_compare_stmt_free);
14111410

14121411
RETURN_TRUE;
14131412
}
@@ -1788,7 +1787,7 @@ PHP_METHOD(SQLite3Stmt, execute)
17881787
result->stmt_obj = stmt_obj;
17891788
result->column_names = NULL;
17901789
result->column_count = -1;
1791-
ZVAL_OBJ_COPY(&result->stmt_obj_zval, Z_OBJ_P(object));
1790+
Z_ADDREF_P(object);
17921791

17931792
break;
17941793
}
@@ -1832,7 +1831,7 @@ PHP_METHOD(SQLite3Stmt, __construct)
18321831
}
18331832

18341833
stmt_obj->db_obj = db_obj;
1835-
ZVAL_OBJ_COPY(&stmt_obj->db_obj_zval, Z_OBJ_P(db_zval));
1834+
Z_ADDREF_P(db_zval);
18361835

18371836
errcode = sqlite3_prepare_v2(db_obj->db, ZSTR_VAL(sql), ZSTR_LEN(sql), &(stmt_obj->stmt), NULL);
18381837
if (errcode != SQLITE_OK) {
@@ -2029,8 +2028,8 @@ PHP_METHOD(SQLite3Result, finalize)
20292028

20302029
/* We need to finalize an internal statement */
20312030
if (result_obj->is_prepared_statement == 0) {
2032-
zend_llist_del_element(&(result_obj->db_obj->free_list), &result_obj->stmt_obj_zval,
2033-
(int (*)(void *, void *)) php_sqlite3_compare_stmt_zval_free);
2031+
zend_llist_del_element(&(result_obj->db_obj->free_list), &result_obj->stmt_obj,
2032+
(int (*)(void *, void *)) php_sqlite3_compare_stmt_free);
20342033
} else {
20352034
sqlite3_reset(result_obj->stmt_obj->stmt);
20362035
}
@@ -2145,12 +2144,6 @@ static void php_sqlite3_free_list_dtor(void **item)
21452144
}
21462145
/* }}} */
21472146

2148-
static int php_sqlite3_compare_stmt_zval_free(php_sqlite3_stmt **stmt_obj_ptr, zval *statement ) /* {{{ */
2149-
{
2150-
return ((*stmt_obj_ptr)->initialised && Z_OBJ_P(statement) == &(*stmt_obj_ptr)->zo);
2151-
}
2152-
/* }}} */
2153-
21542147
static int php_sqlite3_compare_stmt_free(php_sqlite3_stmt **stmt_obj_ptr, sqlite3_stmt *statement ) /* {{{ */
21552148
{
21562149
return ((*stmt_obj_ptr)->initialised && statement == (*stmt_obj_ptr)->stmt);
@@ -2269,8 +2262,8 @@ static void php_sqlite3_stmt_object_free_storage(zend_object *object) /* {{{ */
22692262
(int (*)(void *, void *)) php_sqlite3_compare_stmt_free);
22702263
}
22712264

2272-
if (!Z_ISUNDEF(intern->db_obj_zval)) {
2273-
zval_ptr_dtor(&intern->db_obj_zval);
2265+
if (intern->db_obj) {
2266+
OBJ_RELEASE(&intern->db_obj->zo);
22742267
}
22752268

22762269
zend_object_std_dtor(&intern->zo);
@@ -2283,12 +2276,12 @@ static void php_sqlite3_result_object_free_storage(zend_object *object) /* {{{ *
22832276

22842277
sqlite3result_clear_column_names_cache(intern);
22852278

2286-
if (!Z_ISNULL(intern->stmt_obj_zval)) {
2287-
if (intern->stmt_obj && intern->stmt_obj->initialised) {
2279+
if (intern->stmt_obj) {
2280+
if (intern->stmt_obj->initialised) {
22882281
sqlite3_reset(intern->stmt_obj->stmt);
22892282
}
22902283

2291-
zval_ptr_dtor(&intern->stmt_obj_zval);
2284+
OBJ_RELEASE(&intern->stmt_obj->zo);
22922285
}
22932286

22942287
zend_object_std_dtor(&intern->zo);

0 commit comments

Comments
 (0)