Thread overview
[Issue 18773] Constraints on buffer re-use for std.zlib should be documented.
Apr 19, 2018
Eduard Staniloiu
Sep 15, 2020
SHOO
Dec 17, 2022
Iain Buclaw
April 19, 2018
https://issues.dlang.org/show_bug.cgi?id=18773

Eduard Staniloiu <edi33416@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |bootcamp
                 CC|                            |edi33416@gmail.com

--
September 15, 2020
https://issues.dlang.org/show_bug.cgi?id=18773

SHOO <zan77137@nifty.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |zan77137@nifty.com

--- Comment #1 from SHOO <zan77137@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
Compress/UnCompress.

--
December 17, 2022
https://issues.dlang.org/show_bug.cgi?id=18773

Iain Buclaw <ibuclaw@gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P1                          |P4

--