[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Confuse-devel] cfg_getsec() assertions [Was: Re: libconfuse help (seve
From: |
Ademar de Souza Reis Jr. |
Subject: |
[Confuse-devel] cfg_getsec() assertions [Was: Re: libconfuse help (several questions)] |
Date: |
Mon, 28 Apr 2003 23:53:11 -0300 |
User-agent: |
Mutt/1.5.4i |
On Mon, Apr 28, 2003 at 09:47:19AM +0200, Martin Hedenfalk wrote:
> On Sun, 27 Apr 2003 22:32:19 -0300
> "Ademar de Souza Reis Jr." <address@hidden> wrote:
>
> >
> > Getting a segfault just because you commented out some parts of your
> > config file is really annoying (I was stuck in this problem for some
> > time) :)
>
> Well it's not really a bug, I would rather call it unclear documentation
> :-) And I agree that one can argue if having an assertion instead of
> returning NULL is the most intuitive.
>
> There are a lot of assertions in the code, to "protect" against misuse
> of the API. I felt this was necessary because the library uses a lot of
> casts and the compiler won't warn against wrong arguments. However, the
> library should not abort due to unexpected or left out options in the
> configuration file.
>
> As it is now, the cfg_getXXX functions returns zero if the option is not
> declared (with the CFG_XXX macros) and an assertion is raised if you try
> to access a nonexistent index. Since sections can't have default values,
> an assertion is raised even on index 0 (zero).
>
I think it would make more sense to invert the logic here: What about
raising an exception when there's a coding mistake (a section name not
declared is called) but returning 0 when some section, declared, is not
found?
May be just turning the exception into a return would be better (for cases
where the section name is passed at runtime or something like that).
> The function cfg_size() should be used to check the number of values. So
> your code should be changed to something like:
>
> if(cfg_size(cfg, "sectionname"))
> sec = cfg_getsec(cfg, "sectionname"))
>
> I'm open for a discussion about what's the Right Way to do this.
Calling cfg_size() just to see if a section name exists before calling a
"get" function looks very counterintuitive. Actually, it just makes no sense
to me (generally speaking, "size 0" != "non existent" object). So, based on
what I know of libconfuse so far, I would vote for changing that assertion
into a return statement.
Thanks.
--
Ademar de Souza Reis Jr. <address@hidden>
http://www.ademar.org
I use Linux!!! I have a host, not a MyComputer.
^[:wq!