hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cnaur...@apache.org
Subject svn commit: r1506325 - in /hadoop/common/trunk/hadoop-common-project/hadoop-common: CHANGES.txt src/main/native/src/org/apache/hadoop/util/NativeCodeLoader.c
Date Tue, 23 Jul 2013 22:06:48 GMT
Author: cnauroth
Date: Tue Jul 23 22:06:47 2013
New Revision: 1506325

URL: http://svn.apache.org/r1506325
Log:
HADOOP-9759. Add support for NativeCodeLoader#getLibraryName on Windows. Contributed by Chuan
Liu.

Modified:
    hadoop/common/trunk/hadoop-common-project/hadoop-common/CHANGES.txt
    hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/native/src/org/apache/hadoop/util/NativeCodeLoader.c

Modified: hadoop/common/trunk/hadoop-common-project/hadoop-common/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-common-project/hadoop-common/CHANGES.txt?rev=1506325&r1=1506324&r2=1506325&view=diff
==============================================================================
--- hadoop/common/trunk/hadoop-common-project/hadoop-common/CHANGES.txt (original)
+++ hadoop/common/trunk/hadoop-common-project/hadoop-common/CHANGES.txt Tue Jul 23 22:06:47
2013
@@ -635,6 +635,9 @@ Release 2.1.0-beta - 2013-07-02
 
     HADOOP-9738. TestDistCh fails. (jing9 via kihwal)
 
+    HADOOP-9759. Add support for NativeCodeLoader#getLibraryName on Windows.
+    (Chuan Liu via cnauroth)
+
   BREAKDOWN OF HADOOP-8562 SUBTASKS AND RELATED JIRAS
 
     HADOOP-8924. Hadoop Common creating package-info.java must not depend on

Modified: hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/native/src/org/apache/hadoop/util/NativeCodeLoader.c
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/native/src/org/apache/hadoop/util/NativeCodeLoader.c?rev=1506325&r1=1506324&r2=1506325&view=diff
==============================================================================
--- hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/native/src/org/apache/hadoop/util/NativeCodeLoader.c
(original)
+++ hadoop/common/trunk/hadoop-common-project/hadoop-common/src/main/native/src/org/apache/hadoop/util/NativeCodeLoader.c
Tue Jul 23 22:06:47 2013
@@ -38,9 +38,41 @@ JNIEXPORT jboolean JNICALL Java_org_apac
 JNIEXPORT jstring JNICALL Java_org_apache_hadoop_util_NativeCodeLoader_getLibraryName
   (JNIEnv *env, jclass clazz)
 {
+#ifdef UNIX
   Dl_info dl_info;
   int ret = dladdr(
       Java_org_apache_hadoop_util_NativeCodeLoader_getLibraryName,
       &dl_info);
   return (*env)->NewStringUTF(env, ret==0 ? "Unavailable" : dl_info.dli_fname);
+#endif
+
+#ifdef WINDOWS
+  SIZE_T ret = 0;
+  DWORD size = MAX_PATH;
+  LPWSTR filename = NULL;
+  HMODULE mod = NULL;
+  DWORD err = ERROR_SUCCESS;
+
+  MEMORY_BASIC_INFORMATION mbi;
+  ret = VirtualQuery(Java_org_apache_hadoop_util_NativeCodeLoader_getLibraryName,
+    &mbi, sizeof(mbi));
+  if (ret == 0) goto cleanup;
+  mod = mbi.AllocationBase;
+
+  do {
+    filename = (LPWSTR) realloc(filename, size * sizeof(WCHAR));
+    if (filename == NULL) goto cleanup;
+    GetModuleFileName(mod, filename, size);
+    size <<= 1;
+    err = GetLastError();
+  } while (err == ERROR_INSUFFICIENT_BUFFER);
+  
+  if (err != ERROR_SUCCESS) goto cleanup;
+
+  return (*env)->NewString(env, filename, (jsize) wcslen(filename));
+
+cleanup:
+  if (filename != NULL) free(filename);
+  return (*env)->NewStringUTF(env, "Unavailable");
+#endif
 }



Mime
View raw message