Re: Possible bug in karma

Seth <[email protected]> Mon, 24 Dec 2018 14:43:13 +0100
Newsgroups gmane.comp.parsers.spirit.general
Message-ID <[email protected]>
Op 19-12-18 om 08:46 schreef Stephan Menzel:
> Now the strange thing is, when I run this with optimization on
> (Windows, x64, MSVC141) it works correctly in ~99% of the cases. But
> not 100. It is also covered by a unit test, which I never have seen
> fail (optimized or not optimized).
>
> BOOST_CHECK_NO_THROW(line = generate_ok_line(2453452465346));
> BOOST_CHECK(line == "OK 2453452465346\r\n");
>
> Yet when I run this in the actual non-optimized server (built in the
> same solution with the same parameters, statically linked) it will
> produce something like this:
> "O 235\r"
> Always. The numbers vary but there's always only one 'O' and the '\n'
> is missing at the end. It never produces correct results in a Debug
> build when used within the server application. Which leads me to
> believe this might be some initialization / memory error. 

I agree. I've tried to look for anything wrong with the code, but didn't
immediately see it. If you make it a self-contained reproducer I'll give
it another whirl (possibly with the compiler you listed)

Op 19-12-18 om 08:46 schreef Stephan Menzel:
> I'm quite puzzled because of that and even though I can easily go for
> a simpler approach to save the day, I thought it might still be of
> interest for this list.

May I suggest, without any phoenix/semantic actions:

        start = omit[bool_(true)] << "OK " << skip[string] << ulong_long
<< "\r\n"
              | omit[bool_] << "ERR " << string << skip[ulong_long] <<
"\r\n";

See it live on Coliru: http://coliru.stacked-crooked.com/a/46ab1e0f51935dda

    std::string generate_ok_line(ok_line res) {
        std::string ret;
        karma::generate(back_inserter(ret), ok_line_generator<>{}, res);
        return ret;
    }

    #include <iomanip>

    int main() {
        for (auto res : { ok_line{ true, "", 2453452465346ul }, { false,
    "something went wrong", 0u }, })
            std::cout << "Result: " <<
    std::quoted(generate_ok_line(res)) << "\n";
    }

Prints

Result: "OK 2453452465346

"

Result: "ERR something went wrong

"

_______________________________________________
Spirit-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/spirit-general