This is the mail archive of the
ecos-patches@sourceware.org
mailing list for the eCos project.
zlib package usability issues
- From: Nathan Heijermans <nheijermans at gmail dot com>
- To: ecos-patches at ecos dot sourceware dot org
- Date: Tue, 27 Jan 2009 17:36:37 -0500
- Subject: zlib package usability issues
Hi all,
I recently needed to use the zlib package, but ran into some issues with
it in its current state. I have attached a patch that resolved the
issues for me, but there may be some issues that need to be resolved
that I am not aware of. I do not have an in-depth understanding of the
inner workings of zlib, but have read through the relevant portions of
zlib.h to understand the various compile-time configuration macros they
allow. My goal was to be able to use the routines in gzio.c to read and
write compressed files.
The first problem arose from the fact that MAX_WBITS is defined as
`15+16` (instead of `(15+16)`). The gzopen() call in gzio.c called
deflateInit2() with windowBits=-15+16, which is not a valid value.
Fixing the definition of MAX_WBITS resulted in deflateInit2() being
called with a value of -31. This is also invalid. Disabling the CDL
option controlling the MAX_WBITS value also didn't work, because it
completely disable deflate() functionality. Eliminating the definition
of MAX_WBITS altogether, and using the default value of 15, resolved
this problem.
I then began trying to add support for the various configuration macros
provided by zlib, and realized that defining MAX_WBITS to be in the
-8..-15 (enabling raw deflate()/inflate()) or (8..15)+16 (enabling gzip
deflate()) ranges is also problematic when using the gz* routines in
gzio.c. gzopen() passes -MAX_WBITS to deflateInit2(), while deflate()
passes MAX_WBITS. This is why I totally eliminated the option for
"inflate() to compress gzip compatible output". If somebody really needs
this, a change will probably need to be made to the upstream zlib code
to separately define the MAX_WBITS used in gzio.c from the one used in
deflate.c, or else pass MAX_WBITS in both cases.
That's all; I hope that this made sense and will help somebody...
Sincerely,
Nathan Heijermans
diff --git a/packages/services/compress/zlib/current/cdl/compress_zlib.cdl b/packages/services/compress/zlib/current/cdl/compress_zlib.cdl
index cb0a749..50252e9 100644
--- a/packages/services/compress/zlib/current/cdl/compress_zlib.cdl
+++ b/packages/services/compress/zlib/current/cdl/compress_zlib.cdl
@@ -65,13 +65,35 @@ cdl_package CYGPKG_COMPRESS_ZLIB {
display "Override memory allocation routines."
}
- cdl_option CYGSEM_COMPRESS_ZLIB_DEFLATE_MAKES_GZIP {
- display "Should deflate() produce 'gzip' compatible output?"
- flavor bool
- default_value 1
+ cdl_option CYGSEM_COMPRESS_ZLIB_ENABLE_COMPRESSION {
+ display "Enable Compression"
+ flavor bool
+ default_value 1
description "
- If this option is set then the output of calling deflate()
- will be wrapped up as a 'gzip' compatible file."
+ If this option is disabled, zlib will be compiled without the
+ ability to compress. This is useful when decompression is needed,
+ but compression is not."
+
+ cdl_option CYGOPT_COMPRESS_ZLIB_MAX_WBITS {
+ display "#define MAX_WBITS"
+ define MAX_WBITS
+ flavor data
+ default_value 15
+ legal_values 8 to 15
+ description "
+ MAX_WBITS controls the maximum window size (i.e. the size of
+ the history buffer, which is 2^MAX_WBITS) used by the deflate()
+ call."
+ }
+ }
+
+ cdl_option CYGSEM_COMPRESS_ZLIB_ENABLE_GZIP {
+ display "Enable gzip encoding and decoding"
+ flavor bool
+ default_value 1
+ description "
+ If this option is disabled, zlib will be compiled without the
+ ability to encode and decode gzip streams."
}
cdl_option CYGSEM_COMPRESS_ZLIB_NEEDS_MALLOC {
diff --git a/packages/services/compress/zlib/current/include/zconf.h b/packages/services/compress/zlib/current/include/zconf.h
index 09608dc..1284fe1 100644
--- a/packages/services/compress/zlib/current/include/zconf.h
+++ b/packages/services/compress/zlib/current/include/zconf.h
@@ -16,13 +16,15 @@
#if CYGINT_COMPRESS_ZLIB_LOCAL_ALLOC != 0
#define MY_ZCALLOC
#endif
-#ifdef CYGSEM_COMPRESS_ZLIB_DEFLATE_MAKES_GZIP
-#undef MAX_WBITS
-#define MAX_WBITS 15+16 /* 32K LZ77 window */
-#else
-#define NO_GZIP
-#define NO_GZCOMPRESS
+
+#ifndef CYGSEM_COMPRESS_ZLIB_ENABLE_COMPRESSION
+# define NO_GZCOMPRESS
#endif
+
+#ifndef CYGSEM_COMPRESS_ZLIB_ENABLE_GZIP
+# define NO_GZIP
+#endif
+
// #endif
/*