[pypy-svn] r54655 - in pypy/dist/pypy/translator/tool: . test

xoraxax at codespeak.net xoraxax at codespeak.net
Sun May 11 19:49:34 CEST 2008


Author: xoraxax
Date: Sun May 11 19:49:32 2008
New Revision: 54655

Modified:
   pypy/dist/pypy/translator/tool/cbuild.py
   pypy/dist/pypy/translator/tool/test/test_cbuild.py
Log:
try to avoid duplicates when calling merge with a long list of ecis.

Modified: pypy/dist/pypy/translator/tool/cbuild.py
==============================================================================
--- pypy/dist/pypy/translator/tool/cbuild.py	(original)
+++ pypy/dist/pypy/translator/tool/cbuild.py	Sun May 11 19:49:32 2008
@@ -81,7 +81,16 @@
         return "<ExternalCompilationInfo (%s)>" % ", ".join(info)
 
     def merge(self, *others):
-        others = list(others)
+        def unique_elements(l):
+            seen = set()
+            new_objs = []
+            for obj in l:
+                if obj not in seen:
+                    new_objs.append(obj)
+                    seen.add(obj)
+            return new_objs
+        others = unique_elements(list(others))
+
         attrs = {}
         for name in self._ATTRIBUTES:
             if name not in self._AVOID_DUPLICATES:

Modified: pypy/dist/pypy/translator/tool/test/test_cbuild.py
==============================================================================
--- pypy/dist/pypy/translator/tool/test/test_cbuild.py	(original)
+++ pypy/dist/pypy/translator/tool/test/test_cbuild.py	Sun May 11 19:49:32 2008
@@ -74,6 +74,20 @@
         assert e.includes == ('x.h', 'y.h', 'z.h')
         assert e.post_include_lines == ('p1', 'p2', 'p3')
 
+    def test_merge2(self):
+        e1 = ExternalCompilationInfo(
+            pre_include_lines  = ['1'],
+        )
+        e2 = ExternalCompilationInfo(
+            pre_include_lines  = ['2'],
+        )
+        e3 = ExternalCompilationInfo(
+            pre_include_lines  = ['3'],
+        )
+        e = e1.merge(e2)
+        e = e.merge(e3, e3)
+        assert e.pre_include_lines == ('1', '2', '3')
+
     def test_convert_sources_to_c_files(self):
         eci = ExternalCompilationInfo(
             separate_module_sources = ['xxx'],



More information about the Pypy-commit mailing list