alsa-project / alsa-lib

The Advanced Linux Sound Architecture (ALSA) - library
GNU Lesser General Public License v2.1
366 stars 177 forks source link

[Bug] Duplication in Array Element not Handled in Parsing conf #151

Closed aiChaoSONG closed 3 years ago

aiChaoSONG commented 3 years ago

When parsing array element in conf files, an auto-increase number is used as config id(snd_config_t->id), and array element as the config value(snd_config_t->u.string/integer/integer64/real), duplication is not handle in parse_array_defs/parse_array_def/parse_value functions.

Suppose we have a conf:

array [
    "a"
    "b"
    "a"
]

the parsed result will be:

    parent
        |
        ---- snd_config_t {id: "0", u.string: "a"}
        |
        ---- snd_config_t {id: "1", u.string: "b"}
        |
        ---- snd_config_t {id: "2", u.string: "a"}

The duplication in "a" may be desired. But please consider this condition: suppose we have four conf files A, B, C and D, where A is the conf above, let B include A, C include A, D include B and C, so D include A twice indirectly. File A will be processed twice when parsing D, because duplication is not handled, here comes the problem, the parsed result of A in D is:

    parent
        |
        ---- snd_config_t {id: "0", u.string: "a"}
        |
        ---- snd_config_t {id: "1", u.string: "b"}
        |
        ---- snd_config_t {id: "2", u.string: "a"}
        |
        ---- snd_config_t {id: "3", u.string: "a"}
        |
        ---- snd_config_t {id: "4", u.string: "b"}
        |
        ---- snd_config_t {id: "5", u.string: "a"}

This is obviously wrong.

I think handle duplication in parse_value is not the solution, because element duplication in an array is wanted. The key problem here is that we parse the same conf more than once.

perexg commented 3 years ago

The array merging is a function when the parsing mode is merge. You can force to override the configuration element using ! prefix. You're probably talking about recent bug fixed in ddfc32abf5697de1618b9e7ffdf57a0f97013090 .

perexg commented 3 years ago

So:

array [ a b c ]
!array [ d e f ]
aiChaoSONG commented 3 years ago

@perexg Thank you, ! is a magic operator for conf