Skip to content

Commit 944dd36

Browse files
committed
Only use FCC for SQLite3 user defined collations
1 parent ef0c7e6 commit 944dd36

File tree

2 files changed

+6
-21
lines changed

2 files changed

+6
-21
lines changed

ext/sqlite3/php_sqlite3_structs.h

Lines changed: 1 addition & 7 deletions
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

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -900,20 +900,10 @@ static int php_sqlite3_callback_compare(void *coll, int a_len, const void *a, in
900900
return 0;
901901
}
902902

903-
collation->fci.fci.size = (sizeof(collation->fci.fci));
904-
ZVAL_COPY_VALUE(&collation->fci.fci.function_name, &collation->cmp_func);
905-
collation->fci.fci.object = NULL;
906-
collation->fci.fci.retval = &retval;
907-
collation->fci.fci.param_count = 2;
908-
909903
ZVAL_STRINGL(&zargs[0], a, a_len);
910904
ZVAL_STRINGL(&zargs[1], b, b_len);
911905

912-
collation->fci.fci.params = zargs;
913-
914-
if ((ret = zend_call_function(&collation->fci.fci, &collation->fci.fcc)) == FAILURE) {
915-
php_error_docref(NULL, E_WARNING, "An error occurred while invoking the compare callback");
916-
}
906+
zend_call_known_fcc(&collation->cmp_func, &retval, /* argc */ 2, zargs, /* named_params */ NULL);
917907

918908
zval_ptr_dtor(&zargs[0]);
919909
zval_ptr_dtor(&zargs[1]);
@@ -1050,7 +1040,8 @@ PHP_METHOD(SQLite3, createCollation)
10501040
if (sqlite3_create_collation(db_obj->db, collation_name, SQLITE_UTF8, collation, php_sqlite3_callback_compare) == SQLITE_OK) {
10511041
collation->collation_name = estrdup(collation_name);
10521042

1053-
ZVAL_COPY(&collation->cmp_func, &fci.function_name);
1043+
zend_fcc_addref(&fcc);
1044+
memcpy(&collation->cmp_func, &fcc, sizeof(zend_fcall_info_cache));
10541045

10551046
collation->next = db_obj->collations;
10561047
db_obj->collations = collation;
@@ -2217,8 +2208,8 @@ static void php_sqlite3_object_free_storage(zend_object *object) /* {{{ */
22172208
sqlite3_create_collation(intern->db, collation->collation_name, SQLITE_UTF8, NULL, NULL);
22182209
}
22192210
efree((char*)collation->collation_name);
2220-
if (!Z_ISUNDEF(collation->cmp_func)) {
2221-
zval_ptr_dtor(&collation->cmp_func);
2211+
if (ZEND_FCC_INITIALIZED(collation->cmp_func)) {
2212+
zend_fcc_dtor(&collation->cmp_func);
22222213
}
22232214
efree(collation);
22242215
}

0 commit comments

Comments
 (0)