Skip to content

Commit 37aea43

Browse files
committed
Only use FCC for SQLite3 user defined collations
1 parent 29bb426 commit 37aea43

File tree

2 files changed

+6
-22
lines changed

2 files changed

+6
-22
lines changed

ext/sqlite3/php_sqlite3_structs.h

+1-7
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,6 @@ struct php_sqlite3_bound_param {
4040
zval parameter;
4141
};
4242

43-
struct php_sqlite3_fci {
44-
zend_fcall_info fci;
45-
zend_fcall_info_cache fcc;
46-
};
47-
4843
/* Structure for SQLite function. */
4944
typedef struct _php_sqlite3_func {
5045
struct _php_sqlite3_func *next;
@@ -62,8 +57,7 @@ typedef struct _php_sqlite3_collation {
6257
struct _php_sqlite3_collation *next;
6358

6459
const char *collation_name;
65-
zval cmp_func;
66-
struct php_sqlite3_fci fci;
60+
zend_fcall_info_cache cmp_func;
6761
} php_sqlite3_collation;
6862

6963
/* Structure for SQLite Database object. */

ext/sqlite3/sqlite3.c

+5-15
Original file line numberDiff line numberDiff line change
@@ -889,27 +889,17 @@ static int php_sqlite3_callback_compare(void *coll, int a_len, const void *a, in
889889
php_sqlite3_collation *collation = (php_sqlite3_collation*)coll;
890890
zval zargs[2];
891891
zval retval;
892-
int ret;
892+
int ret = 0;
893893

894894
// Exception occurred on previous callback. Don't attempt to call function.
895895
if (EG(exception)) {
896896
return 0;
897897
}
898898

899-
collation->fci.fci.size = (sizeof(collation->fci.fci));
900-
ZVAL_COPY_VALUE(&collation->fci.fci.function_name, &collation->cmp_func);
901-
collation->fci.fci.object = NULL;
902-
collation->fci.fci.retval = &retval;
903-
collation->fci.fci.param_count = 2;
904-
905899
ZVAL_STRINGL(&zargs[0], a, a_len);
906900
ZVAL_STRINGL(&zargs[1], b, b_len);
907901

908-
collation->fci.fci.params = zargs;
909-
910-
if ((ret = zend_call_function(&collation->fci.fci, &collation->fci.fcc)) == FAILURE) {
911-
php_error_docref(NULL, E_WARNING, "An error occurred while invoking the compare callback");
912-
}
902+
zend_call_known_fcc(&collation->cmp_func, &retval, /* argc */ 2, zargs, /* named_params */ NULL);
913903

914904
zval_ptr_dtor(&zargs[0]);
915905
zval_ptr_dtor(&zargs[1]);
@@ -1043,7 +1033,7 @@ PHP_METHOD(SQLite3, createCollation)
10431033
if (sqlite3_create_collation(db_obj->db, collation_name, SQLITE_UTF8, collation, php_sqlite3_callback_compare) == SQLITE_OK) {
10441034
collation->collation_name = estrdup(collation_name);
10451035

1046-
ZVAL_COPY(&collation->cmp_func, &fci.function_name);
1036+
zend_fcc_dup(&collation->cmp_func, &fcc);
10471037

10481038
collation->next = db_obj->collations;
10491039
db_obj->collations = collation;
@@ -2207,8 +2197,8 @@ static void php_sqlite3_object_free_storage(zend_object *object) /* {{{ */
22072197
sqlite3_create_collation(intern->db, collation->collation_name, SQLITE_UTF8, NULL, NULL);
22082198
}
22092199
efree((char*)collation->collation_name);
2210-
if (!Z_ISUNDEF(collation->cmp_func)) {
2211-
zval_ptr_dtor(&collation->cmp_func);
2200+
if (ZEND_FCC_INITIALIZED(collation->cmp_func)) {
2201+
zend_fcc_dtor(&collation->cmp_func);
22122202
}
22132203
efree(collation);
22142204
}

0 commit comments

Comments
 (0)