[Issue 18773] Constraints on buffer re-use for std.zlib should be documented.

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Sep 15 11:49:46 UTC 2020


SHOO <zan77137 at nifty.com> changed:

           What    |Removed                     |Added
                 CC|                            |zan77137 at nifty.com

--- Comment #1 from SHOO <zan77137 at nifty.com> ---
This issue seems to be implementation problems rather than undocumented
restrictions: since the argument of compress/uncompress is requiring
const(void)[], the function has to take into account the possibility that the
buffer may be changed.

Specifically, the following code does not work:
auto compressed = appender!(ubyte[])();
scope compress = new Compress(HeaderFormat.gzip);
char[128] buffer;
foreach (e; ["abc", "abcdefghijk"]) {
    auto line = sformat!"%s\n"(buffer, e);
    // Invalid buffer is held by Compress
    const compressedLine = compress.compress(line);
    compressed.put(cast(const(ubyte)[]) compressedLine);
compressed.put(cast(const(ubyte)[]) compress.flush());

To solve this, there are two policies:
1. Change the type of argument to immutable(void)[] (this is a breaking change)
2. Copy the argument's buffer, and manage the life of the copied buffer in


More information about the Digitalmars-d-bugs mailing list