confuse-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Confuse-devel] Is arbitrary nesting possible


From: Michael Arntzenius
Subject: [Confuse-devel] Is arbitrary nesting possible
Date: Wed, 7 May 2008 11:54:50 -0400

I was trying out libconfuse to see whether it would be appropriate for
a small project of mine. One thing I did was allow a section to
contain instances of itself, thus allowing arbitrary nesting, using
code somewhat like the following, except more useful:

static cfg_opt_t opts[] = { CFG_INT("value", 0, CFGF_NONE),
CFG_SEC("this", opts, CFGF_NONE), CFG_END() }

The corresponding configuration file could then look something like
this, I imagine:

value = 2 this { value = -4 this { value = 0 this { ... arbitrarily
nested ... }}}

When I call "cfg_init" on "opts", it runs out of stack space. There
are two instances of infinite recursion here - cfg_dupopt_array and
cfg_init_defaults. I fixed this by crudely memoizing them; however,
after doing this, only the most nested instance of a recursive section
is used. So if I have a config file "test.conf":

value = 0 this { value = 1 this { value = 2 }}

And the following code:

cfg_t *cfg = cfg_init(opts, CFGF_NONE);
cfg_parse(cfg, "test.conf");
int val = cfg_getint(cfg, "value");

"val" ends up having the value 2. Perhaps I'm doing something wrong in
the latter example, but if not, may I ask: is libconfuse at least
theoretically (ignoring the recursion problem, which can be fixed)
able to parse arbitrarily-nested sections? And if not, would you ever
consider adding this ability?

- Michael Arntzenius




reply via email to

[Prev in Thread] Current Thread [Next in Thread]