[Click] ANNOUNCE/RFC: Type-safe argument parsing

Eddie Kohler kohler at cs.ucla.edu
Thu Apr 28 16:26:14 EDT 2011


Hi all,

A longstanding Click annoyance is argument parsing, which has been rewritten 
more than once.

There are still problems with the current cp_va_kparse versions.

- Type safety: Did you know that this is a serious bug, that the compiler 
cannot catch?

#include <click/confparse.hh>
bool b;
...
if (cp_va_kparse(conf, this, errh,
              "I_FORGOT_WHAT_B_WAS", cpkP+cpkM, cpInteger, &b,
              cpEnd) < 0)
     return -1;

- Multithread safety: Did you know that if cp_va_kparse is called in parallel 
in two threads, the two calls will unsafely collide on a static array of 
"cp_value" objects?

- Multithread safety: Did you know that cp_integer() and friends set a global 
variable, cp_errno -- and that cp_errno settings can collide across threads?

-*-

The github "argparse" branch, which will soon be shifted to master, fixes 
these problems with a new Args class.  Args is much nicer to type and read 
than cp_va.

#include <click/args.hh>
bool b;
...
if (Args(conf, this, errh)
     .read_mp("B", b)
     .complete() < 0)
     return -1;

There are other advantages: it's easier and cleaner to write and refer to new 
parser types, for example.

-*-

I am interested in feedback and comments.  Please look and report any 
problems.  Thanks to Cliff for discussion.

Eddie


More information about the click mailing list