From 04a395d0dac0f46ff226f18a478599ab827e6b2a Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Sun, 9 Feb 2025 18:42:49 +0100 Subject: [PATCH 1/8] Use faster string operations in sqlite3 --- ext/sqlite3/sqlite3.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/ext/sqlite3/sqlite3.c b/ext/sqlite3/sqlite3.c index 2037bb677dff..c960aaab0001 100644 --- a/ext/sqlite3/sqlite3.c +++ b/ext/sqlite3/sqlite3.c @@ -833,13 +833,14 @@ static int sqlite3_do_callback(zend_fcall_info_cache *fcc, uint32_t argc, sqlite break; default: { - zend_string *str = zval_try_get_string(&retval); + zend_string *tmp; + zend_string *str = zval_try_get_tmp_string(&retval, &tmp); if (UNEXPECTED(!str)) { ret = FAILURE; break; } sqlite3_result_text(context, ZSTR_VAL(str), ZSTR_LEN(str), SQLITE_TRANSIENT); - zend_string_release(str); + zend_tmp_string_release(tmp); break; } } @@ -1564,7 +1565,8 @@ static int php_sqlite3_bind_params(php_sqlite3_stmt *stmt_obj) /* {{{ */ } case SQLITE3_TEXT: { - zend_string *str = zval_try_get_string(parameter); + zend_string *tmp; + zend_string *str = zval_try_get_tmp_string(parameter, &tmp); if (UNEXPECTED(!str)) { return FAILURE; } @@ -1572,7 +1574,7 @@ static int php_sqlite3_bind_params(php_sqlite3_stmt *stmt_obj) /* {{{ */ if (return_code != SQLITE_OK) { php_sqlite3_error(stmt_obj->db_obj, return_code, "Unable to bind parameter number " ZEND_LONG_FMT, param->param_number); } - zend_string_release(str); + zend_tmp_string_release(tmp); break; } @@ -1998,7 +2000,7 @@ PHP_METHOD(SQLite3Result, fetchArray) static void sqlite3result_clear_column_names_cache(php_sqlite3_result *result) { if (result->column_names) { for (int i = 0; i < result->column_count; i++) { - zend_string_release(result->column_names[i]); + zend_string_release_ex(result->column_names[i], false); } efree(result->column_names); } From 0a098e72684d39b15c6201d14f90431a1e79e584 Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Sun, 9 Feb 2025 18:54:17 +0100 Subject: [PATCH 2/8] Get rid of unnecessary wrapping a statement in a free list object This simplifies the code and reduces memory usage. --- ext/sqlite3/php_sqlite3_structs.h | 6 ----- ext/sqlite3/sqlite3.c | 42 ++++++++++--------------------- 2 files changed, 13 insertions(+), 35 deletions(-) diff --git a/ext/sqlite3/php_sqlite3_structs.h b/ext/sqlite3/php_sqlite3_structs.h index 59dcd8b6ee72..ab54fdeedb3d 100644 --- a/ext/sqlite3/php_sqlite3_structs.h +++ b/ext/sqlite3/php_sqlite3_structs.h @@ -89,12 +89,6 @@ typedef struct _php_sqlite3_agg_context { typedef struct _php_sqlite3_stmt_object php_sqlite3_stmt; typedef struct _php_sqlite3_result_object php_sqlite3_result; -/* sqlite3 objects to be destroyed */ -typedef struct _php_sqlite3_free_list { - zval stmt_obj_zval; - php_sqlite3_stmt *stmt_obj; -} php_sqlite3_free_list; - /* Structure for SQLite Result object. */ struct _php_sqlite3_result_object { php_sqlite3_db_object *db_obj; diff --git a/ext/sqlite3/sqlite3.c b/ext/sqlite3/sqlite3.c index c960aaab0001..4fed2742bce9 100644 --- a/ext/sqlite3/sqlite3.c +++ b/ext/sqlite3/sqlite3.c @@ -35,7 +35,7 @@ ZEND_DECLARE_MODULE_GLOBALS(sqlite3) static PHP_GINIT_FUNCTION(sqlite3); static int php_sqlite3_authorizer(void *autharg, int action, const char *arg1, const char *arg2, const char *arg3, const char *arg4); static void sqlite3_param_dtor(zval *data); -static int php_sqlite3_compare_stmt_zval_free(php_sqlite3_free_list **free_list, zval *statement); +static int php_sqlite3_compare_stmt_zval_free(php_sqlite3_stmt **stmt_obj_ptr, zval *statement); #define SQLITE3_CHECK_INITIALIZED(db_obj, member, class_name) \ if (!(db_obj) || !(member)) { \ @@ -509,7 +509,6 @@ PHP_METHOD(SQLite3, prepare) zval *object = ZEND_THIS; zend_string *sql; int errcode; - php_sqlite3_free_list *free_item; db_obj = Z_SQLITE3_DB_P(object); @@ -537,11 +536,7 @@ PHP_METHOD(SQLite3, prepare) stmt_obj->initialised = 1; - free_item = emalloc(sizeof(php_sqlite3_free_list)); - free_item->stmt_obj = stmt_obj; - ZVAL_OBJ(&free_item->stmt_obj_zval, Z_OBJ_P(return_value)); - - zend_llist_add_element(&(db_obj->free_list), &free_item); + zend_llist_add_element(&(db_obj->free_list), &stmt_obj); } /* }}} */ @@ -607,11 +602,7 @@ PHP_METHOD(SQLite3, query) case SQLITE_ROW: /* Valid Row */ case SQLITE_DONE: /* Valid but no results */ { - php_sqlite3_free_list *free_item; - free_item = emalloc(sizeof(php_sqlite3_free_list)); - free_item->stmt_obj = stmt_obj; - free_item->stmt_obj_zval = stmt; - zend_llist_add_element(&(db_obj->free_list), &free_item); + zend_llist_add_element(&(db_obj->free_list), &stmt_obj); sqlite3_reset(result->stmt_obj->stmt); break; } @@ -1825,7 +1816,6 @@ PHP_METHOD(SQLite3Stmt, __construct) zval *db_zval; zend_string *sql; int errcode; - php_sqlite3_free_list *free_item; stmt_obj = Z_SQLITE3_STMT_P(object); @@ -1852,12 +1842,7 @@ PHP_METHOD(SQLite3Stmt, __construct) } stmt_obj->initialised = 1; - free_item = emalloc(sizeof(php_sqlite3_free_list)); - free_item->stmt_obj = stmt_obj; - //?? free_item->stmt_obj_zval = ZEND_THIS; - ZVAL_OBJ(&free_item->stmt_obj_zval, Z_OBJ_P(object)); - - zend_llist_add_element(&(db_obj->free_list), &free_item); + zend_llist_add_element(&(db_obj->free_list), &stmt_obj); } /* }}} */ @@ -2151,25 +2136,24 @@ static int php_sqlite3_authorizer(void *autharg, int action, const char *arg1, c /* {{{ php_sqlite3_free_list_dtor */ static void php_sqlite3_free_list_dtor(void **item) { - php_sqlite3_free_list *free_item = (php_sqlite3_free_list *)*item; + php_sqlite3_stmt *stmt_obj = *item; - if (free_item->stmt_obj && free_item->stmt_obj->initialised) { - sqlite3_finalize(free_item->stmt_obj->stmt); - free_item->stmt_obj->initialised = 0; + if (stmt_obj && stmt_obj->initialised) { + sqlite3_finalize(stmt_obj->stmt); + stmt_obj->initialised = 0; } - efree(*item); } /* }}} */ -static int php_sqlite3_compare_stmt_zval_free(php_sqlite3_free_list **free_list, zval *statement ) /* {{{ */ +static int php_sqlite3_compare_stmt_zval_free(php_sqlite3_stmt **stmt_obj_ptr, zval *statement ) /* {{{ */ { - return ((*free_list)->stmt_obj->initialised && Z_PTR_P(statement) == Z_PTR((*free_list)->stmt_obj_zval)); + return ((*stmt_obj_ptr)->initialised && Z_OBJ_P(statement) == &(*stmt_obj_ptr)->zo); } /* }}} */ -static int php_sqlite3_compare_stmt_free( php_sqlite3_free_list **free_list, sqlite3_stmt *statement ) /* {{{ */ +static int php_sqlite3_compare_stmt_free(php_sqlite3_stmt **stmt_obj_ptr, sqlite3_stmt *statement ) /* {{{ */ { - return ((*free_list)->stmt_obj->initialised && statement == (*free_list)->stmt_obj->stmt); + return ((*stmt_obj_ptr)->initialised && statement == (*stmt_obj_ptr)->stmt); } /* }}} */ @@ -2331,7 +2315,7 @@ static zend_object *php_sqlite3_object_new(zend_class_entry *class_type) /* {{{ intern = zend_object_alloc(sizeof(php_sqlite3_db_object), class_type); /* Need to keep track of things to free */ - zend_llist_init(&(intern->free_list), sizeof(php_sqlite3_free_list *), (llist_dtor_func_t)php_sqlite3_free_list_dtor, 0); + zend_llist_init(&(intern->free_list), sizeof(php_sqlite3_stmt *), (llist_dtor_func_t)php_sqlite3_free_list_dtor, 0); zend_object_std_init(&intern->zo, class_type); object_properties_init(&intern->zo, class_type); From 9ac66da90b259514175655d95a33daec5828f76a Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Sun, 9 Feb 2025 18:55:14 +0100 Subject: [PATCH 3/8] Get rid of always-false intern checks These checks are always false because we're receiving a valid zend_object. --- ext/sqlite3/sqlite3.c | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/ext/sqlite3/sqlite3.c b/ext/sqlite3/sqlite3.c index 4fed2742bce9..7d5b3eaee6dd 100644 --- a/ext/sqlite3/sqlite3.c +++ b/ext/sqlite3/sqlite3.c @@ -2163,10 +2163,6 @@ static void php_sqlite3_object_free_storage(zend_object *object) /* {{{ */ php_sqlite3_func *func; php_sqlite3_collation *collation; - if (!intern) { - return; - } - /* Release function_name from authorizer */ if (ZEND_FCC_INITIALIZED(intern->authorizer_fcc)) { zend_fcc_dtor(&intern->authorizer_fcc); @@ -2262,10 +2258,6 @@ static void php_sqlite3_stmt_object_free_storage(zend_object *object) /* {{{ */ { php_sqlite3_stmt *intern = php_sqlite3_stmt_from_obj(object); - if (!intern) { - return; - } - if (intern->bound_params) { zend_hash_destroy(intern->bound_params); FREE_HASHTABLE(intern->bound_params); @@ -2289,10 +2281,6 @@ static void php_sqlite3_result_object_free_storage(zend_object *object) /* {{{ * { php_sqlite3_result *intern = php_sqlite3_result_from_obj(object); - if (!intern) { - return; - } - sqlite3result_clear_column_names_cache(intern); if (!Z_ISNULL(intern->stmt_obj_zval)) { From f94155327e9e1bc8480cf3619c74e0a849108ca2 Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Sun, 9 Feb 2025 19:05:16 +0100 Subject: [PATCH 4/8] Don't store the object zval directly --- ext/sqlite3/php_sqlite3_structs.h | 2 -- ext/sqlite3/sqlite3.c | 33 ++++++++++++------------------- 2 files changed, 13 insertions(+), 22 deletions(-) diff --git a/ext/sqlite3/php_sqlite3_structs.h b/ext/sqlite3/php_sqlite3_structs.h index ab54fdeedb3d..2c110c5311a2 100644 --- a/ext/sqlite3/php_sqlite3_structs.h +++ b/ext/sqlite3/php_sqlite3_structs.h @@ -93,7 +93,6 @@ typedef struct _php_sqlite3_result_object php_sqlite3_result; struct _php_sqlite3_result_object { php_sqlite3_db_object *db_obj; php_sqlite3_stmt *stmt_obj; - zval stmt_obj_zval; /* Cache of column names to speed up repeated fetchArray(SQLITE3_ASSOC) calls. * 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) struct _php_sqlite3_stmt_object { sqlite3_stmt *stmt; php_sqlite3_db_object *db_obj; - zval db_obj_zval; int initialised; diff --git a/ext/sqlite3/sqlite3.c b/ext/sqlite3/sqlite3.c index 7d5b3eaee6dd..8691c0f79a4a 100644 --- a/ext/sqlite3/sqlite3.c +++ b/ext/sqlite3/sqlite3.c @@ -35,7 +35,7 @@ ZEND_DECLARE_MODULE_GLOBALS(sqlite3) static PHP_GINIT_FUNCTION(sqlite3); static int php_sqlite3_authorizer(void *autharg, int action, const char *arg1, const char *arg2, const char *arg3, const char *arg4); static void sqlite3_param_dtor(zval *data); -static int php_sqlite3_compare_stmt_zval_free(php_sqlite3_stmt **stmt_obj_ptr, zval *statement); +static int php_sqlite3_compare_stmt_free(php_sqlite3_stmt **stmt_obj_ptr, sqlite3_stmt *statement); #define SQLITE3_CHECK_INITIALIZED(db_obj, member, class_name) \ if (!(db_obj) || !(member)) { \ @@ -525,7 +525,7 @@ PHP_METHOD(SQLite3, prepare) object_init_ex(return_value, php_sqlite3_stmt_entry); stmt_obj = Z_SQLITE3_STMT_P(return_value); stmt_obj->db_obj = db_obj; - ZVAL_OBJ_COPY(&stmt_obj->db_obj_zval, Z_OBJ_P(object)); + Z_ADDREF_P(object); errcode = sqlite3_prepare_v2(db_obj->db, ZSTR_VAL(sql), ZSTR_LEN(sql), &(stmt_obj->stmt), NULL); if (errcode != SQLITE_OK) { @@ -577,7 +577,7 @@ PHP_METHOD(SQLite3, query) object_init_ex(&stmt, php_sqlite3_stmt_entry); stmt_obj = Z_SQLITE3_STMT_P(&stmt); stmt_obj->db_obj = db_obj; - ZVAL_OBJ_COPY(&stmt_obj->db_obj_zval, Z_OBJ_P(object)); + Z_ADDREF_P(object); return_code = sqlite3_prepare_v2(db_obj->db, ZSTR_VAL(sql), ZSTR_LEN(sql), &(stmt_obj->stmt), NULL); if (return_code != SQLITE_OK) { @@ -594,7 +594,6 @@ PHP_METHOD(SQLite3, query) result->stmt_obj = stmt_obj; result->column_names = NULL; result->column_count = -1; - ZVAL_OBJ(&result->stmt_obj_zval, Z_OBJ(stmt)); return_code = sqlite3_step(result->stmt_obj->stmt); @@ -1407,7 +1406,7 @@ PHP_METHOD(SQLite3Stmt, close) SQLITE3_CHECK_INITIALIZED(stmt_obj->db_obj, stmt_obj->initialised, SQLite3); - zend_llist_del_element(&(stmt_obj->db_obj->free_list), object, (int (*)(void *, void *)) php_sqlite3_compare_stmt_zval_free); + zend_llist_del_element(&(stmt_obj->db_obj->free_list), stmt_obj, (int (*)(void *, void *)) php_sqlite3_compare_stmt_free); RETURN_TRUE; } @@ -1788,7 +1787,7 @@ PHP_METHOD(SQLite3Stmt, execute) result->stmt_obj = stmt_obj; result->column_names = NULL; result->column_count = -1; - ZVAL_OBJ_COPY(&result->stmt_obj_zval, Z_OBJ_P(object)); + Z_ADDREF_P(object); break; } @@ -1832,7 +1831,7 @@ PHP_METHOD(SQLite3Stmt, __construct) } stmt_obj->db_obj = db_obj; - ZVAL_OBJ_COPY(&stmt_obj->db_obj_zval, Z_OBJ_P(db_zval)); + Z_ADDREF_P(db_zval); errcode = sqlite3_prepare_v2(db_obj->db, ZSTR_VAL(sql), ZSTR_LEN(sql), &(stmt_obj->stmt), NULL); if (errcode != SQLITE_OK) { @@ -2029,8 +2028,8 @@ PHP_METHOD(SQLite3Result, finalize) /* We need to finalize an internal statement */ if (result_obj->is_prepared_statement == 0) { - zend_llist_del_element(&(result_obj->db_obj->free_list), &result_obj->stmt_obj_zval, - (int (*)(void *, void *)) php_sqlite3_compare_stmt_zval_free); + zend_llist_del_element(&(result_obj->db_obj->free_list), &result_obj->stmt_obj, + (int (*)(void *, void *)) php_sqlite3_compare_stmt_free); } else { sqlite3_reset(result_obj->stmt_obj->stmt); } @@ -2145,12 +2144,6 @@ static void php_sqlite3_free_list_dtor(void **item) } /* }}} */ -static int php_sqlite3_compare_stmt_zval_free(php_sqlite3_stmt **stmt_obj_ptr, zval *statement ) /* {{{ */ -{ - return ((*stmt_obj_ptr)->initialised && Z_OBJ_P(statement) == &(*stmt_obj_ptr)->zo); -} -/* }}} */ - static int php_sqlite3_compare_stmt_free(php_sqlite3_stmt **stmt_obj_ptr, sqlite3_stmt *statement ) /* {{{ */ { 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) /* {{{ */ (int (*)(void *, void *)) php_sqlite3_compare_stmt_free); } - if (!Z_ISUNDEF(intern->db_obj_zval)) { - zval_ptr_dtor(&intern->db_obj_zval); + if (intern->db_obj) { + OBJ_RELEASE(&intern->db_obj->zo); } zend_object_std_dtor(&intern->zo); @@ -2283,12 +2276,12 @@ static void php_sqlite3_result_object_free_storage(zend_object *object) /* {{{ * sqlite3result_clear_column_names_cache(intern); - if (!Z_ISNULL(intern->stmt_obj_zval)) { - if (intern->stmt_obj && intern->stmt_obj->initialised) { + if (intern->stmt_obj) { + if (intern->stmt_obj->initialised) { sqlite3_reset(intern->stmt_obj->stmt); } - zval_ptr_dtor(&intern->stmt_obj_zval); + OBJ_RELEASE(&intern->stmt_obj->zo); } zend_object_std_dtor(&intern->zo); From adbf3b6946f68083a5cd3116f828a80dfa61000e Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Sun, 9 Feb 2025 19:05:35 +0100 Subject: [PATCH 5/8] Pack _php_sqlite3_result_object --- ext/sqlite3/php_sqlite3_structs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/sqlite3/php_sqlite3_structs.h b/ext/sqlite3/php_sqlite3_structs.h index 2c110c5311a2..229b8f564c7b 100644 --- a/ext/sqlite3/php_sqlite3_structs.h +++ b/ext/sqlite3/php_sqlite3_structs.h @@ -94,12 +94,12 @@ struct _php_sqlite3_result_object { php_sqlite3_db_object *db_obj; php_sqlite3_stmt *stmt_obj; + int is_prepared_statement; /* Cache of column names to speed up repeated fetchArray(SQLITE3_ASSOC) calls. * Cache is cleared on reset() and finalize() calls. */ int column_count; zend_string **column_names; - int is_prepared_statement; zend_object zo; }; From a28ab987b83e428410f7c3485543a01d8d72c9d2 Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Sun, 9 Feb 2025 19:33:33 +0100 Subject: [PATCH 6/8] Convert is_prepared_statement to bool --- ext/sqlite3/php_sqlite3_structs.h | 2 +- ext/sqlite3/sqlite3.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ext/sqlite3/php_sqlite3_structs.h b/ext/sqlite3/php_sqlite3_structs.h index 229b8f564c7b..c54be8e02774 100644 --- a/ext/sqlite3/php_sqlite3_structs.h +++ b/ext/sqlite3/php_sqlite3_structs.h @@ -94,7 +94,7 @@ struct _php_sqlite3_result_object { php_sqlite3_db_object *db_obj; php_sqlite3_stmt *stmt_obj; - int is_prepared_statement; + bool is_prepared_statement; /* Cache of column names to speed up repeated fetchArray(SQLITE3_ASSOC) calls. * Cache is cleared on reset() and finalize() calls. */ int column_count; diff --git a/ext/sqlite3/sqlite3.c b/ext/sqlite3/sqlite3.c index 8691c0f79a4a..956d8049ddd7 100644 --- a/ext/sqlite3/sqlite3.c +++ b/ext/sqlite3/sqlite3.c @@ -1782,7 +1782,7 @@ PHP_METHOD(SQLite3Stmt, execute) object_init_ex(return_value, php_sqlite3_result_entry); result = Z_SQLITE3_RESULT_P(return_value); - result->is_prepared_statement = 1; + result->is_prepared_statement = true; result->db_obj = stmt_obj->db_obj; result->stmt_obj = stmt_obj; result->column_names = NULL; @@ -2027,7 +2027,7 @@ PHP_METHOD(SQLite3Result, finalize) sqlite3result_clear_column_names_cache(result_obj); /* We need to finalize an internal statement */ - if (result_obj->is_prepared_statement == 0) { + if (!result_obj->is_prepared_statement) { zend_llist_del_element(&(result_obj->db_obj->free_list), &result_obj->stmt_obj, (int (*)(void *, void *)) php_sqlite3_compare_stmt_free); } else { From 5f1aa3f4c9d8675dcc476ef79e6a00188bc02d73 Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Sun, 9 Feb 2025 19:35:05 +0100 Subject: [PATCH 7/8] Convert initialised to bool --- ext/sqlite3/php_sqlite3_structs.h | 4 ++-- ext/sqlite3/sqlite3.c | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/ext/sqlite3/php_sqlite3_structs.h b/ext/sqlite3/php_sqlite3_structs.h index c54be8e02774..a1d696d7ae31 100644 --- a/ext/sqlite3/php_sqlite3_structs.h +++ b/ext/sqlite3/php_sqlite3_structs.h @@ -62,7 +62,7 @@ typedef struct _php_sqlite3_collation { /* Structure for SQLite Database object. */ typedef struct _php_sqlite3_db_object { - int initialised; + bool initialised; sqlite3 *db; php_sqlite3_func *funcs; php_sqlite3_collation *collations; @@ -114,7 +114,7 @@ struct _php_sqlite3_stmt_object { sqlite3_stmt *stmt; php_sqlite3_db_object *db_obj; - int initialised; + bool initialised; /* Keep track of the zvals for bound parameters */ HashTable *bound_params; diff --git a/ext/sqlite3/sqlite3.c b/ext/sqlite3/sqlite3.c index 956d8049ddd7..92621b9c3c08 100644 --- a/ext/sqlite3/sqlite3.c +++ b/ext/sqlite3/sqlite3.c @@ -161,7 +161,7 @@ PHP_METHOD(SQLite3, open) } #endif - db_obj->initialised = 1; + db_obj->initialised = true; db_obj->authorizer_fcc = empty_fcall_info_cache; sqlite3_set_authorizer(db_obj->db, php_sqlite3_authorizer, db_obj); @@ -199,7 +199,7 @@ PHP_METHOD(SQLite3, close) RETURN_FALSE; } } - db_obj->initialised = 0; + db_obj->initialised = false; } RETURN_TRUE; @@ -534,7 +534,7 @@ PHP_METHOD(SQLite3, prepare) RETURN_FALSE; } - stmt_obj->initialised = 1; + stmt_obj->initialised = true; zend_llist_add_element(&(db_obj->free_list), &stmt_obj); } @@ -586,7 +586,7 @@ PHP_METHOD(SQLite3, query) RETURN_FALSE; } - stmt_obj->initialised = 1; + stmt_obj->initialised = true; object_init_ex(return_value, php_sqlite3_result_entry); result = Z_SQLITE3_RESULT_P(return_value); @@ -610,7 +610,7 @@ PHP_METHOD(SQLite3, query) php_sqlite3_error(db_obj, sqlite3_errcode(db_obj->db), "Unable to execute statement: %s", sqlite3_errmsg(db_obj->db)); } sqlite3_finalize(stmt_obj->stmt); - stmt_obj->initialised = 0; + stmt_obj->initialised = false; zval_ptr_dtor(return_value); RETURN_FALSE; } @@ -1839,7 +1839,7 @@ PHP_METHOD(SQLite3Stmt, __construct) zval_ptr_dtor(return_value); RETURN_FALSE; } - stmt_obj->initialised = 1; + stmt_obj->initialised = true; zend_llist_add_element(&(db_obj->free_list), &stmt_obj); } @@ -2139,7 +2139,7 @@ static void php_sqlite3_free_list_dtor(void **item) if (stmt_obj && stmt_obj->initialised) { sqlite3_finalize(stmt_obj->stmt); - stmt_obj->initialised = 0; + stmt_obj->initialised = false; } } /* }}} */ @@ -2197,7 +2197,7 @@ static void php_sqlite3_object_free_storage(zend_object *object) /* {{{ */ if (intern->initialised && intern->db) { sqlite3_close(intern->db); - intern->initialised = 0; + intern->initialised = false; } zend_object_std_dtor(&intern->zo); From 9ea09a2aefd5b71f3ecf35115ccaafa69fc105f0 Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Mon, 10 Feb 2025 08:43:35 +0100 Subject: [PATCH 8/8] Pack _php_sqlite3_db_object --- ext/sqlite3/php_sqlite3_structs.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ext/sqlite3/php_sqlite3_structs.h b/ext/sqlite3/php_sqlite3_structs.h index a1d696d7ae31..5d9f69cc5770 100644 --- a/ext/sqlite3/php_sqlite3_structs.h +++ b/ext/sqlite3/php_sqlite3_structs.h @@ -63,13 +63,13 @@ typedef struct _php_sqlite3_collation { /* Structure for SQLite Database object. */ typedef struct _php_sqlite3_db_object { bool initialised; + bool exception; + sqlite3 *db; php_sqlite3_func *funcs; php_sqlite3_collation *collations; zend_fcall_info_cache authorizer_fcc; - bool exception; - zend_llist free_list; zend_object zo; } php_sqlite3_db_object;