Closed GoogleCodeExporter closed 9 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
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
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
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
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
Closing the issue, but I'll still consider other static data.
Original comment by jbe...@gmail.com
on 12 Nov 2009 at 3:14
Original issue reported on code.google.com by
tim.fi...@gmail.com
on 4 Nov 2009 at 8:57