append to immutable array segfaults - anyone else seen it?

Steven Schveighoffer schveiguy at yahoo.com
Tue May 24 15:14:28 PDT 2011


On Tue, 24 May 2011 18:02:19 -0400, Adam D. Ruppe  
<destructionator at gmail.com> wrote:

> One of my apps, seemingly at random, started crashing today. The
> part at fault looked mostly like this:
>
> ===
>    immutable(string[])[] records;
>
>    foreach(immutableData; inputSource)
>        records ~= [immutableData[1], immutableData[0]];
> ===
>
> Nothing really fancy there except most everything was immutable. It
> worked fine for a while. All my attempts to reduce it to a small
> test case fail; the code works there too.
>
> But, for some reason, the live code failed.
>
>
> Looking into a debugger told me the segfault happened on lifetime.d
> line 1967 in druntime:
>
> /**
>  * The old way, obsolete.
>  */
> extern (C) void* _d_arrayliteralT(TypeInfo ti, size_t length, ...)
> {
>     auto sizeelem = ti.next.tsize();            // array element size
>     void* result;
>
>
> It crashes on the array element size line. Neither ti nor ti.next
> were null - both appeared to be valid references.

Are you doing anything with dynamic libraries?  I think that dynamic  
libraries can have their own copies of the typeinfo, which might be  
invalid if you unload the library.

I can't think of any other reason why a typeinfo would "go away".  There's  
always the possibility of memory corruption.

-Steve


More information about the Digitalmars-d mailing list