@@ -44,6 +44,13 @@ static int php_sqlite3_compare_stmt_zval_free(php_sqlite3_free_list **free_list,
44
44
RETURN_THROWS(); \
45
45
}
46
46
47
+ #define SQLITE3_CHECK_INITIALIZED_FREE_TRAMPOLINE (db_obj , member , class_name , trampoline_fcc ) \
48
+ if (!(db_obj) || !(member)) { \
49
+ zend_release_fcall_info_cache((trampoline_fcc)); \
50
+ zend_throw_error(NULL, "The " #class_name " object has not been correctly initialised or is already closed"); \
51
+ RETURN_THROWS(); \
52
+ }
53
+
47
54
#define SQLITE3_CHECK_INITIALIZED_STMT (member , class_name ) \
48
55
if (!(member)) { \
49
56
zend_throw_error(NULL, "The " #class_name " object has not been correctly initialised or is already closed"); \
@@ -942,13 +949,16 @@ PHP_METHOD(SQLite3, createFunction)
942
949
zend_long flags = 0 ;
943
950
db_obj = Z_SQLITE3_DB_P (object );
944
951
945
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "sf|ll" , & sql_func , & sql_func_len , & fci , & fcc , & sql_func_num_args , & flags ) == FAILURE ) {
952
+ if (zend_parse_parameters (ZEND_NUM_ARGS (), "sF|ll" , & sql_func , & sql_func_len , & fci , & fcc , & sql_func_num_args , & flags ) == FAILURE ) {
953
+ zend_release_fcall_info_cache (& fcc );
946
954
RETURN_THROWS ();
947
955
}
948
956
949
- SQLITE3_CHECK_INITIALIZED (db_obj , db_obj -> initialised , SQLite3 )
957
+ SQLITE3_CHECK_INITIALIZED_FREE_TRAMPOLINE (db_obj , db_obj -> initialised , SQLite3 , & fcc );
950
958
951
959
if (!sql_func_len ) {
960
+ /* TODO Add warning/ValueError that name cannot be empty? */
961
+ zend_release_fcall_info_cache (& fcc );
952
962
RETURN_FALSE ;
953
963
}
954
964
@@ -990,13 +1000,24 @@ PHP_METHOD(SQLite3, createAggregate)
990
1000
zend_long sql_func_num_args = -1 ;
991
1001
db_obj = Z_SQLITE3_DB_P (object );
992
1002
993
- 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 ) {
1003
+ 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 ) {
1004
+ zend_release_fcall_info_cache (& step_fcc );
1005
+ zend_release_fcall_info_cache (& fini_fcc );
994
1006
RETURN_THROWS ();
995
1007
}
996
1008
997
- SQLITE3_CHECK_INITIALIZED (db_obj , db_obj -> initialised , SQLite3 )
1009
+ /* Cannot use SQLITE3_CHECK_INITIALIZED_FREE_TRAMPOLINE() as we have 2 FCCs */
1010
+ if (!db_obj || !db_obj -> initialised ) {
1011
+ zend_release_fcall_info_cache (& step_fcc );
1012
+ zend_release_fcall_info_cache (& fini_fcc );
1013
+ zend_throw_error (NULL , "The SQLite3 object has not been correctly initialised or is already closed" );
1014
+ RETURN_THROWS ();
1015
+ }
998
1016
999
1017
if (!sql_func_len ) {
1018
+ /* TODO Add warning/ValueError that name cannot be empty? */
1019
+ zend_release_fcall_info_cache (& step_fcc );
1020
+ zend_release_fcall_info_cache (& fini_fcc );
1000
1021
RETURN_FALSE ;
1001
1022
}
1002
1023
@@ -1005,19 +1026,7 @@ PHP_METHOD(SQLite3, createAggregate)
1005
1026
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 ) {
1006
1027
func -> func_name = estrdup (sql_func );
1007
1028
1008
- if (!ZEND_FCC_INITIALIZED (step_fcc )) {
1009
- /* Call trampoline has been cleared by zpp. Refetch it, because we want to deal
1010
- * with it outselves. It is important that it is not refetched on every call,
1011
- * because calls may occur from different scopes. */
1012
- zend_is_callable_ex (& step_fci .function_name , NULL , IS_CALLABLE_SUPPRESS_DEPRECATIONS , NULL , & step_fcc , NULL );
1013
- }
1014
1029
zend_fcc_dup (& func -> step , & step_fcc );
1015
- if (!ZEND_FCC_INITIALIZED (fini_fcc )) {
1016
- /* Call trampoline has been cleared by zpp. Refetch it, because we want to deal
1017
- * with it outselves. It is important that it is not refetched on every call,
1018
- * because calls may occur from different scopes. */
1019
- zend_is_callable_ex (& fini_fci .function_name , NULL , IS_CALLABLE_SUPPRESS_DEPRECATIONS , NULL , & fini_fcc , NULL );
1020
- }
1021
1030
zend_fcc_dup (& func -> fini , & fini_fcc );
1022
1031
1023
1032
func -> argc = sql_func_num_args ;
@@ -1044,26 +1053,22 @@ PHP_METHOD(SQLite3, createCollation)
1044
1053
zend_fcall_info_cache fcc ;
1045
1054
db_obj = Z_SQLITE3_DB_P (object );
1046
1055
1047
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "sf " , & collation_name , & collation_name_len , & fci , & fcc ) == FAILURE ) {
1056
+ if (zend_parse_parameters (ZEND_NUM_ARGS (), "sF " , & collation_name , & collation_name_len , & fci , & fcc ) == FAILURE ) {
1048
1057
RETURN_THROWS ();
1049
1058
}
1050
1059
1051
- SQLITE3_CHECK_INITIALIZED (db_obj , db_obj -> initialised , SQLite3 )
1060
+ SQLITE3_CHECK_INITIALIZED_FREE_TRAMPOLINE (db_obj , db_obj -> initialised , SQLite3 , & fcc );
1052
1061
1053
1062
if (!collation_name_len ) {
1063
+ /* TODO Add warning/ValueError that name cannot be empty? */
1064
+ zend_release_fcall_info_cache (& fcc );
1054
1065
RETURN_FALSE ;
1055
1066
}
1056
1067
1057
1068
collation = (php_sqlite3_collation * )ecalloc (1 , sizeof (* collation ));
1058
1069
if (sqlite3_create_collation (db_obj -> db , collation_name , SQLITE_UTF8 , collation , php_sqlite3_callback_compare ) == SQLITE_OK ) {
1059
1070
collation -> collation_name = estrdup (collation_name );
1060
1071
1061
- if (!ZEND_FCC_INITIALIZED (fcc )) {
1062
- /* Call trampoline has been cleared by zpp. Refetch it, because we want to deal
1063
- * with it outselves. It is important that it is not refetched on every call,
1064
- * because calls may occur from different scopes. */
1065
- zend_is_callable_ex (& fci .function_name , NULL , IS_CALLABLE_SUPPRESS_DEPRECATIONS , NULL , & fcc , NULL );
1066
- }
1067
1072
zend_fcc_dup (& collation -> cmp_func , & fcc );
1068
1073
1069
1074
collation -> next = db_obj -> collations ;
@@ -1317,10 +1322,10 @@ PHP_METHOD(SQLite3, setAuthorizer)
1317
1322
zend_fcall_info_cache fcc ;
1318
1323
1319
1324
ZEND_PARSE_PARAMETERS_START (1 , 1 )
1320
- Z_PARAM_FUNC_OR_NULL (fci , fcc )
1325
+ Z_PARAM_FUNC_NO_TRAMPOLINE_FREE_OR_NULL (fci , fcc )
1321
1326
ZEND_PARSE_PARAMETERS_END ();
1322
1327
1323
- SQLITE3_CHECK_INITIALIZED (db_obj , db_obj -> initialised , SQLite3 )
1328
+ SQLITE3_CHECK_INITIALIZED_FREE_TRAMPOLINE (db_obj , db_obj -> initialised , SQLite3 , & fcc );
1324
1329
1325
1330
/* Clear previously set callback */
1326
1331
if (ZEND_FCC_INITIALIZED (db_obj -> authorizer_fcc )) {
@@ -1329,14 +1334,7 @@ PHP_METHOD(SQLite3, setAuthorizer)
1329
1334
1330
1335
/* Only enable userland authorizer if argument is not NULL */
1331
1336
if (ZEND_FCI_INITIALIZED (fci )) {
1332
- if (!ZEND_FCC_INITIALIZED (fcc )) {
1333
- zend_is_callable_ex (& fci .function_name , NULL , IS_CALLABLE_SUPPRESS_DEPRECATIONS , NULL , & fcc , NULL );
1334
- /* Call trampoline has been cleared by zpp. Refetch it, because we want to deal
1335
- * with it outselves. It is important that it is not refetched on every call,
1336
- * because calls may occur from different scopes. */
1337
- }
1338
- db_obj -> authorizer_fcc = fcc ;
1339
- zend_fcc_addref (& db_obj -> authorizer_fcc );
1337
+ zend_fcc_dup (& db_obj -> authorizer_fcc , & fcc );
1340
1338
}
1341
1339
1342
1340
RETURN_TRUE ;
0 commit comments