Skip to content

Commit

Permalink
Revert "ext/sqlite3: Use new F ZPP modifier"
Browse files Browse the repository at this point in the history
Check if the issue is related to SQLite3 changes or not

This reverts commit c59d1c4.
  • Loading branch information
Girgias committed Oct 9, 2023
1 parent c59d1c4 commit 77007f1
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 229 deletions.
66 changes: 34 additions & 32 deletions ext/sqlite3/sqlite3.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,6 @@ static int php_sqlite3_compare_stmt_zval_free(php_sqlite3_free_list **free_list,
RETURN_THROWS(); \
}

#define SQLITE3_CHECK_INITIALIZED_FREE_TRAMPOLINE(db_obj, member, class_name, trampoline_fcc) \
if (!(db_obj) || !(member)) { \
zend_release_fcall_info_cache((trampoline_fcc)); \
zend_throw_error(NULL, "The " #class_name " object has not been correctly initialised or is already closed"); \
RETURN_THROWS(); \
}

#define SQLITE3_CHECK_INITIALIZED_STMT(member, class_name) \
if (!(member)) { \
zend_throw_error(NULL, "The " #class_name " object has not been correctly initialised or is already closed"); \
Expand Down Expand Up @@ -949,16 +942,13 @@ PHP_METHOD(SQLite3, createFunction)
zend_long flags = 0;
db_obj = Z_SQLITE3_DB_P(object);

if (zend_parse_parameters(ZEND_NUM_ARGS(), "sF|ll", &sql_func, &sql_func_len, &fci, &fcc, &sql_func_num_args, &flags) == FAILURE) {
zend_release_fcall_info_cache(&fcc);
if (zend_parse_parameters(ZEND_NUM_ARGS(), "sf|ll", &sql_func, &sql_func_len, &fci, &fcc, &sql_func_num_args, &flags) == FAILURE) {
RETURN_THROWS();
}

SQLITE3_CHECK_INITIALIZED_FREE_TRAMPOLINE(db_obj, db_obj->initialised, SQLite3, &fcc);
SQLITE3_CHECK_INITIALIZED(db_obj, db_obj->initialised, SQLite3)

if (!sql_func_len) {
/* TODO Add warning/ValueError that name cannot be empty? */
zend_release_fcall_info_cache(&fcc);
RETURN_FALSE;
}

Expand Down Expand Up @@ -1000,24 +990,13 @@ PHP_METHOD(SQLite3, createAggregate)
zend_long sql_func_num_args = -1;
db_obj = Z_SQLITE3_DB_P(object);

if (zend_parse_parameters(ZEND_NUM_ARGS(), "sFF|l", &sql_func, &sql_func_len, &step_fci, &step_fcc, &fini_fci, &fini_fcc, &sql_func_num_args) == FAILURE) {
zend_release_fcall_info_cache(&step_fcc);
zend_release_fcall_info_cache(&fini_fcc);
if (zend_parse_parameters(ZEND_NUM_ARGS(), "sff|l", &sql_func, &sql_func_len, &step_fci, &step_fcc, &fini_fci, &fini_fcc, &sql_func_num_args) == FAILURE) {
RETURN_THROWS();
}

/* Cannot use SQLITE3_CHECK_INITIALIZED_FREE_TRAMPOLINE() as we have 2 FCCs */
if (!db_obj || !db_obj->initialised) {
zend_release_fcall_info_cache(&step_fcc);
zend_release_fcall_info_cache(&fini_fcc);
zend_throw_error(NULL, "The SQLite3 object has not been correctly initialised or is already closed");
RETURN_THROWS();
}
SQLITE3_CHECK_INITIALIZED(db_obj, db_obj->initialised, SQLite3)

if (!sql_func_len) {
/* TODO Add warning/ValueError that name cannot be empty? */
zend_release_fcall_info_cache(&step_fcc);
zend_release_fcall_info_cache(&fini_fcc);
RETURN_FALSE;
}

Expand All @@ -1026,7 +1005,19 @@ PHP_METHOD(SQLite3, createAggregate)
if (sqlite3_create_function(db_obj->db, sql_func, sql_func_num_args, SQLITE_UTF8, func, NULL, php_sqlite3_callback_step, php_sqlite3_callback_final) == SQLITE_OK) {
func->func_name = estrdup(sql_func);

if (!ZEND_FCC_INITIALIZED(step_fcc)) {
/* Call trampoline has been cleared by zpp. Refetch it, because we want to deal
* with it outselves. It is important that it is not refetched on every call,
* because calls may occur from different scopes. */
zend_is_callable_ex(&step_fci.function_name, NULL, IS_CALLABLE_SUPPRESS_DEPRECATIONS, NULL, &step_fcc, NULL);
}
zend_fcc_dup(&func->step, &step_fcc);
if (!ZEND_FCC_INITIALIZED(fini_fcc)) {
/* Call trampoline has been cleared by zpp. Refetch it, because we want to deal
* with it outselves. It is important that it is not refetched on every call,
* because calls may occur from different scopes. */
zend_is_callable_ex(&fini_fci.function_name, NULL, IS_CALLABLE_SUPPRESS_DEPRECATIONS, NULL, &fini_fcc, NULL);
}
zend_fcc_dup(&func->fini, &fini_fcc);

func->argc = sql_func_num_args;
Expand All @@ -1053,22 +1044,26 @@ PHP_METHOD(SQLite3, createCollation)
zend_fcall_info_cache fcc;
db_obj = Z_SQLITE3_DB_P(object);

if (zend_parse_parameters(ZEND_NUM_ARGS(), "sF", &collation_name, &collation_name_len, &fci, &fcc) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "sf", &collation_name, &collation_name_len, &fci, &fcc) == FAILURE) {
RETURN_THROWS();
}

SQLITE3_CHECK_INITIALIZED_FREE_TRAMPOLINE(db_obj, db_obj->initialised, SQLite3, &fcc);
SQLITE3_CHECK_INITIALIZED(db_obj, db_obj->initialised, SQLite3)

if (!collation_name_len) {
/* TODO Add warning/ValueError that name cannot be empty? */
zend_release_fcall_info_cache(&fcc);
RETURN_FALSE;
}

collation = (php_sqlite3_collation *)ecalloc(1, sizeof(*collation));
if (sqlite3_create_collation(db_obj->db, collation_name, SQLITE_UTF8, collation, php_sqlite3_callback_compare) == SQLITE_OK) {
collation->collation_name = estrdup(collation_name);

if (!ZEND_FCC_INITIALIZED(fcc)) {
/* Call trampoline has been cleared by zpp. Refetch it, because we want to deal
* with it outselves. It is important that it is not refetched on every call,
* because calls may occur from different scopes. */
zend_is_callable_ex(&fci.function_name, NULL, IS_CALLABLE_SUPPRESS_DEPRECATIONS, NULL, &fcc, NULL);
}
zend_fcc_dup(&collation->cmp_func, &fcc);

collation->next = db_obj->collations;
Expand Down Expand Up @@ -1322,10 +1317,10 @@ PHP_METHOD(SQLite3, setAuthorizer)
zend_fcall_info_cache fcc;

ZEND_PARSE_PARAMETERS_START(1, 1)
Z_PARAM_FUNC_NO_TRAMPOLINE_FREE_OR_NULL(fci, fcc)
Z_PARAM_FUNC_OR_NULL(fci, fcc)
ZEND_PARSE_PARAMETERS_END();

SQLITE3_CHECK_INITIALIZED_FREE_TRAMPOLINE(db_obj, db_obj->initialised, SQLite3, &fcc);
SQLITE3_CHECK_INITIALIZED(db_obj, db_obj->initialised, SQLite3)

/* Clear previously set callback */
if (ZEND_FCC_INITIALIZED(db_obj->authorizer_fcc)) {
Expand All @@ -1334,7 +1329,14 @@ PHP_METHOD(SQLite3, setAuthorizer)

/* Only enable userland authorizer if argument is not NULL */
if (ZEND_FCI_INITIALIZED(fci)) {
zend_fcc_dup(&db_obj->authorizer_fcc, &fcc);
if (!ZEND_FCC_INITIALIZED(fcc)) {
zend_is_callable_ex(&fci.function_name, NULL, IS_CALLABLE_SUPPRESS_DEPRECATIONS, NULL, &fcc, NULL);
/* Call trampoline has been cleared by zpp. Refetch it, because we want to deal
* with it outselves. It is important that it is not refetched on every call,
* because calls may occur from different scopes. */
}
db_obj->authorizer_fcc = fcc;
zend_fcc_addref(&db_obj->authorizer_fcc);
}

RETURN_TRUE;
Expand Down
67 changes: 0 additions & 67 deletions ext/sqlite3/tests/sqlite3_trampoline_create_aggregate_no_leak.phpt

This file was deleted.

44 changes: 0 additions & 44 deletions ext/sqlite3/tests/sqlite3_trampoline_createcollation_no_leak.phpt

This file was deleted.

45 changes: 0 additions & 45 deletions ext/sqlite3/tests/sqlite3_trampoline_createfunction_no_leak.phpt

This file was deleted.

41 changes: 0 additions & 41 deletions ext/sqlite3/tests/sqlite3_trampoline_setauthorizer_no_leak.phpt

This file was deleted.

0 comments on commit 77007f1

Please sign in to comment.