[Click] Parsing String through cp_va_kparse

Cliff Frey cliff at meraki.com
Sat Jun 20 03:09:04 EDT 2009


you cannot pass a String object in directly to a printf-like function using
%s.  You need to use the .c_str() method.

   errh->error("XXX: %s capacity %d, data %s", __FUNCTION__,new_capacity,
data.c_str());

should fix your error (which turns into an abort).

However, I'd recommend using

   errh->error("XXX: %{element} capacity %d, data %s", this, new_capacity,
data.c_str());

for even more clarity.

Cliff

On Fri, Jun 19, 2009 at 10:52 PM, Yogesh Mundada <yhm at cc.gatech.edu> wrote:

> Hi,
>
> I am trying to parse a string variable using cp_va_kparse(). However,
> click crashes at install time.
> To debug further, I created another dummy element from samplepackage
> called sqdummy. I first tried to parse only int type that worked fine.
> Then I added String as follows:
>
> int
> Sqdummy::configure(Vector<String> &conf, ErrorHandler *errh)
> {
>    int new_capacity = 1000;
>    String data;
>    if (cp_va_kparse(conf, this, errh,
>                     "CAPACITY", cpkP, cpUnsigned, &new_capacity,
>                     "DATA", cpkP, cpString, &data,
>                     cpEnd) < 0)
>        return -1;
>    errh->error("XXX: %s capacity %d, data %s",
> __FUNCTION__,new_capacity, data);
>    return 0;
> }
>
> I got following compiler warnings:
>
> gmake[1]: Entering directory `/data/click/userlevel'
>  CXX ../elements/sqdummy/sqdummy.cc
> ../elements/sqdummy/sqdummy.cc: In member function ‘virtual int
> Sqdummy::configure(Vector<String>&, ErrorHandler*)’:
> ../elements/sqdummy/sqdummy.cc:30: warning: cannot pass objects of
> non-POD type ‘class String’ through ‘...’; call will abort at runtime
> ../elements/sqdummy/sqdummy.cc: At global scope:
> ../elements/sqdummy/sqdummy.cc:35: warning: unused parameter ‘errh’
>  CXX elements.cc
>
> (Not sure why String becomes non-POD)
>
> If I install click using click-install, then click router crashes
> (with a backtrace in dmesg). However, clickfs remains mounted. Any
> further calls to click-uninstall, click-install or "ls /click" hangs.
> To do any further click operations, I have to reboot the machine.
>
> I checked the documentation for confparse.hh and I dont seem to be
> doing anything wrong. There are other classes like todevice,
> fromdevice that also try to parse "String _devname" (defined in
> anydevice.hh) and I guess those work just fine. But I am not sure what
> I am missing here.
>
> Any help will be greatly appreciated.
>
> -Yogesh
>
> _______________________________________________
> click mailing list
> click at amsterdam.lcs.mit.edu
> https://amsterdam.lcs.mit.edu/mailman/listinfo/click
>


More information about the click mailing list