http://d.puremagic.com/issues/show_bug.cgi?id=3191


Andrej Mitrovic <andrej.mitrov...@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrej.mitrov...@gmail.com


--- Comment #2 from Andrej Mitrovic <andrej.mitrov...@gmail.com> 2011-05-24 
22:05:17 PDT ---
Greetings, I come from the future.

Here's a modern implementation of your sample:

import std.zlib;
import std.stdio;

const size_t BLOCK_SIZE = 1024;

void main(string[] a) 
{
    auto file = File(a[1], "r");
    auto uc = new UnCompress();

    void[] ucData;
    ubyte[] block = new ubyte[BLOCK_SIZE];

    foreach (ubyte[] buffer; file.byChunk(BLOCK_SIZE))
    {
        writeln(buffer.length);
        ucData ~= uc.uncompress(buffer);
    }

    ucData ~= uc.flush();
    writefln("Finished: %s", ucData.length);
}

Still errors out. But I have a hunch it has something to do with buffer being
reused by file.byChunk, and zlib might internally be storing a pointer to the
buffer while the GC might deallocate it in the meantime.

Something like that, because if you .dup your buffer, you won't get errors
anymore:

import std.zlib;
import std.stdio;

const size_t BLOCK_SIZE = 1024;

void main(string[] a) 
{
    auto file = File(a[1], "r");
    auto uc = new UnCompress();

    void[] ucData;
    ubyte[] block = new ubyte[BLOCK_SIZE];

    foreach (ubyte[] buffer; file.byChunk(BLOCK_SIZE))
    {
        writeln(buffer.length);
        ucData ~= uc.uncompress(buffer.dup);
    }

    ucData ~= uc.flush();  
    writefln("Finished: %s", ucData.length);
}

It might just be that zlib expects all data passed in to be valid while you use
the UnCompress() class. I have no other explanation.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------

Reply via email to