Skip to content

Commit d5bb199

Browse files
committed
- MFH: New parameter parsing API
1 parent a9132bb commit d5bb199

File tree

4 files changed

+53
-41
lines changed

4 files changed

+53
-41
lines changed

ext/interbase/ibase_events.c

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,9 @@ static void _php_ibase_event_block(ibase_db_link *ib_link, unsigned short count,
126126
Waits for any one of the passed Interbase events to be posted by the database, and returns its name */
127127
PHP_FUNCTION(ibase_wait_event)
128128
{
129-
zval **args[16];
129+
zval ***args;
130130
ibase_db_link *ib_link;
131+
int num_args;
131132
char *event_buffer, *result_buffer, *events[15];
132133
unsigned short i = 0, event_count = 0, buffer_size;
133134
unsigned long occurred_event[15];
@@ -139,22 +140,25 @@ PHP_FUNCTION(ibase_wait_event)
139140
WRONG_PARAM_COUNT;
140141
}
141142

142-
if (zend_get_parameters_array_ex(ZEND_NUM_ARGS(), args) == FAILURE) {
143-
RETURN_FALSE;
143+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "+", &args, &num_args) == FAILURE) {
144+
return;
144145
}
145146

146147
if (Z_TYPE_PP(args[0]) == IS_RESOURCE) {
147-
148-
ZEND_FETCH_RESOURCE2(ib_link, ibase_db_link *, args[0], -1, "InterBase link", le_link, le_plink);
148+
if (!ZEND_FETCH_RESOURCE2_NO_RETURN(ib_link, ibase_db_link *, args[0], -1, "InterBase link", le_link, le_plink)) {
149+
efree(args);
150+
RETURN_FALSE;
151+
}
149152
i = 1;
150-
151153
} else {
152-
153154
if (ZEND_NUM_ARGS() > 15) {
155+
efree(args);
154156
WRONG_PARAM_COUNT;
155157
}
156-
157-
ZEND_FETCH_RESOURCE2(ib_link, ibase_db_link *, NULL, IBG(default_link), "InterBase link", le_link, le_plink);
158+
if (!ZEND_FETCH_RESOURCE2_NO_RETURN(ib_link, ibase_db_link *, NULL, IBG(default_link), "InterBase link", le_link, le_plink)) {
159+
efree(args);
160+
RETURN_FALSE;
161+
}
158162
}
159163

160164
for (; i < ZEND_NUM_ARGS(); ++i) {
@@ -169,6 +173,7 @@ PHP_FUNCTION(ibase_wait_event)
169173
if (isc_wait_for_event(IB_STATUS, &ib_link->handle, buffer_size, event_buffer, result_buffer)) {
170174
_php_ibase_error(TSRMLS_C);
171175
_php_ibase_event_free(event_buffer,result_buffer);
176+
efree(args);
172177
RETURN_FALSE;
173178
}
174179

@@ -178,13 +183,15 @@ PHP_FUNCTION(ibase_wait_event)
178183
if (occurred_event[i]) {
179184
char *result = estrdup(events[i]);
180185
_php_ibase_event_free(event_buffer,result_buffer);
186+
efree(args);
181187
RETURN_STRING(result,0);
182188
}
183189
}
184190

185191
/* If we reach this line, isc_wait_for_event() did return, but we don't know
186192
which event fired. */
187193
_php_ibase_event_free(event_buffer,result_buffer);
194+
efree(args);
188195
RETURN_FALSE;
189196
}
190197
/* }}} */
@@ -261,11 +268,11 @@ PHP_FUNCTION(ibase_set_event_handler)
261268
* used to determine if the event handler should remain set.
262269
*/
263270
char *cb_name;
264-
zval **args[17], **cb_arg;
271+
zval ***args, **cb_arg;
265272
ibase_db_link *ib_link;
266273
ibase_event *event;
267274
unsigned short i = 1, buffer_size;
268-
int link_res_id;
275+
int link_res_id, num_args;
269276

270277
RESET_ERRMSG;
271278

@@ -274,8 +281,8 @@ PHP_FUNCTION(ibase_set_event_handler)
274281
WRONG_PARAM_COUNT;
275282
}
276283

277-
if (zend_get_parameters_array_ex(ZEND_NUM_ARGS(), args) == FAILURE) {
278-
RETURN_FALSE;
284+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "+", &args, &num_args) == FAILURE) {
285+
return;
279286
}
280287

281288
/* get a working link */
@@ -284,14 +291,17 @@ PHP_FUNCTION(ibase_set_event_handler)
284291
* No more than 15 events
285292
*/
286293
if (ZEND_NUM_ARGS() < 3 || ZEND_NUM_ARGS() > 17) {
294+
efree(args);
287295
WRONG_PARAM_COUNT;
288296
}
289297

290298
cb_arg = args[1];
291299
i = 2;
292300

293-
ZEND_FETCH_RESOURCE2(ib_link, ibase_db_link *, args[0], -1,
294-
"InterBase link", le_link, le_plink);
301+
if (!ZEND_FETCH_RESOURCE2_NO_RETURN(ib_link, ibase_db_link *, args[0], -1, "InterBase link", le_link, le_plink)) {
302+
efree(args);
303+
RETURN_FALSE;
304+
}
295305

296306
convert_to_long_ex(args[0]);
297307
link_res_id = Z_LVAL_PP(args[0]);
@@ -301,20 +311,24 @@ PHP_FUNCTION(ibase_set_event_handler)
301311
* No more than 15 events
302312
*/
303313
if (ZEND_NUM_ARGS() < 2 || ZEND_NUM_ARGS() > 16) {
314+
efree(args);
304315
WRONG_PARAM_COUNT;
305316
}
306317

307318
cb_arg = args[0];
308319

309-
ZEND_FETCH_RESOURCE2(ib_link, ibase_db_link *, NULL, IBG(default_link),
310-
"InterBase link", le_link, le_plink);
320+
if (!ZEND_FETCH_RESOURCE2_NO_RETURN(ib_link, ibase_db_link *, NULL, IBG(default_link), "InterBase link", le_link, le_plink)) {
321+
efree(args);
322+
RETURN_FALSE;
323+
}
311324
link_res_id = IBG(default_link);
312325
}
313326

314327
/* get the callback */
315328
if (!zend_is_callable(*cb_arg, 0, &cb_name TSRMLS_CC)) {
316329
_php_ibase_module_error("Callback argument %s is not a callable function" TSRMLS_CC, cb_name);
317330
efree(cb_name);
331+
efree(args);
318332
RETURN_FALSE;
319333
}
320334
efree(cb_name);
@@ -348,6 +362,7 @@ PHP_FUNCTION(ibase_set_event_handler)
348362

349363
_php_ibase_error(TSRMLS_C);
350364
efree(event);
365+
efree(args);
351366
RETURN_FALSE;
352367
}
353368

@@ -356,6 +371,7 @@ PHP_FUNCTION(ibase_set_event_handler)
356371

357372
ZEND_REGISTER_RESOURCE(return_value, event, le_event);
358373
zend_list_addref(Z_LVAL_P(return_value));
374+
efree(args);
359375
}
360376
/* }}} */
361377

ext/interbase/ibase_query.c

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,7 +1070,7 @@ PHP_FUNCTION(ibase_query)
10701070
{
10711071
zval *zlink, *ztrans, ***bind_args = NULL;
10721072
char *query;
1073-
int bind_i, query_len;
1073+
int bind_i, query_len, bind_num;
10741074
long trans_res_id = 0;
10751075
ibase_db_link *ib_link = NULL;
10761076
ibase_trans *trans = NULL;
@@ -1176,11 +1176,9 @@ PHP_FUNCTION(ibase_query)
11761176
if (bind_n < expected_n) {
11771177
break;
11781178
}
1179-
} else if (bind_n > 0) {
1180-
bind_args = (zval ***) safe_emalloc(sizeof(zval **), ZEND_NUM_ARGS(), 0);
1181-
1182-
if (FAILURE == zend_get_parameters_array_ex(ZEND_NUM_ARGS(), bind_args)) {
1183-
break;
1179+
} else if (bind_n > 0) {
1180+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "+", &bind_args, &bind_num) == FAILURE) {
1181+
return;
11841182
}
11851183
}
11861184

@@ -1491,7 +1489,6 @@ static int _php_ibase_arr_zval(zval *ar_zval, char *data, unsigned long data_siz
14911489
static void _php_ibase_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, int fetch_type) /* {{{ */
14921490
{
14931491
zval *result_arg;
1494-
long flag_arg;
14951492
long i, array_cnt = 0, flag = 0;
14961493
ibase_result *ib_result;
14971494

@@ -2059,16 +2056,16 @@ PHP_FUNCTION(ibase_field_info)
20592056
Get the number of params in a prepared query */
20602057
PHP_FUNCTION(ibase_num_params)
20612058
{
2062-
zval **result;
2059+
zval *result;
20632060
ibase_query *ib_query;
20642061

20652062
RESET_ERRMSG;
20662063

2067-
if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &result) == FAILURE) {
2068-
WRONG_PARAM_COUNT;
2064+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &result) == FAILURE) {
2065+
return;
20692066
}
20702067

2071-
ZEND_FETCH_RESOURCE(ib_query, ibase_query *, result, -1, LE_QUERY, le_query);
2068+
ZEND_FETCH_RESOURCE(ib_query, ibase_query *, &result, -1, LE_QUERY, le_query);
20722069

20732070
if (ib_query->in_sqlda == NULL) {
20742071
RETURN_LONG(0);
@@ -2082,28 +2079,27 @@ PHP_FUNCTION(ibase_num_params)
20822079
Get information about a parameter */
20832080
PHP_FUNCTION(ibase_param_info)
20842081
{
2085-
zval **result_arg, **field_arg;
2082+
zval *result_arg;
2083+
long field_arg;
20862084
ibase_query *ib_query;
20872085

20882086
RESET_ERRMSG;
20892087

2090-
if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &result_arg, &field_arg) == FAILURE) {
2091-
WRONG_PARAM_COUNT;
2088+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &result_arg, &field_arg) == FAILURE) {
2089+
return;
20922090
}
20932091

2094-
ZEND_FETCH_RESOURCE(ib_query, ibase_query *, result_arg, -1, LE_QUERY, le_query);
2092+
ZEND_FETCH_RESOURCE(ib_query, ibase_query *, &result_arg, -1, LE_QUERY, le_query);
20952093

20962094
if (ib_query->in_sqlda == NULL) {
20972095
RETURN_FALSE;
20982096
}
20992097

2100-
convert_to_long_ex(field_arg);
2101-
2102-
if (Z_LVAL_PP(field_arg) < 0 || Z_LVAL_PP(field_arg) >= ib_query->in_sqlda->sqld) {
2098+
if (field_arg < 0 || field_arg >= ib_query->in_sqlda->sqld) {
21032099
RETURN_FALSE;
21042100
}
21052101

2106-
_php_ibase_field_info(return_value,ib_query->in_sqlda->sqlvar + Z_LVAL_PP(field_arg));
2102+
_php_ibase_field_info(return_value,ib_query->in_sqlda->sqlvar + field_arg);
21072103
}
21082104
/* }}} */
21092105

ext/interbase/tests/ibase_num_params_001.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ var_dump(ibase_num_params($rs));
2323
--EXPECTF--
2424
int(2)
2525

26-
Warning: Wrong parameter count for ibase_num_params() in %s on line %d
26+
Warning: ibase_num_params() expects exactly 1 parameter, 0 given in %s on line %d
2727
NULL
2828

29-
Warning: ibase_prepare(): Dynamic SQL Error SQL error code = -206 Column unknown X At line 1, column 52%s in %s on line %d
29+
Warning: ibase_prepare(): Dynamic SQL Error SQL error code = -206 Column unknown X At line 1, column 52 in %s on line %d
3030

31-
Warning: ibase_num_params(): supplied argument is not a valid Firebird/InterBase query resource in %s on line %d
32-
bool(false)
31+
Warning: ibase_num_params() expects parameter 1 to be resource, boolean given in %s on line %d
32+
NULL

ext/interbase/tests/ibase_param_info_001.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,5 @@ array(10) {
4949
bool(false)
5050
---
5151

52-
Warning: Wrong parameter count for ibase_param_info() in %s on line %d
52+
Warning: ibase_param_info() expects exactly 2 parameters, 1 given in %s on line %d
5353
NULL

0 commit comments

Comments
 (0)