@@ -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,27 +949,23 @@ 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
955
965
func = (php_sqlite3_func * )ecalloc (1 , sizeof (* func ));
956
966
957
967
if (sqlite3_create_function (db_obj -> db , sql_func , sql_func_num_args , flags | SQLITE_UTF8 , func , php_sqlite3_callback_func , NULL , NULL ) == SQLITE_OK ) {
958
968
func -> func_name = estrdup (sql_func );
959
-
960
- if (!ZEND_FCC_INITIALIZED (fcc )) {
961
- zend_is_callable_ex (& fci .function_name , NULL , IS_CALLABLE_SUPPRESS_DEPRECATIONS , NULL , & fcc , NULL );
962
- /* Call trampoline has been cleared by zpp. Refetch it, because we want to deal
963
- * with it outselves. It is important that it is not refetched on every call,
964
- * because calls may occur from different scopes. */
965
- }
966
969
zend_fcc_dup (& func -> func , & fcc );
967
970
968
971
func -> argc = sql_func_num_args ;
@@ -972,6 +975,7 @@ PHP_METHOD(SQLite3, createFunction)
972
975
RETURN_TRUE ;
973
976
}
974
977
efree (func );
978
+ zend_release_fcall_info_cache (& fcc );
975
979
976
980
RETURN_FALSE ;
977
981
}
@@ -990,34 +994,27 @@ PHP_METHOD(SQLite3, createAggregate)
990
994
zend_long sql_func_num_args = -1 ;
991
995
db_obj = Z_SQLITE3_DB_P (object );
992
996
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 ) {
994
- RETURN_THROWS () ;
997
+ 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 ) {
998
+ goto error ;
995
999
}
996
1000
997
- SQLITE3_CHECK_INITIALIZED (db_obj , db_obj -> initialised , SQLite3 )
1001
+ /* Cannot use SQLITE3_CHECK_INITIALIZED_FREE_TRAMPOLINE() as we have 2 FCCs */
1002
+ if (!db_obj || !db_obj -> initialised ) {
1003
+ zend_throw_error (NULL , "The SQLite3 object has not been correctly initialised or is already closed" );
1004
+ goto error ;
1005
+ }
998
1006
999
1007
if (!sql_func_len ) {
1000
- RETURN_FALSE ;
1008
+ /* TODO Add warning/ValueError that name cannot be empty? */
1009
+ goto error ;
1001
1010
}
1002
1011
1003
1012
func = (php_sqlite3_func * )ecalloc (1 , sizeof (* func ));
1004
1013
1005
1014
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
1015
func -> func_name = estrdup (sql_func );
1007
1016
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
1017
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
1018
zend_fcc_dup (& func -> fini , & fini_fcc );
1022
1019
1023
1020
func -> argc = sql_func_num_args ;
@@ -1028,6 +1025,14 @@ PHP_METHOD(SQLite3, createAggregate)
1028
1025
}
1029
1026
efree (func );
1030
1027
1028
+ error :
1029
+ if (ZEND_FCC_INITIALIZED (step_fcc )) {
1030
+ zend_release_fcall_info_cache (& step_fcc );
1031
+ }
1032
+ if (ZEND_FCC_INITIALIZED (fini_fcc )) {
1033
+ zend_release_fcall_info_cache (& fini_fcc );
1034
+ }
1035
+
1031
1036
RETURN_FALSE ;
1032
1037
}
1033
1038
/* }}} */
@@ -1044,26 +1049,22 @@ PHP_METHOD(SQLite3, createCollation)
1044
1049
zend_fcall_info_cache fcc ;
1045
1050
db_obj = Z_SQLITE3_DB_P (object );
1046
1051
1047
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "sf " , & collation_name , & collation_name_len , & fci , & fcc ) == FAILURE ) {
1052
+ if (zend_parse_parameters (ZEND_NUM_ARGS (), "sF " , & collation_name , & collation_name_len , & fci , & fcc ) == FAILURE ) {
1048
1053
RETURN_THROWS ();
1049
1054
}
1050
1055
1051
- SQLITE3_CHECK_INITIALIZED (db_obj , db_obj -> initialised , SQLite3 )
1056
+ SQLITE3_CHECK_INITIALIZED_FREE_TRAMPOLINE (db_obj , db_obj -> initialised , SQLite3 , & fcc );
1052
1057
1053
1058
if (!collation_name_len ) {
1059
+ /* TODO Add warning/ValueError that name cannot be empty? */
1060
+ zend_release_fcall_info_cache (& fcc );
1054
1061
RETURN_FALSE ;
1055
1062
}
1056
1063
1057
1064
collation = (php_sqlite3_collation * )ecalloc (1 , sizeof (* collation ));
1058
1065
if (sqlite3_create_collation (db_obj -> db , collation_name , SQLITE_UTF8 , collation , php_sqlite3_callback_compare ) == SQLITE_OK ) {
1059
1066
collation -> collation_name = estrdup (collation_name );
1060
1067
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
1068
zend_fcc_dup (& collation -> cmp_func , & fcc );
1068
1069
1069
1070
collation -> next = db_obj -> collations ;
@@ -1072,6 +1073,7 @@ PHP_METHOD(SQLite3, createCollation)
1072
1073
RETURN_TRUE ;
1073
1074
}
1074
1075
efree (collation );
1076
+ zend_release_fcall_info_cache (& fcc );
1075
1077
1076
1078
RETURN_FALSE ;
1077
1079
}
@@ -1317,10 +1319,10 @@ PHP_METHOD(SQLite3, setAuthorizer)
1317
1319
zend_fcall_info_cache fcc ;
1318
1320
1319
1321
ZEND_PARSE_PARAMETERS_START (1 , 1 )
1320
- Z_PARAM_FUNC_OR_NULL (fci , fcc )
1322
+ Z_PARAM_FUNC_NO_TRAMPOLINE_FREE_OR_NULL (fci , fcc )
1321
1323
ZEND_PARSE_PARAMETERS_END ();
1322
1324
1323
- SQLITE3_CHECK_INITIALIZED (db_obj , db_obj -> initialised , SQLite3 )
1325
+ SQLITE3_CHECK_INITIALIZED_FREE_TRAMPOLINE (db_obj , db_obj -> initialised , SQLite3 , & fcc );
1324
1326
1325
1327
/* Clear previously set callback */
1326
1328
if (ZEND_FCC_INITIALIZED (db_obj -> authorizer_fcc )) {
@@ -1329,14 +1331,7 @@ PHP_METHOD(SQLite3, setAuthorizer)
1329
1331
1330
1332
/* Only enable userland authorizer if argument is not NULL */
1331
1333
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 );
1334
+ zend_fcc_dup (& db_obj -> authorizer_fcc , & fcc );
1340
1335
}
1341
1336
1342
1337
RETURN_TRUE ;
0 commit comments