-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ZlibStreamError due to size mismatch of data types (Linux) #39
Comments
Is it then a matter of making this change or is something else needed? when defined(windows):
type
Ulong* = uint32
Ulongf* = uint32
ZOffT* = int32
else:
type
Ulong* = int
Ulongf* = int
ZOffT* = int EDIT: Added the ZOffT*, too. I don't have any Windows instalation to verify if the 64-bit zlib there matches the type definition. |
I don't know. |
I have the same problem, but this solution works on Linux x64. |
Had this issue as well, the fix from @Nindaleth works for me as well. Could this be applied to master, or is there something holding this back? |
This bug won't be fixed. See: #42 (review) |
It will be fixed but properly. |
See dup #53. (And the dup I would have filed today if I hadn't searched first...) Zlib is pretty much dead in the water on macOS (and iOS, and probably Linux(?)) due to this. The fix is simply to change the int types to the standard C-based ones, e.g.: Uint* = cuint
Ulong* = culong
Ulongf* = culong
Pulongf* = ptr Ulongf
|
Integer types in zlib.h were not properly translated into Nim. Most seriously, `Ulong` and `Ulongf` (which are both `unsigned long`) were translated to `int32`, which is wrong on LP64 systems like macOS, iOS and I think 64-bit Linux too. This causes the Nim `ZStream` struct to be much shorter than the real `z_stream` (88 vs 120 bytes), and that causes the size comparison in the inflate/deflateInit functions to fail with Z_VERSION_ERROR, which is actually a good thing because if it kept going it would be smashing memory, since Nim didn't allocate enough space for its struct. I've fixed the types to the best of my knowledge, using the standard C-based types like `cint` and `culong`. The only iffy one is `ZOffT` which has a complicated conditional definition in C -- I think it's supposed to match `off_t`, whose size depends not on the ABI but on whether the filesystem supports 64-bit files... I made it a `clong` since most systems handle 64-bit files nowadays. Fixes nim-lang#23, nim-lang#39, nim-lang#53
I had a solution that addressed exactly that. Just take a look at my last comment. |
I was trying out the zlib wrapper on my Linux machine (amd64, zlib
1.2.11
) with the following program:Compilation goes well but the program yields the following run-time error:
I went digging through the source code and I think I've figured out what's going on.
The version mismatch exception is (in this case) caused by zlib's
deflateInit2()
returningZ_VERSION_ERROR
. According to the docs, that can happen for two reasons:z_stream
size differs from that used by the library.The wrapper defines the
ZStream
object to representz_stream
and passessizeof(ZStream)
as the size that gets validated by the library. That causes a mismatch on my system since the library expects a 112-byte struct but instead gets one that's 88 bytes.There is a zlib function called
zlibCompileFlags()
that defines the sizes of the types used by the library. Compile the following withgcc
:For me that yields the output:
Merge request #35 changed the data type for
Ulong
toint32
instead of Nim'sint
type. This should be the source of the issue on my machine and other's too, I'm sure.I'm guessing a solution has to work around the fact that #35 was needed on Windows, without breaking the wrapper for other platforms. Just changing the types back to
int
orint64
works for me. Additionally, looking at the output fromzlibCompileFlags()
, there seems to be a mismatch for theZoffT
type too.The text was updated successfully, but these errors were encountered: