Skip to content

Commit

Permalink
Merge branch 'bjorn/erts/zlib-1.2.8'
Browse files Browse the repository at this point in the history
* bjorn/erts/zlib-1.2.8:
  configure: Prefer the system's zlib over own our zlib source
  Update preloaded modules
  Add the 'rle' zstrategy
  Don't make gzio.c dependent on the zutil.h header file
  Update zlib to 1.2.8
  erts/zlib: Remove unused file example.c
  • Loading branch information
bjorng committed Jan 22, 2014
2 parents 990b655 + 9f57d8c commit e99633a
Show file tree
Hide file tree
Showing 32 changed files with 2,559 additions and 1,922 deletions.
5 changes: 3 additions & 2 deletions configure.in
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,9 @@ AC_ARG_ENABLE(dynamic-ssl-lib,
AS_HELP_STRING([--disable-dynamic-ssl-lib],
[disable using dynamic openssl libraries]))

AC_ARG_ENABLE(shared-zlib,
AS_HELP_STRING([--enable-shared-zlib], [enable using shared zlib library]))
AC_ARG_ENABLE(builtin-zlib,
AS_HELP_STRING([--enable-builtin-zlib],
[force use of our own built-in zlib]))

dnl This functionality has been lost along the way... :(
dnl It could perhaps be nice to reintroduce some day; therefore,
Expand Down
46 changes: 33 additions & 13 deletions erts/configure.in
Original file line number Diff line number Diff line change
Expand Up @@ -1372,24 +1372,44 @@ dnl -------------
dnl zlib
dnl -------------

AC_ARG_ENABLE(shared-zlib,
AS_HELP_STRING([--enable-shared-zlib], [enable using shared zlib library]),
[ case "$enableval" in
no) enable_shared_zlib=no ;;
*) enable_shared_zlib=yes ;;
esac ], enable_shared_zlib=no)
AC_ARG_ENABLE(builtin-zlib,
AS_HELP_STRING([--enable-builtin-zlib],
[force use of our own built-in zlib]),
[ case "$enableval" in
no) enable_builtin_zlib=no ;;
*) enable_builtin_zlib=yes ;;
esac ], enable_builtin_zlib=no)

Z_LIB=

if test "x$enable_shared_zlib" = "xyes" ; then
AC_CHECK_LIB(z, adler32_combine,
[Z_LIB="-lz"
AC_DEFINE(HAVE_LIBZ, 1, [Define to 1 if you have the `z' library (-lz).])],
[AC_MSG_ERROR([cannot find any shared zlib])])
if test "x$enable_builtin_zlib" = "xyes"; then
AC_MSG_NOTICE([Using our own built-in zlib source])
else
AC_MSG_NOTICE([Using own zlib source])
AC_MSG_CHECKING(for zlib 1.2.5 or higher)
zlib_save_LIBS=$LIBS
LIBS="-lz $LIBS"
AC_LINK_IFELSE(
[AC_LANG_PROGRAM([[
#include "zlib.h"
]],[[
#if ZLIB_VERNUM >= 0x1250
Bytef s[1];
s[0] = 0;
(void) adler32((uLong)0, s, 1);
#else
#error "No zlib 1.2.5 or higher found"
error
#endif
]])],
[
Z_LIB="-lz"
AC_DEFINE(HAVE_LIBZ, 1, [Define to 1 if you have the `z' library (-lz).])
AC_MSG_RESULT(yes)
],[
AC_MSG_RESULT(no)
])
LIBS=$zlib_save_LIBS
fi

AC_SUBST(Z_LIB)

dnl
Expand Down
30 changes: 16 additions & 14 deletions erts/doc/src/zlib.xml
Original file line number Diff line number Diff line change
Expand Up @@ -161,20 +161,22 @@ list_to_binary([Compressed|Last])</pre>
state. <c><anno>MemLevel</anno></c>=1 uses minimum memory but is slow and
reduces compression ratio; <c><anno>MemLevel</anno></c>=9 uses maximum
memory for optimal speed. The default value is 8.</p>
<p>The <c><anno>Strategy</anno></c> parameter is used to tune the
compression algorithm. Use the value <c>default</c> for
normal data, <c>filtered</c> for data produced by a filter
(or predictor), or <c>huffman_only</c> to force Huffman
encoding only (no string match). Filtered data consists
mostly of small values with a somewhat random
distribution. In this case, the compression algorithm is
tuned to compress them better. The effect of
<c>filtered</c>is to force more Huffman coding and less
string matching; it is somewhat intermediate between
<c>default</c> and <c>huffman_only</c>. The <c><anno>Strategy</anno></c>
parameter only affects the compression ratio but not the
correctness of the compressed output even if it is not set
appropriately.</p>
<p>The <c><anno>Strategy</anno></c> parameter is used to tune
the compression algorithm. Use the value <c>default</c> for
normal data, <c>filtered</c> for data produced by a filter (or
predictor), <c>huffman_only</c> to force Huffman encoding
only (no string match), or <c>rle</c> to limit match
distances to one (run-length encoding). Filtered data
consists mostly of small values with a somewhat random
distribution. In this case, the compression algorithm is tuned
to compress them better. The effect of <c>filtered</c>is to
force more Huffman coding and less string matching; it is
somewhat intermediate between <c>default</c> and
<c>huffman_only</c>. <c>rle</c> is designed to be almost as
fast as <c>huffman_only</c>, but give better compression for PNG
image data. The <c><anno>Strategy</anno></c> parameter only
affects the compression ratio but not the correctness of the
compressed output even if it is not set appropriately.</p>
</desc>
</func>
<func>
Expand Down
15 changes: 7 additions & 8 deletions erts/emulator/drivers/common/efile_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@
#include "erl_driver.h"
#include "erl_efile.h"
#include "erl_threads.h"
#include "zlib.h"
#include "gzio.h"
#include "dtrace-wrapper.h"
#include <ctype.h>
Expand Down Expand Up @@ -818,7 +817,7 @@ file_start(ErlDrvPort port, char* command)

static void do_close(int flags, SWord fd) {
if (flags & EFILE_COMPRESSED) {
erts_gzclose((gzFile)(fd));
erts_gzclose((ErtsGzFile)(fd));
} else {
efile_closefile((int) fd);
}
Expand Down Expand Up @@ -1136,7 +1135,7 @@ static void invoke_read(void *data)
}
read_size = size;
if (d->flags & EFILE_COMPRESSED) {
read_size = erts_gzread((gzFile)d->fd,
read_size = erts_gzread((ErtsGzFile)d->fd,
d->c.read.binp->orig_bytes + d->c.read.bin_offset,
size);
status = (read_size != (size_t) -1);
Expand Down Expand Up @@ -1209,7 +1208,7 @@ static void invoke_read_line(void *data)
size = need - d->c.read_line.read_size;
}
if (d->flags & EFILE_COMPRESSED) {
read_size = erts_gzread((gzFile)d->fd,
read_size = erts_gzread((ErtsGzFile)d->fd,
d->c.read_line.binp->orig_bytes +
d->c.read_line.read_offset + d->c.read_line.read_size,
size);
Expand Down Expand Up @@ -1250,7 +1249,7 @@ static void invoke_read_line(void *data)
d->c.read_line.read_size -= too_much;
ASSERT(d->c.read_line.read_size >= 0);
if (d->flags & EFILE_COMPRESSED) {
Sint64 location = erts_gzseek((gzFile)d->fd,
Sint64 location = erts_gzseek((ErtsGzFile)d->fd,
-((Sint64) too_much), EFILE_SEEK_CUR);
if (location == -1) {
d->result_ok = 0;
Expand Down Expand Up @@ -1535,7 +1534,7 @@ static void invoke_writev(void *data) {
*/
errno = EINVAL;
if (! (status =
erts_gzwrite((gzFile)d->fd,
erts_gzwrite((ErtsGzFile)d->fd,
iov[i].iov_base,
iov[i].iov_len)) == iov[i].iov_len) {
d->errInfo.posix_errno =
Expand Down Expand Up @@ -1797,7 +1796,7 @@ static void invoke_lseek(void *data)
d->errInfo.posix_errno = EINVAL;
status = 0;
} else {
d->c.lseek.location = erts_gzseek((gzFile)d->fd,
d->c.lseek.location = erts_gzseek((ErtsGzFile)d->fd,
offset, d->c.lseek.origin);
if (d->c.lseek.location == -1) {
d->errInfo.posix_errno = errno;
Expand Down Expand Up @@ -1885,7 +1884,7 @@ static void invoke_open(void *data)
if (status || (d->errInfo.posix_errno != EISDIR)) {
mode = (d->flags & EFILE_MODE_READ) ? "rb" : "wb";
d->fd = (SWord) erts_gzopen(d->b, mode);
if ((gzFile)d->fd) {
if ((ErtsGzFile)d->fd) {
status = 1;
} else {
if (errno == 0) {
Expand Down
53 changes: 26 additions & 27 deletions erts/emulator/drivers/common/gzio.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ typedef struct gz_stream {
* this structure. */
} gz_stream;

local gzFile gz_open OF((const char *path, const char *mode));
local ErtsGzFile gz_open OF((const char *path, const char *mode));
local int get_byte OF((gz_stream *s));
local void check_header OF((gz_stream *s));
local int destroy OF((gz_stream *s));
Expand Down Expand Up @@ -144,7 +144,7 @@ local uLong getLong OF((gz_stream *s));
can be checked to distinguish the two cases (if errno is zero, the
zlib error is Z_MEM_ERROR).
*/
local gzFile gz_open (path, mode)
local ErtsGzFile gz_open (path, mode)
const char *path;
const char *mode;
{
Expand Down Expand Up @@ -179,7 +179,7 @@ local gzFile gz_open (path, mode)

s->path = (char*)ALLOC(FILENAME_BYTELEN(path)+FILENAME_CHARSIZE);
if (s->path == NULL) {
return s->destroy(s), (gzFile)Z_NULL;
return s->destroy(s), (ErtsGzFile)Z_NULL;
}
FILENAME_COPY(s->path, path); /* do this early for debugging */

Expand All @@ -197,7 +197,7 @@ local gzFile gz_open (path, mode)
} while (*p++ && m < fmode + sizeof(fmode) - 1);
*m = '\0';
if (s->mode == '\0')
return s->destroy(s), (gzFile)Z_NULL;
return s->destroy(s), (ErtsGzFile)Z_NULL;

if (s->mode == 'w') {
err = deflateInit2(&(s->stream), level,
Expand All @@ -207,7 +207,7 @@ local gzFile gz_open (path, mode)
s->stream.next_out = s->outbuf = (Byte*)ALLOC(Z_BUFSIZE);

if (err != Z_OK || s->outbuf == Z_NULL) {
return s->destroy(s), (gzFile)Z_NULL;
return s->destroy(s), (ErtsGzFile)Z_NULL;
}
} else {
/*
Expand All @@ -221,25 +221,24 @@ local gzFile gz_open (path, mode)
s->stream.next_in = s->inbuf = (Byte*)ALLOC(Z_BUFSIZE);

if (err != Z_OK || s->inbuf == Z_NULL) {
return s->destroy(s), (gzFile)Z_NULL;
return s->destroy(s), (ErtsGzFile)Z_NULL;
}
}
s->stream.avail_out = Z_BUFSIZE;

errno = 0;
#if defined(FILENAMES_16BIT)
{
char wfmode[160];
int i=0,j;
for(j=0;fmode[j] != '\0';++j) {
wfmode[i++]=fmode[j];
wfmode[i++]='\0';
WCHAR wfmode[80];
int i = 0;
int j;
for(j = 0; fmode[j] != '\0'; ++j) {
wfmode[i++] = (WCHAR) fmode[j];
}
wfmode[i++] = '\0';
wfmode[i++] = '\0';
s->file = F_OPEN(path, wfmode);
wfmode[i++] = L'\0';
s->file = _wfopen((WCHAR *)path, wfmode);
if (s->file == NULL) {
return s->destroy(s), (gzFile)Z_NULL;
return s->destroy(s), (ErtsGzFile)Z_NULL;
}
}
#elif defined(UNIX)
Expand All @@ -249,18 +248,18 @@ local gzFile gz_open (path, mode)
s->file = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0666);
}
if (s->file == -1) {
return s->destroy(s), (gzFile)Z_NULL;
return s->destroy(s), (ErtsGzFile)Z_NULL;
}
#else
s->file = F_OPEN(path, fmode);
s->file = fopen(path, fmode);
if (s->file == NULL) {
return s->destroy(s), (gzFile)Z_NULL;
return s->destroy(s), (ErtsGzFile)Z_NULL;
}
#endif
if (s->mode == 'r') {
check_header(s); /* skip the .gz header */
}
return (gzFile)s;
return (ErtsGzFile)s;
}

/* ===========================================================================
Expand Down Expand Up @@ -296,7 +295,7 @@ local int gz_rewind (gz_stream *s)
/* ===========================================================================
Opens a gzip (.gz) file for reading or writing.
*/
gzFile erts_gzopen (path, mode)
ErtsGzFile erts_gzopen (path, mode)
const char *path;
const char *mode;
{
Expand Down Expand Up @@ -447,7 +446,7 @@ local int destroy (s)
gzread returns the number of bytes actually read (0 for end of file).
*/
int
erts_gzread(gzFile file, voidp buf, unsigned len)
erts_gzread(ErtsGzFile file, voidp buf, unsigned len)
{
gz_stream *s = (gz_stream*)file;
Bytef *start = buf; /* starting point for crc computation */
Expand Down Expand Up @@ -557,7 +556,7 @@ erts_gzread(gzFile file, voidp buf, unsigned len)
gzwrite returns the number of bytes actually written (0 in case of error).
*/
int
erts_gzwrite(gzFile file, voidp buf, unsigned len)
erts_gzwrite(ErtsGzFile file, voidp buf, unsigned len)
{
gz_stream *s = (gz_stream*)file;

Expand Down Expand Up @@ -593,7 +592,7 @@ erts_gzwrite(gzFile file, voidp buf, unsigned len)
*/

int
erts_gzseek(gzFile file, int offset, int whence)
erts_gzseek(ErtsGzFile file, int offset, int whence)
{
int pos;
gz_stream* s = (gz_stream *) file;
Expand Down Expand Up @@ -655,7 +654,7 @@ erts_gzseek(gzFile file, int offset, int whence)
degrade compression.
*/
int
erts_gzflush(gzFile file, int flush)
erts_gzflush(ErtsGzFile file, int flush)
{
uInt len;
int done = 0;
Expand Down Expand Up @@ -714,7 +713,7 @@ local uLong getLong (s)
and deallocates all the (de)compression state.
*/
int
erts_gzclose(gzFile file)
erts_gzclose(ErtsGzFile file)
{
int err;
gz_stream *s = (gz_stream*)file;
Expand All @@ -723,9 +722,9 @@ erts_gzclose(gzFile file)

if (s->mode == 'w') {
err = erts_gzflush (file, Z_FINISH);
if (err != Z_OK) return s->destroy(file);
if (err != Z_OK) return s->destroy(s);
}
return s->destroy(file);
return s->destroy(s);
}


Expand Down
16 changes: 10 additions & 6 deletions erts/emulator/drivers/common/gzio.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,15 @@
* %CopyrightEnd%
*/

gzFile erts_gzopen (const char *path, const char *mode);
int erts_gzread(gzFile file, voidp buf, unsigned len);
int erts_gzwrite(gzFile file, voidp buf, unsigned len);
int erts_gzseek(gzFile, int, int);
int erts_gzflush(gzFile file, int flush);
int erts_gzclose(gzFile file);
#include "zlib.h"

typedef struct erts_gzFile* ErtsGzFile;

ErtsGzFile erts_gzopen (const char *path, const char *mode);
int erts_gzread(ErtsGzFile file, voidp buf, unsigned len);
int erts_gzwrite(ErtsGzFile file, voidp buf, unsigned len);
int erts_gzseek(ErtsGzFile, int, int);
int erts_gzflush(ErtsGzFile file, int flush);
int erts_gzclose(ErtsGzFile file);
ErlDrvBinary* erts_gzinflate_buffer(char*, uLong);
ErlDrvBinary* erts_gzdeflate_buffer(char*, uLong);
9 changes: 0 additions & 9 deletions erts/emulator/drivers/common/gzio_zutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@
* that may change or not exist at all.
*/

#ifndef HAVE_LIBZ
/* Use our "real" copy of zutil.h if we don't use shared zlib */
#include "zutil.h"

#else /* HAVE_LIBZ: Shared zlib is used */

#define local static
#define DEF_MEM_LEVEL 8
#define zmemcpy sys_memcpy
Expand Down Expand Up @@ -77,6 +71,3 @@
# define OS_CODE 0x03 /* assume Unix */
#endif


#endif /* HAVE_LIBZ */

Loading

0 comments on commit e99633a

Please sign in to comment.