On Tue, Oct 16, 2012 at 2:54 PM, H. S. Teoh <span dir="ltr"><<a href="mailto:hsteoh@quickfur.ath.cx" target="_blank">hsteoh@quickfur.ath.cx</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On Tue, Oct 16, 2012 at 12:33:20PM -0700, H. S. Teoh wrote:<br>
[...]<br>
<div class="im">> Another data point: if I move the .joiner call out of cprod() into<br>
> main(), then there is no problem. Could it be that something in joiner<br>
> is breaking somehow, when returned from a function?<br>
</div>[...]<br>
<br>
I found a reduced case:<br>
<div class="im"><br>
        import std.algorithm;<br>
        import std.range;<br>
        import std.stdio;<br>
<br>
</div>        auto boo() {<br>
                auto C = [2];<br>
                return<br>
                        [1,1]<br>
                        .map!((a) => C)<br>
                        .joiner<br>
                ;<br>
        }<br>
<br>
        void main() {<br>
                auto C = [2];<br>
                writeln(<br>
                        [1,1]<br>
                        .map!((a) => C)<br>
                        .joiner<br>
                .take(12));<br>
<br>
                writeln("====");<br>
<br>
                writeln(boo().take(12));<br>
        }<br>
<br>
Excuse the odd formatting, I wanted to make sure the [1,1,1].map!(...)<br>
parts are line-for-line identical between boo() and main().<br>
<br>
This example segfaults in the last writeln. Commenting out .joiner makes<br>
the segfault go away. Reducing [1,1] to a 1-element array makes the<br>
problem go away. Replacing C with [1] makes the problem go away.<br>
Removing map!(...) and replacing it with something involving C makes the<br>
problem go away. Deleting the .take(12) outputs a whole mass of garbage<br>
values and then segfaults.<br>
<br>
So it seems like there is some kind of bad interaction between map and<br>
joiner. Maybe as jethro said, it's wrong code produced by dmd for the<br>
delegate passed to map? It seems to be dependent on the reference to the<br>
local variable C, which seems to imply a corrupted (or just<br>
out-of-scope?) delegate context.<br>
<span class="HOEnZb"><font color="#888888"><br>
<br>
T<br>
<br>
--<br>
The best way to destroy a cause is to defend it poorly.</font></span></blockquote><div><br></div><div>I'm starting to think maybe I shouldn't have closed my issue I reported awhile back:</div><div><br></div><div>
<a href="http://d.puremagic.com/issues/show_bug.cgi?id=7978">http://d.puremagic.com/issues/show_bug.cgi?id=7978</a></div><div><br></div><div>I really need to read how closures are supposed to work. </div><div><br></div><div>
BA</div></div>