|
From: <ale...@us...> - 2014-11-26 17:43:53
|
Revision: 60297
http://sourceforge.net/p/firebird/code/60297
Author: alexpeshkoff
Date: 2014-11-26 17:43:45 +0000 (Wed, 26 Nov 2014)
Log Message:
-----------
Load zlib dynamically to make it possible for the client to run without it
Added configure switch to turn off build with compression
Cleanup zlib streams to avoid memory leak
Use SHRLIB_EXT instead explicit "so"
Modified Paths:
--------------
firebird/trunk/configure.ac
firebird/trunk/src/common/os/posix/mod_loader.cpp
firebird/trunk/src/jrd/flu.cpp
firebird/trunk/src/remote/remote.cpp
firebird/trunk/src/remote/remote.h
Modified: firebird/trunk/configure.ac
===================================================================
--- firebird/trunk/configure.ac 2014-11-26 10:20:45 UTC (rev 60296)
+++ firebird/trunk/configure.ac 2014-11-26 17:43:45 UTC (rev 60297)
@@ -485,6 +485,7 @@
AC_SUBST(AR_OPTIONS)
AC_SUBST(PLATFORM)
AC_SUBST(SHRLIB_EXT)
+AC_DEFINE_UNQUOTED(SHRLIB_EXT, "$SHRLIB_EXT", [Extension for shared libraries])
AC_DEFINE(CASE_SENSITIVITY, true, [Define this if paths are case sensitive])
@@ -653,6 +654,15 @@
esac])
AC_SUBST(GPRE_LANGUAGE_MODULES)
+dnl Compression switch
+COMPRESSION=Y
+AC_ARG_WITH(wire-compress,
+ [ --with-wire-compress support compression of data, tarnsfered over the wire (default=yes)],
+ [case "$withval" in
+ yes) ;;
+ no) COMPRESSION=N;;
+ *) AC_MSG_ERROR(bad value '${withval}' for --with-wire-compress);;
+ esac])
dnl Checks for programs.
@@ -723,8 +733,12 @@
AC_CHECK_HEADERS(iconv.h)
AC_CHECK_HEADERS(libio.h)
AC_CHECK_HEADERS(linux/falloc.h)
-AC_CHECK_HEADERS(zlib.h)
+dnl check for compression
+if test "$COMPRESSION" = "Y"; then
+ AC_CHECK_HEADERS(zlib.h,,AC_MSG_ERROR(zlib header not found - please install development zlib package))
+fi
+
dnl check for ICU presence
AC_CHECK_HEADER(unicode/ucnv.h,,AC_MSG_ERROR(ICU support not found - please install development ICU package))
dnl setting ICU_OK here is done to only avoid default action
@@ -740,7 +754,6 @@
dnl Check for libraries
AC_SEARCH_LIBS(dlopen, dl)
-AC_CHECK_LIB(z, deflate)
AC_CHECK_LIB(m, main)
if test "$EDITLINE_FLG" = "Y"; then
AC_CHECK_LIB(curses, tgetent, TERMLIB=curses, \
Modified: firebird/trunk/src/common/os/posix/mod_loader.cpp
===================================================================
--- firebird/trunk/src/common/os/posix/mod_loader.cpp 2014-11-26 10:20:45 UTC (rev 60296)
+++ firebird/trunk/src/common/os/posix/mod_loader.cpp 2014-11-26 17:43:45 UTC (rev 60297)
@@ -67,10 +67,10 @@
if (name.isEmpty())
return;
- Firebird::PathName::size_type pos = name.rfind(".so");
+ Firebird::PathName::size_type pos = name.rfind("." SHRLIB_EXT);
if (pos != name.length() - 3)
{
- name += ".so";
+ name += "." SHRLIB_EXT;
}
pos = name.rfind('/');
pos = (pos == Firebird::PathName::npos) ? 0 : pos + 1;
Modified: firebird/trunk/src/jrd/flu.cpp
===================================================================
--- firebird/trunk/src/jrd/flu.cpp 2014-11-26 10:20:45 UTC (rev 60296)
+++ firebird/trunk/src/jrd/flu.cpp 2014-11-26 17:43:45 UTC (rev 60297)
@@ -109,19 +109,15 @@
// always try to use module "as is"
{MOD_SUFFIX, "", false},
-#ifdef HPUX
- {MOD_SUFFIX, ".sl", true},
-#endif
-
#ifdef DYNAMIC_SHARED_LIBRARIES
- {MOD_SUFFIX, ".so", true},
+ {MOD_SUFFIX, "." SHRLIB_EXT, true},
{MOD_PREFIX, "lib", true},
#endif
-
+/*
#ifdef DARWIN
{MOD_SUFFIX, ".dylib", true},
#endif
-
+ */
};
// UDF/BLOB filter verifier
Modified: firebird/trunk/src/remote/remote.cpp
===================================================================
--- firebird/trunk/src/remote/remote.cpp 2014-11-26 10:20:45 UTC (rev 60296)
+++ firebird/trunk/src/remote/remote.cpp 2014-11-26 17:43:45 UTC (rev 60297)
@@ -36,6 +36,7 @@
#include "../common/classes/init.h"
#include "../common/db_alias.h"
#include "firebird/Interface.h"
+#include "../common/os/mod_loader.h"
#ifdef DEV_BUILD
Firebird::AtomicCounter rem_port::portCounter;
@@ -820,37 +821,6 @@
{
}
-rem_port::~rem_port()
-{
- if (port_events_shutdown)
- {
- port_events_shutdown(this);
- }
-
- delete port_srv_auth;
- delete port_srv_auth_block;
- delete port_version;
- delete port_connection;
- delete port_host;
- delete port_server_crypt_callback;
-
-#ifdef DEBUG_XDR_MEMORY
- delete port_packet_vector;
-#endif
-
- while (port_crypt_keys.hasData())
- {
- delete port_crypt_keys.pop();
- }
-
- if (port_crypt_plugin)
- Firebird::PluginManagerInterfacePtr()->releasePlugin(port_crypt_plugin);
-
-#ifdef DEV_BUILD
- --portCounter;
-#endif
-}
-
/*
void Rdb::set_async_vector(ISC_STATUS* userStatus) throw()
{
@@ -1391,6 +1361,88 @@
}
+namespace {
+ class ZLib
+ {
+ public:
+ ZLib(Firebird::MemoryPool&)
+ {
+ const char* name = "libz." SHRLIB_EXT ".1";
+ z.reset(ModuleLoader::fixAndLoadModule(name));
+ if (z)
+ symbols();
+ if (!z)
+ (Firebird::Arg::Gds(isc_random) << "Error loading zlib").raise();
+ }
+
+ int ZEXPORT (*deflateInit_)(z_stream* strm, int level, const char *version, int stream_size);
+ int ZEXPORT (*inflateInit_)(z_stream* strm, const char *version, int stream_size);
+ int ZEXPORT (*deflate)(z_stream* strm, int flush);
+ int ZEXPORT (*inflate)(z_stream* strm, int flush);
+ void ZEXPORT (*deflateEnd)(z_stream* strm);
+ void ZEXPORT (*inflateEnd)(z_stream* strm);
+
+ operator bool() {return z.hasData();}
+ bool operator!() {return !z.hasData();}
+
+ private:
+ Firebird::AutoPtr<ModuleLoader::Module> z;
+
+ void symbols()
+ {
+#define FB_ZSYMB(A) z->findSymbol(STRINGIZE(A), A); if (!A) {z.reset(NULL); return;}
+ FB_ZSYMB(deflateInit_)
+ FB_ZSYMB(inflateInit_)
+ FB_ZSYMB(deflate)
+ FB_ZSYMB(inflate)
+ FB_ZSYMB(deflateEnd)
+ FB_ZSYMB(inflateEnd)
+#undef FB_ZSYMB
+ }
+ };
+
+ Firebird::InitInstance<ZLib> zlib;
+}
+
+rem_port::~rem_port()
+{
+ if (port_events_shutdown)
+ {
+ port_events_shutdown(this);
+ }
+
+ delete port_srv_auth;
+ delete port_srv_auth_block;
+ delete port_version;
+ delete port_connection;
+ delete port_host;
+ delete port_server_crypt_callback;
+
+#ifdef DEBUG_XDR_MEMORY
+ delete port_packet_vector;
+#endif
+
+ while (port_crypt_keys.hasData())
+ {
+ delete port_crypt_keys.pop();
+ }
+
+ if (port_crypt_plugin)
+ Firebird::PluginManagerInterfacePtr()->releasePlugin(port_crypt_plugin);
+
+#ifdef DEV_BUILD
+ --portCounter;
+#endif
+
+#ifdef WIRE_COMPRESS_SUPPORT
+ if (port_compressed)
+ {
+ zlib().deflateEnd(&port_send_stream);
+ zlib().inflateEnd(&port_recv_stream);
+ }
+#endif
+}
+
bool REMOTE_inflate(rem_port* port, PacketReceive* packet_receive, UCHAR* buffer, SSHORT buffer_length, SSHORT* length)
{
#ifdef WIRE_COMPRESS_SUPPORT
@@ -1413,12 +1465,11 @@
#endif
#endif
- if (inflate(&strm, Z_NO_FLUSH) != Z_OK)
+ if (zlib().inflate(&strm, Z_NO_FLUSH) != Z_OK)
{
#ifdef COMPRESS_DEBUG
fprintf(stderr, "Inflate error\n");
#endif
- (void)inflateEnd(&strm);
port->port_flags &= ~PORT_z_data;
return false;
}
@@ -1450,7 +1501,6 @@
SSHORT l = (SSHORT) (port->port_buff_size - strm.avail_in);
if ((!packet_receive(port, strm.next_in, l, &l)) || (l <= 0)) // fixit - 2 ways to report errors in same routine
{
- (void)inflateEnd(&strm);
port->port_flags &= ~PORT_z_data;
return false;
}
@@ -1470,7 +1520,6 @@
#endif
}
-
bool REMOTE_deflate(XDR* xdrs, ProtoWrite* proto_write, PacketSend* packet_send, bool flash)
{
#ifdef WIRE_COMPRESS_SUPPORT
@@ -1499,7 +1548,7 @@
fprintf(stderr, "\n");
#endif
#endif
- int ret = deflate(&strm, flash ? Z_SYNC_FLUSH : Z_NO_FLUSH);
+ int ret = zlib().deflate(&strm, flash ? Z_SYNC_FLUSH : Z_NO_FLUSH);
if (ret == Z_BUF_ERROR)
ret = 0;
if (ret != 0)
@@ -1542,7 +1591,6 @@
#endif
}
-
void rem_port::initCompression()
{
#ifdef WIRE_COMPRESS_SUPPORT
@@ -1551,7 +1599,7 @@
port_send_stream.zalloc = Z_NULL;
port_send_stream.zfree = Z_NULL;
port_send_stream.opaque = Z_NULL;
- int ret = deflateInit(&port_send_stream, Z_DEFAULT_COMPRESSION);
+ int ret = zlib().deflateInit(&port_send_stream, Z_DEFAULT_COMPRESSION);
if (ret != Z_OK)
(Firebird::Arg::Gds(isc_random) << "compression stream init error").raise(); // add error code
port_send_stream.next_out = NULL;
@@ -1561,13 +1609,25 @@
port_recv_stream.opaque = Z_NULL;
port_recv_stream.avail_in = 0;
port_recv_stream.next_in = Z_NULL;
- ret = inflateInit(&port_recv_stream);
+ ret = zlib().inflateInit(&port_recv_stream);
if (ret != Z_OK)
+ {
+ zlib().deflateEnd(&port_send_stream);
(Firebird::Arg::Gds(isc_random) << "decompression stream init error").raise(); // add error code
+ }
- port_compressed.reset(FB_NEW(getPool()) UCHAR[port_buff_size * 2]);
+ try
+ {
+ port_compressed.reset(FB_NEW(getPool()) UCHAR[port_buff_size * 2]);
+ }
+ catch(const Firebird::Exception&)
+ {
+ zlib().deflateEnd(&port_send_stream);
+ zlib().inflateEnd(&port_recv_stream);
+ }
memset(port_compressed, 0, port_buff_size * 2);
port_recv_stream.next_in = &port_compressed[REM_RECV_OFFSET(port_buff_size)];
+
#ifdef COMPRESS_DEBUG
fprintf(stderr, "Completed init port %p\n", this);
#endif
Modified: firebird/trunk/src/remote/remote.h
===================================================================
--- firebird/trunk/src/remote/remote.h 2014-11-26 10:20:45 UTC (rev 60296)
+++ firebird/trunk/src/remote/remote.h 2014-11-26 17:43:45 UTC (rev 60297)
@@ -55,7 +55,7 @@
#endif
#endif // !WIN_NT
-#if defined(HAVE_ZLIB_H) && defined(HAVE_LIBZ)
+#if defined(HAVE_ZLIB_H)
#define WIRE_COMPRESS_SUPPORT 1
#endif
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|