Opened 18 years ago

Closed 18 years ago

#331 closed Support Requests (None)

spirit: run-time error

Reported by: bnf Owned by: nobody
Milestone: Component: None
Version: None Severity:
Keywords: Cc:

Description

I am using the Spirit library v1.8.1, part of Boost 1.32.
Here is a test case which fails at run-time: I get a
VC++ Debug Library Error in file
core\non-terminal\impl\rule.ipp at line 173.
My compiler is VC++ 7.1 on Windows XP SP2.
In particular I get a Run-Time Check Failure #2: Stack
around the variable 'context-wrap' was corrupted.

Any idea about what can be the problem?
Please note that with the following I don't get any error:

    definition(const JSIGrammar& self)
    {
      Rule_T pp_token = real_p
      r = ch_p('#') >> str_p("line") >> +(pp_token);
    }




struct JSIGrammar : public grammar<JSIGrammar>
{
  template <typename ScannerT>
  struct definition
  {
    typedef rule<ScannerT> Rule_T;
    
    definition(const JSIGrammar& self)
    {
      Rule_T pp_number = real_p;
      Rule_T pp_token = pp_number;
      r = ch_p('#') >> str_p("line") >> +(pp_token);
    }

    const Rule_T& start() const 
    {
      return r;
    }

    Rule_T r;
  };
};



int
main(int argc, char* argv[])
{
  string str;
  {
    ifstream in(argv[1]);
    ostringstream out;
    out << in.rdbuf();
    str = out.str();
  }

  typedef parse_info<string::iterator> Info;

  JSIGrammar g;
  Info pi = parse(str.begin(), str.end(), g, space_p);
  
  if ( pi.hit )
  {
    cout << "Match" << endl;
    cout << "Full: " << (pi.full ? "Yes" : "No") << endl;
    cout << "Length: " << pi.length << endl;
  }
  else
  {
    cout << "No match" << endl;
  }
  
  return 0;
}

Change History (1)

comment:1 by biochimia, 18 years ago

Status: assignedclosed
Logged In: YES 
user_id=840777

rules must be "alive" while parsing. So, pp_token and
pp_number may not be temporary variables within
JSIGrammar::definition's constructor. Change them so they
become members of JSIGrammar::definition as 'r' is.

For rationale, consider what happens when you change the
order of the rules' definitions or when you have
self-referential rules as happens with the calculator
examples in the docs.

You may also want to direct spirit questions to spirit's
mailing list where you may get more responses.

br,


João Abecasis
Note: See TracTickets for help on using tickets.