[pypy-svn] r46062 - in pypy/branch/pypy-more-rtti-inprogress/translator/cli: . src test

antocuni at codespeak.net antocuni at codespeak.net
Mon Aug 27 21:03:11 CEST 2007


Author: antocuni
Date: Mon Aug 27 21:03:10 2007
New Revision: 46062

Modified:
   pypy/branch/pypy-more-rtti-inprogress/translator/cli/database.py
   pypy/branch/pypy-more-rtti-inprogress/translator/cli/src/ll_os.cs
   pypy/branch/pypy-more-rtti-inprogress/translator/cli/src/pypylib.cs
   pypy/branch/pypy-more-rtti-inprogress/translator/cli/test/test_builtin.py
Log:
make os.environ work again with gencli



Modified: pypy/branch/pypy-more-rtti-inprogress/translator/cli/database.py
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/translator/cli/database.py	(original)
+++ pypy/branch/pypy-more-rtti-inprogress/translator/cli/database.py	Mon Aug 27 21:03:10 2007
@@ -29,6 +29,9 @@
     ootype.Record({"item0": ootype.Float, "item1": ootype.Float}):
     '[pypylib]pypy.runtime.Record_Float_Float',
 
+    ootype.Record({"item0": ootype.String, "item1": ootype.String}):
+    '[pypylib]pypy.runtime.Record_String_String',
+
     ll_os.STAT_RESULT: '[pypylib]pypy.runtime.Record_Stat_Result',
     }
 

Modified: pypy/branch/pypy-more-rtti-inprogress/translator/cli/src/ll_os.cs
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/translator/cli/src/ll_os.cs	(original)
+++ pypy/branch/pypy-more-rtti-inprogress/translator/cli/src/ll_os.cs	Mon Aug 27 21:03:10 2007
@@ -145,7 +145,6 @@
         private static Dictionary<int, IFile> FileDescriptors;
         private static int fdcount;
         private static Dictionary<int, string> ErrorMessages;
-        private static SortedList MyEnviron;
         
         // NB: these values are those used by Windows and they differs
         // from the Unix ones; the os module is patched with these
@@ -167,8 +166,6 @@
         static ll_os()
         {
             ErrorMessages = new Dictionary<int, string>();
-            MyEnviron = new SortedList(Environment.GetEnvironmentVariables());
-
             FileDescriptors = new Dictionary<int, IFile>();
             // XXX: what about CRLF conversion for stdin, stdout and stderr?
             // It seems that Posix let you read from stdout and
@@ -347,29 +344,41 @@
             File.Delete(path);
         }
 
-        public static string ll_os_environ(int index)
+        public static void ll_os_putenv(string key, string value)
         {
-            try {
-                string key = (string)MyEnviron.GetKey(index);
-                string value = (string)MyEnviron.GetByIndex(index);
-                return string.Format("{0}={1}", key, value);
-            }
-            catch(ArgumentOutOfRangeException) {
-                return null;
-            }
+            Environment.SetEnvironmentVariable(key, value);
         }
 
-        public static void ll_os_putenv(string s)
+        public static string ll_os_getenv(string key)
         {
-            char[] delim = {'='};
-            string[] parts = s.Split(delim, 2);
-            Environment.SetEnvironmentVariable(parts[0], parts[1]);
+            return Environment.GetEnvironmentVariable(key);
         }
 
         public static void ll_os_unsetenv(string s)
         {
             Environment.SetEnvironmentVariable(s, null);
         }
+
+        public static pypy.runtime.List<Record_String_String> ll_os_envitems()
+        {
+            pypy.runtime.List<Record_String_String> env = new pypy.runtime.List<Record_String_String>();
+            foreach (DictionaryEntry entry in Environment.GetEnvironmentVariables())
+                {
+                    Record_String_String var = new Record_String_String();
+                    var.item0 = (string)entry.Key;
+                    var.item1 = (string)entry.Value;
+                    env.Add(var);
+                }
+            return env;
+        }
+
+        public static pypy.runtime.List<string> ll_os_envkeys()
+        {
+            pypy.runtime.List<string> keys = new pypy.runtime.List<string>();
+            foreach (DictionaryEntry entry in Environment.GetEnvironmentVariables())
+                keys.Add((string)entry.Key);
+            return keys;
+        }
      
         public static long ll_os_lseek(int fd, int offset, int whence)
         {

Modified: pypy/branch/pypy-more-rtti-inprogress/translator/cli/src/pypylib.cs
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/translator/cli/src/pypylib.cs	(original)
+++ pypy/branch/pypy-more-rtti-inprogress/translator/cli/src/pypylib.cs	Mon Aug 27 21:03:10 2007
@@ -588,6 +588,18 @@
         public override int GetHashCode() { return item0.GetHashCode(); }
     }
 
+    public class Record_String_String {
+        public string item0;
+        public string item1;
+        public override string ToString() { return string.Format("({0}, {1},)", item0, item1); }
+        public override bool Equals(object obj)
+        {
+            Record_String_String x = (Record_String_String)obj;
+            return item0 == x.item0 && item1 == x.item1;
+        }
+        public override int GetHashCode() { return item0.GetHashCode(); }
+    }
+
     public class Record_Stat_Result {
         public int item0, item1, item2, item3, item4, item5, item6, item7, item8, item9;
         public override string ToString() 

Modified: pypy/branch/pypy-more-rtti-inprogress/translator/cli/test/test_builtin.py
==============================================================================
--- pypy/branch/pypy-more-rtti-inprogress/translator/cli/test/test_builtin.py	(original)
+++ pypy/branch/pypy-more-rtti-inprogress/translator/cli/test/test_builtin.py	Mon Aug 27 21:03:10 2007
@@ -112,6 +112,21 @@
         res = self.ll_to_string(self.interpret(fn, []))
         # XXX assert something about res
 
+    def test_environ(self):
+        def fn():
+            os.environ['PYPY_TEST_ENVIRON'] = '42'
+            return os.environ['PYPY_TEST_ENVIRON']
+        assert self.interpret(fn, []) == '42'
+
+    def test_environ_items(self):
+        def fn():
+            env = os.environ.items()
+            env2 = []
+            for key in os.environ.keys():
+                env2.append((key, os.environ[key]))
+            assert env == env2
+        self.interpret(fn, [])
+
     def test_os_listdir(self):
         def fn():
             return os.listdir('.')



More information about the Pypy-commit mailing list