kastnermario / yaml-cpp

Automatically exported from code.google.com/p/yaml-cpp
MIT License
0 stars 0 forks source link

Strings are all output as quoted. #55

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Build debug static lib using VS 9 2008
2. Link it with a project.
3. Emit some YAML

What is the expected output? What do you see instead?
Expected:
key: value

What I see instead is:
"key": value

What version of the product are you using? On what operating system?
yaml-cpp 0.24
XP, Visual Studio 9, 2008 Express.

Please provide any additional information below.
It looks like the IsValidPlainScalar isn't working correctly and is
reporting a regexp match failure, therefore the quotes.  I verified this by
resetting EAX in the debugger to fool IsValidPlainScalar to return true,
and everything worked great.

Original issue reported on code.google.com by tim.fi...@gmail.com on 4 Nov 2009 at 8:57

GoogleCodeExporter commented 8 years ago
Ah, I found it.  I was testing YAML serialization as part of a static 
initializer. 
the RegEx for PlainScalar wasn't initialized yet.  Inexplicably, the compiler 
gave my
code an empty regex, that of course failed against a string with something in 
it.

Perhaps these constant regexes could be statically initialized lazily on demand?

Regards,
Tim

Original comment by tim.fi...@gmail.com on 4 Nov 2009 at 10:21

GoogleCodeExporter commented 8 years ago
Good idea, I think. I switched them all to little functions that just return a 
static
argument (I assume that's what you mean), but I'm still a little worried about 
other
stuff, since there are a few other things that are statically initialized.

Anyways, can you try it out (r319) and let me know whether it does what you 
want?

Thanks!

Original comment by jbe...@gmail.com on 4 Nov 2009 at 10:58

GoogleCodeExporter commented 8 years ago
Actually, I did two things to get my tests to work with MSVC.  

I added to yaml-cpp code for msvc to move the priority to "library" for the 
exp.h code:

{{{
#if defined(_MSC_VER)

#   pragma warning( push )

#   pragma warning( disable: 4073 )

#   pragma init_seg( lib )

#   pragma warning( pop )

#endif
}}}

In my code, I did the same, only I picked "user" priority.  

For GCC, I only had to add an attribute to struct that ran my test:

{{{
#if defined(__GNUG__)

#   define STATIC_INIT_LATE __attribute__ ((init_priority (65535)))

#else

#   define STATIC_INIT_LATE

#endif

    struct YamlTest {

        YamlTest() {

            struct_t s0;

            ZeroPOD( s0 );

            YAML::Emitter out;

            out << s0;

            stringstream ss;

            ss << out.c_str();

            struct_t s1;

            memset( &s1, 0xff, sizeof(s1));

            YAML::Parser parser(ss);

            YAML::Node doc;

            if (parser.GetNextDocument(doc))

                doc >> qdt1;

            assert( 0 == memcmp(&s0, &s1, sizeof(s0)) );

        }

    } runYamlTest STATIC_INIT_LATE;
}}}

Original comment by tim.fi...@gmail.com on 4 Nov 2009 at 11:08

GoogleCodeExporter commented 8 years ago
So do you not need the patch (lazily evaluating the global RegExes)?

Original comment by jbe...@gmail.com on 6 Nov 2009 at 3:32

GoogleCodeExporter commented 8 years ago
Not atm.  But in the long run you might want to look for any other static 
initialized
data.

Original comment by tim.fi...@gmail.com on 6 Nov 2009 at 5:32

GoogleCodeExporter commented 8 years ago
Closing the issue, but I'll still consider other static data.

Original comment by jbe...@gmail.com on 12 Nov 2009 at 3:14