hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sur...@apache.org
Subject svn commit: r1401519 - in /hadoop/common/branches/branch-1-win/src/native/src/org/apache/hadoop/io/compress/zlib: ZlibCompressor.c ZlibDecompressor.c
Date Wed, 24 Oct 2012 00:18:12 GMT
Author: suresh
Date: Wed Oct 24 00:18:12 2012
New Revision: 1401519

URL: http://svn.apache.org/viewvc?rev=1401519&view=rev
Log:
HADOOP-8907. Provide means to look for zlib1.dll next to hadoop.dll on Windows. Contributed
by Ivan Mitic.

Modified:
    hadoop/common/branches/branch-1-win/src/native/src/org/apache/hadoop/io/compress/zlib/ZlibCompressor.c
    hadoop/common/branches/branch-1-win/src/native/src/org/apache/hadoop/io/compress/zlib/ZlibDecompressor.c

Modified: hadoop/common/branches/branch-1-win/src/native/src/org/apache/hadoop/io/compress/zlib/ZlibCompressor.c
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-1-win/src/native/src/org/apache/hadoop/io/compress/zlib/ZlibCompressor.c?rev=1401519&r1=1401518&r2=1401519&view=diff
==============================================================================
--- hadoop/common/branches/branch-1-win/src/native/src/org/apache/hadoop/io/compress/zlib/ZlibCompressor.c
(original)
+++ hadoop/common/branches/branch-1-win/src/native/src/org/apache/hadoop/io/compress/zlib/ZlibCompressor.c
Wed Oct 24 00:18:12 2012
@@ -68,6 +68,7 @@ static int (*dlsym_deflateEnd)(z_streamp
 #endif
 
 #ifdef WINDOWS
+#include <Strsafe.h>
 typedef int (__cdecl *__dlsym_deflateInit2_) (z_streamp, int, int, int, int, int, const char
*, int);
 typedef int (__cdecl *__dlsym_deflate) (z_streamp, int);
 typedef int (__cdecl *__dlsym_deflateSetDictionary) (z_streamp, const Bytef *, uInt);
@@ -78,6 +79,45 @@ static __dlsym_deflate dlsym_deflate;
 static __dlsym_deflateSetDictionary dlsym_deflateSetDictionary;
 static __dlsym_deflateReset dlsym_deflateReset;
 static __dlsym_deflateEnd dlsym_deflateEnd;
+
+// Try to load zlib.dll from the dir where hadoop.dll is located.
+HANDLE LoadZlibTryHadoopNativeDir() {
+  HMODULE libz = NULL;
+  PCWSTR HADOOP_DLL = L"hadoop.dll";
+  size_t HADOOP_DLL_LEN = 10;
+  WCHAR path[MAX_PATH] = { 0 };
+  BOOL isPathValid = FALSE;
+
+  // Get hadoop.dll full path
+  HMODULE hModule = GetModuleHandle(HADOOP_DLL);
+  if (hModule != NULL) {
+    if (GetModuleFileName(hModule, path, MAX_PATH) > 0) {
+      size_t size = 0;
+      if (StringCchLength(path, MAX_PATH, &size) == S_OK) {
+
+        // Update path variable to have the full path to the zlib.dll
+        size = size - HADOOP_DLL_LEN;
+        if (size >= 0) {
+          path[size] = L'\0';
+          if (StringCchCat(path, MAX_PATH, HADOOP_ZLIB_LIBRARY) == S_OK) {
+            isPathValid = TRUE;
+          }
+        }
+      }
+    }
+  }
+
+  if (isPathValid) {
+    libz = LoadLibrary(path);
+  }
+
+  // fallback to system paths
+  if (!libz) {
+    libz = LoadLibrary(HADOOP_ZLIB_LIBRARY);
+  }
+
+  return libz;
+}
 #endif
 
 JNIEXPORT void JNICALL
@@ -94,7 +134,8 @@ Java_org_apache_hadoop_io_compress_zlib_
 #endif
 
 #ifdef WINDOWS
-    HMODULE libz = LoadLibrary(HADOOP_ZLIB_LIBRARY);
+  HMODULE libz = LoadZlibTryHadoopNativeDir();
+
   if (!libz) {
 		THROW(env, "java/lang/UnsatisfiedLinkError", "Cannot load zlib1.dll");
 	  	return;

Modified: hadoop/common/branches/branch-1-win/src/native/src/org/apache/hadoop/io/compress/zlib/ZlibDecompressor.c
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-1-win/src/native/src/org/apache/hadoop/io/compress/zlib/ZlibDecompressor.c?rev=1401519&r1=1401518&r2=1401519&view=diff
==============================================================================
--- hadoop/common/branches/branch-1-win/src/native/src/org/apache/hadoop/io/compress/zlib/ZlibDecompressor.c
(original)
+++ hadoop/common/branches/branch-1-win/src/native/src/org/apache/hadoop/io/compress/zlib/ZlibDecompressor.c
Wed Oct 24 00:18:12 2012
@@ -68,6 +68,7 @@ static int (*dlsym_inflateEnd)(z_streamp
 #endif
 
 #ifdef WINDOWS
+#include <Strsafe.h>
 typedef int (__cdecl *__dlsym_inflateInit2_)(z_streamp, int, const char *, int);
 typedef int (__cdecl *__dlsym_inflate)(z_streamp, int);
 typedef int (__cdecl *__dlsym_inflateSetDictionary)(z_streamp, const Bytef *, uInt);
@@ -78,6 +79,7 @@ static __dlsym_inflate dlsym_inflate;
 static __dlsym_inflateSetDictionary dlsym_inflateSetDictionary;
 static __dlsym_inflateReset dlsym_inflateReset;
 static __dlsym_inflateEnd dlsym_inflateEnd;
+extern HANDLE LoadZlibTryHadoopNativeDir();
 #endif
 
 JNIEXPORT void JNICALL
@@ -94,7 +96,8 @@ JNIEnv *env, jclass class
 #endif
 
 #ifdef WINDOWS
-  HMODULE libz = LoadLibrary(HADOOP_ZLIB_LIBRARY);
+  HMODULE libz = LoadZlibTryHadoopNativeDir();
+
 	if (!libz) {
 	  THROW(env, "java/lang/UnsatisfiedLinkError", "Cannot load zlib1.dll");
 	  return;



Mime
View raw message