#At file:///home/thek/bzr/mysql-5.5-bugteam/ based on revid:bar@stripped
3095 Kristofer Pettersson 2010-10-25
Bug#54569 Some options are not allowed to take argument when passed with loose- prefix
Boolean options cause parsing failures when they are given
with prefix loose- and an argument, either in the command
line or in configuration file.
The reason was a faulty logic which forced the parsing
to throw an error when an argument of type NO_ARG was
used together with an argument which has been identified
as a key-value pair. Despite the attribute NO_ARG these
options actually take arguments if they are of type
BOOL.
@ include/my_getopt.h
* More comments to help future refactoring
@ mysys/my_getopt.c
* removed if-statement which prevented logic for handling boolean types with arguments to be executed.
* Added comments to aid in future refactoring.
modified:
include/my_getopt.h
mysys/my_getopt.c
=== modified file 'include/my_getopt.h'
--- a/include/my_getopt.h 2010-06-11 01:30:49 +0000
+++ b/include/my_getopt.h 2010-10-25 12:30:07 +0000
@@ -39,6 +39,13 @@ C_MODE_START
#define GET_ASK_ADDR 128
#define GET_TYPE_MASK 127
+/**
+ Enumeration of the my_option::arg_type attributes.
+ It should be noted that for historical reasons variables with the combination
+ arg_type=NO_ARG, my_option::var_type=GET_BOOL still accepts
+ arguments. This is someone counter intuitive and care should be taken
+ if the code is refactored.
+*/
enum get_opt_arg_type { NO_ARG, OPT_ARG, REQUIRED_ARG };
struct st_typelib;
=== modified file 'mysys/my_getopt.c'
--- a/mysys/my_getopt.c 2010-09-28 15:15:58 +0000
+++ b/mysys/my_getopt.c 2010-10-25 12:30:07 +0000
@@ -360,14 +360,6 @@ int handle_options(int *argc, char ***ar
}
return EXIT_OPTION_DISABLED;
}
- if (must_be_var && optp->arg_type == NO_ARG)
- {
- if (my_getopt_print_errors)
- my_getopt_error_reporter(ERROR_LEVEL,
- "%s: option '%s' cannot take an argument",
- my_progname, optp->name);
- return EXIT_NO_ARGUMENT_ALLOWED;
- }
error= 0;
value= optp->var_type & GET_ASK_ADDR ?
(*getopt_get_addr)(key_name, (uint) strlen(key_name), optp, &error) :
@@ -377,6 +369,11 @@ int handle_options(int *argc, char ***ar
if (optp->arg_type == NO_ARG)
{
+ /*
+ Due to historical reasons GET_BOOL var_types still accepts arguments
+ despite the NO_ARG arg_type attribute. This can seems a bit unintuitive
+ and care should be taken when refactoring this code.
+ */
if (optend && (optp->var_type & GET_TYPE_MASK) != GET_BOOL)
{
if (my_getopt_print_errors)
@@ -391,7 +388,7 @@ int handle_options(int *argc, char ***ar
Set bool to 1 if no argument or if the user has used
--enable-'option-name'.
*optend was set to '0' if one used --disable-option
- */
+ */
(*argc)--;
if (!optend || *optend == '1' ||
!my_strcasecmp(&my_charset_latin1, optend, "true"))
@@ -418,10 +415,9 @@ int handle_options(int *argc, char ***ar
else if (optp->arg_type == REQUIRED_ARG && !optend)
{
/* Check if there are more arguments after this one,
-
- Note: options loaded from config file that requires value
- should always be in the form '--option=value'.
- */
+ Note: options loaded from config file that requires value
+ should always be in the form '--option=value'.
+ */
if (!is_cmdline_arg || !*++pos)
{
if (my_getopt_print_errors)
Attachment: [text/bzr-bundle] bzr/kristofer.pettersson@oracle.com-20101025123007-by58sn2aouyqrjj2.bundle
| Thread |
|---|
| • bzr commit into mysql-5.5-bugteam branch (kristofer.pettersson:3095)Bug#54569 | Kristofer Pettersson | 25 Oct |