Skip to content

Conversation

@aruscher
Copy link

@aruscher aruscher commented Sep 3, 2025

Fixes #5649

  • Checked all function signature and type declarations
  • Corrected the function signature of inflateInit_ + inflateInit helper function
  • Updated zlib to the most recent version 1.3.1
  • Rebuild libz.lib static library

@aruscher
Copy link
Author

aruscher commented Sep 3, 2025

Maintainers: The library was cross compiled from Linux. I would recommend building it again from windows as the file size dropped by 22% which seems odd.

Here is a short script for testing the library:

package main

import "vendor:zlib"
import "core:fmt"

//see https://gist.github.com/arq5x/5315739
main :: proc(){

    // original string len = 36
    text := cstring("Hello Hello Hello Hello Hello Hello!")

    // placeholder for the compressed (deflated) version of "text" 
    deflated: [50]zlib.Byte

    // // placeholder for the UNcompressed (inflated) version of "defalted"
    inflated: [50]zlib.Byte

    fmt.printfln("Uncompressed size is: %d", len(text));
    fmt.printfln("Uncompressed size is: %s", text);

    fmt.printfln("----------");
    
    defstream:zlib.z_stream
    defstream.zfree = nil
    defstream.zalloc = nil
    defstream.opaque = nil
    defstream.avail_in = cast(zlib.uInt) len(text)+1 // Text + Terminator
    defstream.next_in = cast(^zlib.Bytef) text
    defstream.avail_out = cast(zlib.uInt) size_of(deflated) // size of output
    defstream.next_out = cast(^zlib.Bytef) &deflated

    // the actual compression work.
    zlib.deflateInit(&defstream, zlib.BEST_COMPRESSION);
    zlib.deflate(&defstream, zlib.FINISH);
    zlib.deflateEnd(&defstream);

    deflated_string := cstring(raw_data(deflated[:defstream.total_out]))
    fmt.printfln("Deflated size is: %d", len(deflated_string));
    fmt.printfln("Deflated text is: %s", deflated_string);

    fmt.printfln("----------");

    infstream:zlib.z_stream
    infstream.zfree = nil
    infstream.zalloc = nil
    infstream.opaque = nil
    infstream.avail_in = cast(zlib.uInt) defstream.total_out
    infstream.next_in = cast(^zlib.Bytef) &deflated
    infstream.avail_out = cast(zlib.uInt) size_of(inflated) 
    infstream.next_out = cast(^zlib.Bytef) &inflated

    zlib.inflateInit(&infstream);
    zlib.inflate(&infstream, zlib.NO_FLUSH);
    zlib.inflateEnd(&infstream);

    inflated_string := cstring(raw_data(inflated[:infstream.total_out]))
    fmt.printfln("Inflated size is: %d", len(inflated_string));
    fmt.printfln("Inflated text is: %s", inflated_string);

    assert(inflated_string == text)
}

Expected Output:

Uncompressed size is: 36
Uncompressed size is: Hello Hello Hello Hello Hello Hello!
----------
Deflated size is: 13
Deflated text is: x��H���W��G*2
----------
Inflated size is: 36
Inflated text is: Hello Hello Hello Hello Hello Hello!

Comment on lines 138 to 142
Version :: proc() -> cstring ---
@(link_prefix = "zlib")
Version :: proc() -> cstring ---

deflate :: proc(strm: z_streamp, flush: c.int) -> c.int ---
deflateEnd :: proc(strm: z_streamp) -> c.int ---
inflate :: proc(strm: z_streamp, flush: c.int) -> c.int ---
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why have you changed all of the formatting?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why have you changed all of the formatting?

Yeah..Sorry my mistake...happened due to odinfmt or emacs format buffer -.-
I will upload version soon.

Btw. are there any formatting guidelines?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

vendor:zlib SIGSEGV, Segmentation fault - String passing issue?

2 participants