activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r583878 - in /activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang: System.cpp System.h
Date Thu, 11 Oct 2007 16:56:03 GMT
Author: tabish
Date: Thu Oct 11 09:56:02 2007
New Revision: 583878

URL: http://svn.apache.org/viewvc?rev=583878&view=rev
Log:
http://issues.apache.org/activemq/browse/AMQCPP-103

Fixing getenv to not reference environ, make plat get funcs return vector<string>

Modified:
    activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/System.cpp
    activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/System.h

Modified: activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/System.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/System.cpp?rev=583878&r1=583877&r2=583878&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/System.cpp (original)
+++ activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/System.cpp Thu Oct 11 09:56:02
2007
@@ -39,10 +39,6 @@
 using namespace decaf::internal;
 using namespace decaf::lang::exceptions;
 
-#if !defined(_WIN32)
-    extern char** environ;
-#endif 
-
 ////////////////////////////////////////////////////////////////////////////////
 AprPool System::aprPool;
 
@@ -134,16 +130,10 @@
     string key = "";
     string value = "";
     int tokens = 0;
-    char** env = getEnvArray();
-    if( env == NULL ) {
-        throw RuntimeException(
-            __FILE__, __LINE__,
-            "System::getenv - Failed to enumerate the environment." );
-    }
+    std::vector<std::string> env = getEnvArray();
 
-    for( int i = 0; *(env + i); i++ ){
+    for( std::size_t i = 0; i < env.size(); i++ ){
         tokenizer.reset( env[i], "=" );
-        delete env[i];  // Clean them as we go
 
         tokens = tokenizer.countTokens();
 
@@ -154,16 +144,15 @@
         } else if( tokens > 2 ) {
             // special case: first equals delimits the key value, the rest are
             // part of the variable
-            std::string envVal( environ[i] );
-            int pos = envVal.find( "=" );
-            key = envVal.substr( 0, pos );
-            value = envVal.substr( pos + 1, string::npos );
+            int pos = env[i].find( "=" );
+            key = env[i].substr( 0, pos );
+            value = env[i].substr( pos + 1, string::npos );
         } else if( tokens == 0 ) {
             // Odd case, got a string with no equals sign.
             throw IllegalArgumentException(
                 __FILE__, __LINE__,
                 "System::getenv - Invalid env string. %s",
-                environ[i] );
+                env[i].c_str() );
         } else {
             // Normal case.
             key = tokenizer.nextToken();
@@ -174,9 +163,6 @@
         values.setValue( key, value );
     }
 
-    // cleanup
-    delete [] env;
-
     return values;
 }
 
@@ -185,9 +171,9 @@
 #include <windows.h>
 
 ////////////////////////////////////////////////////////////////////////////////
-char** System::getEnvArray() {
+std::vector<std::string> System::getEnvArray() {
 
-    char** buffer = NULL;
+    std::vector<std::string> buffer;
     int count = 0;
     LPTSTR lpszVars;
     LPVOID lpvEnv;
@@ -203,14 +189,10 @@
         lpszVars += strlen(lpszVars)+1;
     }
 
-    // allocate buffer first dimension
-    buffer = new char*[count+1];
-    buffer[count] = NULL;
-
     lpszVars = (LPTSTR)lpvEnv;
     int index = 0;
     while( *lpszVars != NULL ) {
-        buffer[++index] = strdup( lpszVars );
+        buffer.push_back( lpszVars );
         lpszVars += strlen(lpszVars)+1;
     }
 
@@ -220,23 +202,21 @@
 
 #else
 
+////////////////////////////////////////////////////////////////////////////////
+extern char** environ;
 
 ////////////////////////////////////////////////////////////////////////////////
-char** System::getEnvArray() {
+std::vector<std::string> System::getEnvArray() {
 
-    char** buffer = NULL;
+    std::vector<std::string> buffer;
     int count = 0;
 
     for( int i = 0; *(environ + i); i++ ){
         count++;
     }
 
-    // allocate buffer first dimension
-    buffer = new char*[count+1];
-    buffer[count] = NULL;
-
     for( int i = 0; *(environ + i); i++ ){
-        buffer[i] = strdup( environ[i] );
+        buffer.push_back( environ[i] );
     }
 
     return buffer;

Modified: activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/System.h
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/System.h?rev=583878&r1=583877&r2=583878&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/System.h (original)
+++ activemq/activemq-cpp/trunk/src/decaf/src/main/decaf/lang/System.h Thu Oct 11 09:56:02
2007
@@ -86,9 +86,9 @@
          * Enumerates the environment and return an array of strings
          * with the values.  Caller owns the array.  The array is terminated
          * by an element that holds the value NULL
-         * @returns caller owned array of env name=value paris.
+         * @returns a vector of env name=value paris.
          */
-        static char** getEnvArray();
+        static std::vector< std::string > getEnvArray();
 
     };
 



Mime
View raw message