diff options
author | Felipe Pena <felipe@php.net> | 2008-11-27 02:17:22 +0000 |
---|---|---|
committer | Felipe Pena <felipe@php.net> | 2008-11-27 02:17:22 +0000 |
commit | d5bb19938d3b936deb8098d161984fa50eee89fc (patch) | |
tree | 61e0a9efb965619b6aab64ddc002b3d583fd9e55 /ext/interbase | |
parent | a9132bb75f6275a855a9fe3ee9d378bfaa7b0088 (diff) | |
download | php-git-d5bb19938d3b936deb8098d161984fa50eee89fc.tar.gz |
- MFH: New parameter parsing API
Diffstat (limited to 'ext/interbase')
-rw-r--r-- | ext/interbase/ibase_events.c | 50 | ||||
-rw-r--r-- | ext/interbase/ibase_query.c | 34 | ||||
-rw-r--r-- | ext/interbase/tests/ibase_num_params_001.phpt | 8 | ||||
-rw-r--r-- | ext/interbase/tests/ibase_param_info_001.phpt | 2 |
4 files changed, 53 insertions, 41 deletions
diff --git a/ext/interbase/ibase_events.c b/ext/interbase/ibase_events.c index 09cf99ef8c..64842dd505 100644 --- a/ext/interbase/ibase_events.c +++ b/ext/interbase/ibase_events.c @@ -126,8 +126,9 @@ static void _php_ibase_event_block(ibase_db_link *ib_link, unsigned short count, Waits for any one of the passed Interbase events to be posted by the database, and returns its name */ PHP_FUNCTION(ibase_wait_event) { - zval **args[16]; + zval ***args; ibase_db_link *ib_link; + int num_args; char *event_buffer, *result_buffer, *events[15]; unsigned short i = 0, event_count = 0, buffer_size; unsigned long occurred_event[15]; @@ -139,22 +140,25 @@ PHP_FUNCTION(ibase_wait_event) WRONG_PARAM_COUNT; } - if (zend_get_parameters_array_ex(ZEND_NUM_ARGS(), args) == FAILURE) { - RETURN_FALSE; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "+", &args, &num_args) == FAILURE) { + return; } if (Z_TYPE_PP(args[0]) == IS_RESOURCE) { - - ZEND_FETCH_RESOURCE2(ib_link, ibase_db_link *, args[0], -1, "InterBase link", le_link, le_plink); + if (!ZEND_FETCH_RESOURCE2_NO_RETURN(ib_link, ibase_db_link *, args[0], -1, "InterBase link", le_link, le_plink)) { + efree(args); + RETURN_FALSE; + } i = 1; - } else { - if (ZEND_NUM_ARGS() > 15) { + efree(args); WRONG_PARAM_COUNT; } - - ZEND_FETCH_RESOURCE2(ib_link, ibase_db_link *, NULL, IBG(default_link), "InterBase link", le_link, le_plink); + if (!ZEND_FETCH_RESOURCE2_NO_RETURN(ib_link, ibase_db_link *, NULL, IBG(default_link), "InterBase link", le_link, le_plink)) { + efree(args); + RETURN_FALSE; + } } for (; i < ZEND_NUM_ARGS(); ++i) { @@ -169,6 +173,7 @@ PHP_FUNCTION(ibase_wait_event) if (isc_wait_for_event(IB_STATUS, &ib_link->handle, buffer_size, event_buffer, result_buffer)) { _php_ibase_error(TSRMLS_C); _php_ibase_event_free(event_buffer,result_buffer); + efree(args); RETURN_FALSE; } @@ -178,6 +183,7 @@ PHP_FUNCTION(ibase_wait_event) if (occurred_event[i]) { char *result = estrdup(events[i]); _php_ibase_event_free(event_buffer,result_buffer); + efree(args); RETURN_STRING(result,0); } } @@ -185,6 +191,7 @@ PHP_FUNCTION(ibase_wait_event) /* If we reach this line, isc_wait_for_event() did return, but we don't know which event fired. */ _php_ibase_event_free(event_buffer,result_buffer); + efree(args); RETURN_FALSE; } /* }}} */ @@ -261,11 +268,11 @@ PHP_FUNCTION(ibase_set_event_handler) * used to determine if the event handler should remain set. */ char *cb_name; - zval **args[17], **cb_arg; + zval ***args, **cb_arg; ibase_db_link *ib_link; ibase_event *event; unsigned short i = 1, buffer_size; - int link_res_id; + int link_res_id, num_args; RESET_ERRMSG; @@ -274,8 +281,8 @@ PHP_FUNCTION(ibase_set_event_handler) WRONG_PARAM_COUNT; } - if (zend_get_parameters_array_ex(ZEND_NUM_ARGS(), args) == FAILURE) { - RETURN_FALSE; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "+", &args, &num_args) == FAILURE) { + return; } /* get a working link */ @@ -284,14 +291,17 @@ PHP_FUNCTION(ibase_set_event_handler) * No more than 15 events */ if (ZEND_NUM_ARGS() < 3 || ZEND_NUM_ARGS() > 17) { + efree(args); WRONG_PARAM_COUNT; } cb_arg = args[1]; i = 2; - ZEND_FETCH_RESOURCE2(ib_link, ibase_db_link *, args[0], -1, - "InterBase link", le_link, le_plink); + if (!ZEND_FETCH_RESOURCE2_NO_RETURN(ib_link, ibase_db_link *, args[0], -1, "InterBase link", le_link, le_plink)) { + efree(args); + RETURN_FALSE; + } convert_to_long_ex(args[0]); link_res_id = Z_LVAL_PP(args[0]); @@ -301,13 +311,16 @@ PHP_FUNCTION(ibase_set_event_handler) * No more than 15 events */ if (ZEND_NUM_ARGS() < 2 || ZEND_NUM_ARGS() > 16) { + efree(args); WRONG_PARAM_COUNT; } cb_arg = args[0]; - ZEND_FETCH_RESOURCE2(ib_link, ibase_db_link *, NULL, IBG(default_link), - "InterBase link", le_link, le_plink); + if (!ZEND_FETCH_RESOURCE2_NO_RETURN(ib_link, ibase_db_link *, NULL, IBG(default_link), "InterBase link", le_link, le_plink)) { + efree(args); + RETURN_FALSE; + } link_res_id = IBG(default_link); } @@ -315,6 +328,7 @@ PHP_FUNCTION(ibase_set_event_handler) if (!zend_is_callable(*cb_arg, 0, &cb_name TSRMLS_CC)) { _php_ibase_module_error("Callback argument %s is not a callable function" TSRMLS_CC, cb_name); efree(cb_name); + efree(args); RETURN_FALSE; } efree(cb_name); @@ -348,6 +362,7 @@ PHP_FUNCTION(ibase_set_event_handler) _php_ibase_error(TSRMLS_C); efree(event); + efree(args); RETURN_FALSE; } @@ -356,6 +371,7 @@ PHP_FUNCTION(ibase_set_event_handler) ZEND_REGISTER_RESOURCE(return_value, event, le_event); zend_list_addref(Z_LVAL_P(return_value)); + efree(args); } /* }}} */ diff --git a/ext/interbase/ibase_query.c b/ext/interbase/ibase_query.c index c2568f66a0..9bc7b5102b 100644 --- a/ext/interbase/ibase_query.c +++ b/ext/interbase/ibase_query.c @@ -1070,7 +1070,7 @@ PHP_FUNCTION(ibase_query) { zval *zlink, *ztrans, ***bind_args = NULL; char *query; - int bind_i, query_len; + int bind_i, query_len, bind_num; long trans_res_id = 0; ibase_db_link *ib_link = NULL; ibase_trans *trans = NULL; @@ -1176,11 +1176,9 @@ PHP_FUNCTION(ibase_query) if (bind_n < expected_n) { break; } - } else if (bind_n > 0) { - bind_args = (zval ***) safe_emalloc(sizeof(zval **), ZEND_NUM_ARGS(), 0); - - if (FAILURE == zend_get_parameters_array_ex(ZEND_NUM_ARGS(), bind_args)) { - break; + } else if (bind_n > 0) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "+", &bind_args, &bind_num) == FAILURE) { + return; } } @@ -1491,7 +1489,6 @@ static int _php_ibase_arr_zval(zval *ar_zval, char *data, unsigned long data_siz static void _php_ibase_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, int fetch_type) /* {{{ */ { zval *result_arg; - long flag_arg; long i, array_cnt = 0, flag = 0; ibase_result *ib_result; @@ -2059,16 +2056,16 @@ PHP_FUNCTION(ibase_field_info) Get the number of params in a prepared query */ PHP_FUNCTION(ibase_num_params) { - zval **result; + zval *result; ibase_query *ib_query; RESET_ERRMSG; - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &result) == FAILURE) { - WRONG_PARAM_COUNT; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &result) == FAILURE) { + return; } - ZEND_FETCH_RESOURCE(ib_query, ibase_query *, result, -1, LE_QUERY, le_query); + ZEND_FETCH_RESOURCE(ib_query, ibase_query *, &result, -1, LE_QUERY, le_query); if (ib_query->in_sqlda == NULL) { RETURN_LONG(0); @@ -2082,28 +2079,27 @@ PHP_FUNCTION(ibase_num_params) Get information about a parameter */ PHP_FUNCTION(ibase_param_info) { - zval **result_arg, **field_arg; + zval *result_arg; + long field_arg; ibase_query *ib_query; RESET_ERRMSG; - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &result_arg, &field_arg) == FAILURE) { - WRONG_PARAM_COUNT; + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &result_arg, &field_arg) == FAILURE) { + return; } - ZEND_FETCH_RESOURCE(ib_query, ibase_query *, result_arg, -1, LE_QUERY, le_query); + ZEND_FETCH_RESOURCE(ib_query, ibase_query *, &result_arg, -1, LE_QUERY, le_query); if (ib_query->in_sqlda == NULL) { RETURN_FALSE; } - convert_to_long_ex(field_arg); - - if (Z_LVAL_PP(field_arg) < 0 || Z_LVAL_PP(field_arg) >= ib_query->in_sqlda->sqld) { + if (field_arg < 0 || field_arg >= ib_query->in_sqlda->sqld) { RETURN_FALSE; } - _php_ibase_field_info(return_value,ib_query->in_sqlda->sqlvar + Z_LVAL_PP(field_arg)); + _php_ibase_field_info(return_value,ib_query->in_sqlda->sqlvar + field_arg); } /* }}} */ diff --git a/ext/interbase/tests/ibase_num_params_001.phpt b/ext/interbase/tests/ibase_num_params_001.phpt index ec4fc8c4a8..b89f948412 100644 --- a/ext/interbase/tests/ibase_num_params_001.phpt +++ b/ext/interbase/tests/ibase_num_params_001.phpt @@ -23,10 +23,10 @@ var_dump(ibase_num_params($rs)); --EXPECTF-- int(2) -Warning: Wrong parameter count for ibase_num_params() in %s on line %d +Warning: ibase_num_params() expects exactly 1 parameter, 0 given in %s on line %d NULL -Warning: ibase_prepare(): Dynamic SQL Error SQL error code = -206 Column unknown X At line 1, column 52%s in %s on line %d +Warning: ibase_prepare(): Dynamic SQL Error SQL error code = -206 Column unknown X At line 1, column 52 in %s on line %d -Warning: ibase_num_params(): supplied argument is not a valid Firebird/InterBase query resource in %s on line %d -bool(false) +Warning: ibase_num_params() expects parameter 1 to be resource, boolean given in %s on line %d +NULL diff --git a/ext/interbase/tests/ibase_param_info_001.phpt b/ext/interbase/tests/ibase_param_info_001.phpt index c8054f683b..31fe196ce6 100644 --- a/ext/interbase/tests/ibase_param_info_001.phpt +++ b/ext/interbase/tests/ibase_param_info_001.phpt @@ -49,5 +49,5 @@ array(10) { bool(false) --- -Warning: Wrong parameter count for ibase_param_info() in %s on line %d +Warning: ibase_param_info() expects exactly 2 parameters, 1 given in %s on line %d NULL |