Re: x3 static initialisation problems

Dirk Bonekämper <[email protected]>
Newsgroups gmane.comp.parsers.spirit.general
Message-ID <[email protected]>
 I guess I need to clarify my previous mail.

Let's look at the expression parser from the 1.65.1 calc9 example.

expression.hpp declares 'parser::expression_type const& expression()'.
This function allows other rules to access the expression rule. It may
be called before the static initializers of expression.o have been
called.

The definion of expression() is in expression_def.hpp. When it's called
before static initialization, two things happen:
- add_keywords() tries to modify uninitialized static x3::symbols<>
  objects.
- a reference to an unintialized object is returned.

So I think that this initialization pattern is broken.

In my code I use several separately compiled rules calling each other.
So the Executable is quite prone to SIOF. And yes, the assertion added
to x3::traits::get_info<>() fired immediately, showing that some rules
were uninitialized and this problem is real.

As a conlusion, I think that the examples need to be fixed.

The solution I came up with:
Let's assume a rule named coordinates. The parser::coordinates()
acessor function returns a reference to a function static
coordinates_type object. This rnsures that all calls return a valid
object.

The static x3::symbols<> parsers used by the coordinates rule are
initialized with symbols_gen functions. (Just as the pattern was in
1.60) symbols<> parsers will be properly initialzed before being
called from within main().

This solution works for me. It has one little wart, though. One still
needs to keep a namespace object called coordinates. The
BOOST_SPIRIT_DEFINE_ macro uses it to figure out the type of the rule
object. 



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.