← Back to team overview

zorba-coders team mailing list archive

[Merge] lp:~zorba-coders/zorba/bug1058231b into lp:zorba

 

Rodolfo Ochoa has proposed merging lp:~zorba-coders/zorba/bug1058231b into lp:zorba.

Requested reviews:
  Chris Hillery (ceejatec)
Related bugs:
  Bug #1058231 in Zorba: "Can´t get Zorba Java API to work under Win XP"
  https://bugs.launchpad.net/zorba/+bug/1058231

For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/bug1058231b/+merge/139556

This is a new branch where you can appreciate better the changes,
you can follow your last comments in previous branch merge proposal:
https://code.launchpad.net/~zorba-coders/zorba/bug1058231/+merge/129531

Changes required are applied here.
-- 
https://code.launchpad.net/~zorba-coders/zorba/bug1058231b/+merge/139556
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'bin/path_util.cpp'
--- bin/path_util.cpp	2012-09-19 21:16:15 +0000
+++ bin/path_util.cpp	2012-12-12 19:43:21 +0000
@@ -28,27 +28,6 @@
 
 namespace PathUtil {
 
-static std::string
-getPathFromEnvironment(std::string const& aEnvVar)
-{
-#ifdef WIN32
-  char* lBuffer;
-  size_t lLen=0;
-  errno_t lErr = getenv_s(&lLen, NULL, 0, aEnvVar.c_str());
-  if (lErr || !lLen) return "";
-  lBuffer = (char*)malloc(lLen * sizeof(char));
-  if (!lBuffer) return "";
-  getenv_s(&lLen, lBuffer, lLen, aEnvVar.c_str());
-  std::string lRes(lBuffer);
-  free(lBuffer);
-  return lRes;
-#else
-  const char* lEnvValue = getenv(aEnvVar.c_str());
-  return lEnvValue != 0 ? lEnvValue : "";
-#endif
-}
-
-
 void
 tokenizePath(
   const std::string&    aPathStr,
@@ -66,42 +45,22 @@
   }
 }
 
-
-String
-concatenatePaths( const std::vector<String>& aPathList)
-{
-  String delimiter(filesystem_path::get_path_separator());
-
-  String lResult;
-  for (std::vector<String>::const_iterator lIter = aPathList.begin();
-       lIter != aPathList.end(); ++lIter)
-  {
-    lResult += delimiter + *lIter;
-  }
-
-  return lResult;
-}
-
-
 void
 setPathsOnContext(
   const ZorbaCMDProperties& aProperties,
   StaticContext_t& aStaticCtx)
 {
   std::vector<String> lPath;
-  std::string lPathStr, lEnvStr;
+  std::string lPathStr;
 
   // Compute the current working directory to append to all paths.
   filesystem_path lCWD;
 
   // setModulePaths() *overwrites* the URI path and lib path, so there's no
-  // sense in calling both. So if either --module-path or ZORBA_MODULE_PATH
-  // exists, just use those.
+  // sense in calling both. So if --module-path exists, just use it.
   aProperties.getModulePath(lPathStr);
-  lEnvStr = getPathFromEnvironment("ZORBA_MODULE_PATH");
-  if (lPathStr.length() > 0 || lEnvStr.length() > 0) {
+  if (lPathStr.length() > 0) {
     tokenizePath(lPathStr, lPath);
-    tokenizePath(lEnvStr, lPath);
     lPath.push_back(lCWD.get_path());
     aStaticCtx->setModulePaths(lPath);
   }
@@ -109,8 +68,6 @@
     // Compute and set URI path
     aProperties.getURIPath(lPathStr);
     tokenizePath(lPathStr, lPath);
-    lEnvStr = getPathFromEnvironment("ZORBA_URI_PATH");
-    tokenizePath(lEnvStr, lPath);
     lPath.push_back(lCWD.get_path());
     aStaticCtx->setURIPath(lPath);
     lPath.clear();
@@ -119,8 +76,6 @@
     aProperties.getLibPath(lPathStr);
     tokenizePath(lPathStr, lPath);
     lPath.push_back(lCWD.get_path());
-    lEnvStr = getPathFromEnvironment("ZORBA_LIB_PATH");
-    tokenizePath(lEnvStr, lPath);
     aStaticCtx->setLibPath(lPath);
   }
 }

=== modified file 'bin/path_util.h'
--- bin/path_util.h	2012-09-19 21:16:15 +0000
+++ bin/path_util.h	2012-12-12 19:43:21 +0000
@@ -35,10 +35,6 @@
     void
     tokenizePath(const std::string& aPathStr, std::vector<String>&  aResult);
 
-
-    String
-    concatenatePaths( const std::vector<String>& aPathList);
-
   }
 } /* namespace zorba */
 

=== modified file 'include/zorba/config.h.cmake'
--- include/zorba/config.h.cmake	2012-09-19 21:16:15 +0000
+++ include/zorba/config.h.cmake	2012-12-12 19:43:21 +0000
@@ -160,6 +160,8 @@
 
 ////////// Zorba //////////////////////////////////////////////////////////////
 
+#cmakedefine ZORBA_STORE_NAME "zorba_${ZORBA_STORE_NAME}"
+
 // Version
 #define ZORBA_VERSION "${ZORBA_VERSION}"
 #define ZORBA_MAJOR_NUMBER ${ZORBA_MAJOR_NUMBER}

=== modified file 'src/api/store_consts.cpp'
--- src/api/store_consts.cpp	2012-12-05 15:07:29 +0000
+++ src/api/store_consts.cpp	2012-12-12 19:43:21 +0000
@@ -14,6 +14,7 @@
  * limitations under the License.
  */
 
+#include "stdafx.h"
 #include <zorba/store_consts.h>
 
 namespace zorba {

=== modified file 'src/context/root_static_context.cpp'
--- src/context/root_static_context.cpp	2012-11-06 10:11:37 +0000
+++ src/context/root_static_context.cpp	2012-12-12 19:43:21 +0000
@@ -31,11 +31,19 @@
 
 #include "store/api/item_factory.h"
 
+#ifdef WIN32
+#include <zorba/config.h>
+#endif WIN32
+
+
+// DEFINE ENVIRONMENT VARIABLES
 namespace zorba 
 {
 
 
 #ifdef WIN32
+#define MAX_VAR_SIZE 32767
+
 static void append_to_path(
     std::vector<zstring>& aPath,
     zstring& zorba_root,
@@ -47,6 +55,62 @@
   full_path.append("\\");
   aPath.push_back(full_path);
 }
+
+static void append_env_var(
+  wchar_t const * env_var_name,
+  std::vector<zstring>& pathsVector,
+  zstring& core_path,
+  zstring& noncore_path
+  )
+{
+  wchar_t env_var[MAX_VAR_SIZE];
+  DWORD path_size;
+  // get a relative path from the environment for LIB
+  path_size = GetEnvironmentVariableW (env_var_name,
+                                       env_var,
+                                       MAX_VAR_SIZE );
+  if (path_size)
+  {
+    char  dll_path[MAX_VAR_SIZE];
+    WideCharToMultiByte(CP_UTF8,
+                        0,
+                        env_var,
+                        -1,
+                        dll_path,
+                        MAX_VAR_SIZE,
+                        NULL,
+                        NULL);
+    char * str_env = std::strtok(dll_path, ";");
+    while (str_env !=NULL) {
+      zstring zorba_env_dir(str_env);
+      if (str_env[strlen(str_env)-1] != '\\')
+      {
+        zorba_env_dir.append("\\");
+      }
+      append_to_path(pathsVector, zorba_env_dir, core_path);
+      append_to_path(pathsVector, zorba_env_dir, noncore_path);
+      str_env = std::strtok(NULL, ";");
+    }
+  }
+}
+#else
+  static void append_env_var(
+  char * env_var_name,
+  std::vector<zstring>& pathsVector
+  )
+{
+  char* dll_path = getenv(env_var_name);
+  char* str_env = std::strtok(dll_path, ";");
+  while (str_env !=NULL) {
+    zstring zorba_env_dir(str_env);
+    if (str_env[strlen(str_env)-1] != '/')
+    {
+      zorba_env_dir.append("/");
+    }
+    pathsVector.push_back(zorba_env_dir);
+    str_env = std::strtok(NULL, ";");
+  }
+}
 #endif
 
 
@@ -133,7 +197,8 @@
   // compute the relative path to zorba_simplestore.dll (this dll)
   WCHAR  wdll_path[1024];
   DWORD dll_path_size;
-  dll_path_size = GetModuleFileNameW(NULL,
+  HMODULE h_module = GetModuleHandleW (_T(ZORBA_STORE_NAME));
+  dll_path_size = GetModuleFileNameW(h_module,
                                      wdll_path,
                                      sizeof(wdll_path)/sizeof(wdll_path[0]));
   if(dll_path_size)
@@ -167,6 +232,7 @@
     }
   }
 #endif
+
   const char ** lURIPathIter = get_builtin_uri_path();
   for (; *lURIPathIter != 0; ++lURIPathIter)
   {
@@ -186,6 +252,21 @@
   set_feature( feature::scripting );
   set_feature( feature::trace );
   set_feature( feature::http_resolution );
+
+#ifdef WIN32
+  // get a relative path from the environment for URI
+  append_env_var (L"ZORBA_MODULE_PATH", lRootURIPath, zstring(ZORBA_CORE_URI_DIR), zstring(ZORBA_NONCORE_URI_DIR));
+  append_env_var (L"ZORBA_MODULE_PATH", lRootLibPath, zstring(ZORBA_CORE_LIB_DIR), zstring(ZORBA_NONCORE_LIB_DIR));
+
+  append_env_var (L"ZORBA_URI_PATH", lRootURIPath, zstring(ZORBA_CORE_URI_DIR), zstring(ZORBA_NONCORE_URI_DIR));
+  append_env_var (L"ZORBA_LIB_PATH", lRootLibPath, zstring(ZORBA_CORE_LIB_DIR), zstring(ZORBA_NONCORE_LIB_DIR));
+
+#else
+  append_env_var ("ZORBA_URI_PATH", lRootURIPath);
+  append_env_var ("ZORBA_LIB_PATH", lRootLibPath);
+
+#endif
+
 } 
 
 

=== modified file 'src/util/hash/hash.cpp'
--- src/util/hash/hash.cpp	2012-12-12 01:04:36 +0000
+++ src/util/hash/hash.cpp	2012-12-12 19:43:21 +0000
@@ -14,6 +14,7 @@
  * limitations under the License.
  */
 
+#include "stdafx.h"
 // standard
 #ifdef ZORBA_HASH_FN_PJW
 # include <limits>

=== modified file 'test/rbkt/modules/java/CMakeLists.txt'
--- test/rbkt/modules/java/CMakeLists.txt	2012-10-08 12:09:36 +0000
+++ test/rbkt/modules/java/CMakeLists.txt	2012-12-12 19:43:21 +0000
@@ -31,6 +31,8 @@
     GET_PROPERTY (JavaTest2_JAR_FILE TARGET JavaTest2 PROPERTY JAR_FILE)
     DECLARE_ZORBA_JAR(FILE ${JavaTest_JAR_FILE} TARGET JavaTest TEST_ONLY)
     DECLARE_ZORBA_JAR(FILE ${JavaTest2_JAR_FILE} TARGET JavaTest2 TEST_ONLY)
+    SET_TARGET_PROPERTIES (JavaTest PROPERTIES FOLDER "Tests")
+    SET_TARGET_PROPERTIES (JavaTest2 PROPERTIES FOLDER "Tests")
 
   ENDIF (Java_JAVAC_EXECUTABLE)
 ENDIF (${RESULT} GREATER -1)


Follow ups