Skip to content

Commit fc6c8f5

Browse files
author
Ilia Alshanetsky
committed
Improved parameter handling
1 parent b32d357 commit fc6c8f5

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

ext/readline/readline.c

+8-9
Original file line numberDiff line numberDiff line change
@@ -216,17 +216,16 @@ PHP_FUNCTION(readline)
216216
Gets/sets various internal readline variables. */
217217
PHP_FUNCTION(readline_info)
218218
{
219-
char *what;
220-
zval **value;
219+
char *what = NULL;
220+
zval **value = NULL;
221221
int what_len, oldval;
222222
char *oldstr;
223-
int ac = ZEND_NUM_ARGS();
224223

225224
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sZ", &what, &what_len, &value) == FAILURE) {
226225
return;
227226
}
228227

229-
if (ac == 0) {
228+
if (what) {
230229
array_init(return_value);
231230
add_assoc_string(return_value,"line_buffer",SAFE_STRING(rl_line_buffer),1);
232231
add_assoc_long(return_value,"point",rl_point);
@@ -246,7 +245,7 @@ PHP_FUNCTION(readline_info)
246245
} else {
247246
if (!strcasecmp(what,"line_buffer")) {
248247
oldstr = rl_line_buffer;
249-
if (ac == 2) {
248+
if (value) {
250249
/* XXX if (rl_line_buffer) free(rl_line_buffer); */
251250
convert_to_string_ex(value);
252251
rl_line_buffer = strdup(Z_STRVAL_PP(value));
@@ -261,14 +260,14 @@ PHP_FUNCTION(readline_info)
261260
RETVAL_LONG(rl_mark);
262261
} else if (!strcasecmp(what, "done")) {
263262
oldval = rl_done;
264-
if (ac == 2) {
263+
if (value) {
265264
convert_to_long_ex(value);
266265
rl_done = Z_LVAL_PP(value);
267266
}
268267
RETVAL_LONG(oldval);
269268
} else if (!strcasecmp(what, "pending_input")) {
270269
oldval = rl_pending_input;
271-
if (ac == 2) {
270+
if (value) {
272271
convert_to_string_ex(value);
273272
rl_pending_input = Z_STRVAL_PP(value)[0];
274273
}
@@ -281,7 +280,7 @@ PHP_FUNCTION(readline_info)
281280
#if HAVE_ERASE_EMPTY_LINE
282281
} else if (!strcasecmp(what, "erase_empty_line")) {
283282
oldval = rl_erase_empty_line;
284-
if (ac == 2) {
283+
if (value) {
285284
convert_to_long_ex(value);
286285
rl_erase_empty_line = Z_LVAL_PP(value);
287286
}
@@ -291,7 +290,7 @@ PHP_FUNCTION(readline_info)
291290
RETVAL_STRING((char *)SAFE_STRING(rl_library_version),1);
292291
} else if (!strcasecmp(what, "readline_name")) {
293292
oldstr = (char*)rl_readline_name;
294-
if (ac == 2) {
293+
if (value) {
295294
/* XXX if (rl_readline_name) free(rl_readline_name); */
296295
convert_to_string_ex(value);
297296
rl_readline_name = strdup(Z_STRVAL_PP(value));;

0 commit comments

Comments
 (0)