Re: [Boost-users] [proto, fusion] Segfault in for_each

On 5/19/2010 10:01 AM, David Greene wrote:
On Thursday 13 May 2010 23:16:31 David A. Greene wrote:
On Monday 10 May 2010 21:15:42 Eric Niebler wrote:
I've been wrestling with this for days. Any ideas on how to debug this?
Nope. But it'd probably help if you sent around a self-contained repro.
Ok, here's a smallish testcase. gdb shows the same problem: an invalid proto expression reference.
Hey Eric,
No rush to take a look at this, but I wanted to make sure you got the testcase since I haven't seen a reply.
Sorry for not responding sooner. I got it. This came in during the melee of BoostCon. And now I'm down with a cold. I hope to look at it soon. -- Eric Niebler BoostPro Computing http://www.boostpro.com

On 5/19/2010 10:27 AM, Eric Niebler wrote:
On 5/19/2010 10:01 AM, David Greene wrote:
On Thursday 13 May 2010 23:16:31 David A. Greene wrote:
On Monday 10 May 2010 21:15:42 Eric Niebler wrote:
I've been wrestling with this for days. Any ideas on how to debug this?
Nope. But it'd probably help if you sent around a self-contained repro.
Ok, here's a smallish testcase. gdb shows the same problem: an invalid proto expression reference.
Hey Eric,
No rush to take a look at this, but I wanted to make sure you got the testcase since I haven't seen a reply.
Sorry for not responding sooner. I got it. This came in during the melee of BoostCon. And now I'm down with a cold. I hope to look at it soon.
OK, I had a quick look. Basically, you're playing fast and loose with Fusion views and temporaries. When you call fusion::transform, it doesn't eagerly generate a new fusion sequence. It returns a /view/ that holds a reference to the input sequence and the map function. In transformList and all the functions it calls, you're passing arguments by value, and then returning a fusion::transform_view object that is holding a reference to the (now deceased) argument. I've changed the code to pass-by-reference to side-step the lifetime issues, and it seems to work now. I make no promises that there aren't other lifetime issues in this code. You need to think carefully about temporaries and lifetime management when using proto and fusion. I also fixed your grammar for you. Be sure to draw a distinction between grammar rules and expressions. terminal<int> is a grammar rule. terminal<int>::type is an expression. An expression can be used as a grammar (it matches itself), but a grammar is not an expression. HTH, -- Eric Niebler BoostPro Computing http://www.boostpro.com
participants (1)
-
Eric Niebler