Skip to content

Commit 3d4d448

Browse files
committed
pgsqlSetNoticeCallback: standard ZPP and FCC
use standard macros & funcs #6764 (review)
1 parent 5b12816 commit 3d4d448

File tree

2 files changed

+17
-51
lines changed

2 files changed

+17
-51
lines changed

ext/pdo_pgsql/pgsql_driver.c

Lines changed: 16 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -104,23 +104,13 @@ int _pdo_pgsql_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, int errcode, const char *
104104

105105
static void _pdo_pgsql_notice(void *context, const char *message) /* {{{ */
106106
{
107-
int ret;
108107
zval zarg;
109-
zval retval;
110-
pdo_pgsql_fci * fc;
108+
zend_fcall_info_cache *fc;
111109
pdo_dbh_t * dbh = (pdo_dbh_t *)context;
112110
if ((fc = ((pdo_pgsql_db_handle *)dbh->driver_data)->notice_callback)) {
113111
ZVAL_STRINGL(&zarg, (char *) message, strlen(message));
114-
fc->fci.param_count = 1;
115-
fc->fci.params = &zarg;
116-
fc->fci.retval = &retval;
117-
if ((ret = zend_call_function(&fc->fci, &fc->fcc)) != FAILURE) {
118-
zval_ptr_dtor(&retval);
119-
}
112+
zend_call_known_fcc(fc, NULL, 1, &zarg, NULL);
120113
zval_ptr_dtor(&zarg);
121-
if (ret == FAILURE) {
122-
pdo_raise_impl_error(dbh, NULL, "HY000", "could not call user-supplied function");
123-
}
124114
}
125115
}
126116
/* }}} */
@@ -145,7 +135,7 @@ static void pdo_pgsql_fetch_error_func(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *i
145135
static void pdo_pgsql_cleanup_notice_callback(pdo_pgsql_db_handle *H) /* {{{ */
146136
{
147137
if (H->notice_callback) {
148-
zval_ptr_dtor(&H->notice_callback->fci.function_name);
138+
zend_fcc_dtor(H->notice_callback);
149139
efree(H->notice_callback);
150140
H->notice_callback = NULL;
151141
}
@@ -1256,46 +1246,27 @@ PHP_METHOD(PDO_PGSql_Ext, pgsqlGetPid)
12561246
Sets a callback to receive DB notices (after client_min_messages has been set) */
12571247
PHP_METHOD(PDO_PGSql_Ext, pgsqlSetNoticeCallback)
12581248
{
1259-
zval *callback;
1260-
zend_string *cbname;
12611249
pdo_dbh_t *dbh;
12621250
pdo_pgsql_db_handle *H;
1263-
pdo_pgsql_fci *fc;
1264-
1265-
if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS(), "z", &callback)) {
1266-
RETURN_FALSE;
1267-
}
1251+
zend_fcall_info fci = empty_fcall_info;
1252+
zend_fcall_info_cache fcc = empty_fcall_info_cache;
12681253

12691254
dbh = Z_PDO_DBH_P(getThis());
12701255
PDO_CONSTRUCT_CHECK;
12711256

12721257
H = (pdo_pgsql_db_handle *)dbh->driver_data;
1273-
1274-
if (Z_TYPE_P(callback) == IS_NULL) {
1275-
pdo_pgsql_cleanup_notice_callback(H);
1276-
RETURN_TRUE;
1277-
} else {
1278-
if (!(fc = H->notice_callback)) {
1279-
fc = (pdo_pgsql_fci*)ecalloc(1, sizeof(pdo_pgsql_fci));
1280-
} else {
1281-
zval_ptr_dtor(&fc->fci.function_name);
1282-
memcpy(&fc->fcc, &empty_fcall_info_cache, sizeof(fc->fcc));
1283-
}
1284-
1285-
if (FAILURE == zend_fcall_info_init(callback, 0, &fc->fci, &fc->fcc, &cbname, NULL)) {
1286-
php_error_docref(NULL, E_WARNING, "function '%s' is not callable", ZSTR_VAL(cbname));
1287-
zend_string_release_ex(cbname, 0);
1288-
efree(fc);
1289-
H->notice_callback = NULL;
1290-
RETURN_FALSE;
1291-
}
1292-
Z_TRY_ADDREF_P(&fc->fci.function_name);
1293-
zend_string_release_ex(cbname, 0);
1294-
1295-
H->notice_callback = fc;
1296-
1297-
RETURN_TRUE;
1258+
1259+
pdo_pgsql_cleanup_notice_callback(H);
1260+
if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS(), "F!", &fci, &fcc)) {
1261+
RETURN_FALSE;
12981262
}
1263+
1264+
if (ZEND_FCC_INITIALIZED(fcc)) {
1265+
H->notice_callback = ecalloc(1, sizeof(zend_fcall_info_cache));
1266+
zend_fcc_dup(H->notice_callback, &fcc);
1267+
}
1268+
1269+
RETURN_TRUE;
12991270
}
13001271
/* }}} */
13011272

ext/pdo_pgsql/php_pdo_pgsql_int.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,6 @@ typedef struct {
3232
char *errmsg;
3333
} pdo_pgsql_error_info;
3434

35-
typedef struct {
36-
zend_fcall_info fci;
37-
zend_fcall_info_cache fcc;
38-
} pdo_pgsql_fci;
39-
4035
/* stuff we use in a pgsql database handle */
4136
typedef struct {
4237
PGconn *server;
@@ -51,7 +46,7 @@ typedef struct {
5146
bool disable_native_prepares; /* deprecated since 5.6 */
5247
bool disable_prepares;
5348
HashTable *lob_streams;
54-
pdo_pgsql_fci * notice_callback;
49+
zend_fcall_info_cache *notice_callback;
5550
} pdo_pgsql_db_handle;
5651

5752
typedef struct {

0 commit comments

Comments
 (0)