[pypy-commit] pypy default: merge heads

arigo noreply at buildbot.pypy.org
Thu Oct 20 11:00:15 CEST 2011


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r48255:8fe3564dc575
Date: 2011-10-20 10:59 +0200
http://bitbucket.org/pypy/pypy/changeset/8fe3564dc575/

Log:	merge heads

diff --git a/pypy/module/__builtin__/__init__.py b/pypy/module/__builtin__/__init__.py
--- a/pypy/module/__builtin__/__init__.py
+++ b/pypy/module/__builtin__/__init__.py
@@ -23,6 +23,7 @@
         'map'           : 'app_functional.map',
         'reduce'        : 'app_functional.reduce',
         'filter'        : 'app_functional.filter',
+        'zip'           : 'app_functional.zip',
         'vars'          : 'app_inspect.vars',
         'dir'           : 'app_inspect.dir',
 
@@ -89,7 +90,6 @@
         'enumerate'     : 'functional.W_Enumerate',
         'min'           : 'functional.min',
         'max'           : 'functional.max',
-        'zip'           : 'functional.zip',
         'reversed'      : 'functional.reversed',
         'super'         : 'descriptor.W_Super',
         'staticmethod'  : 'descriptor.StaticMethod',
diff --git a/pypy/module/__builtin__/app_functional.py b/pypy/module/__builtin__/app_functional.py
--- a/pypy/module/__builtin__/app_functional.py
+++ b/pypy/module/__builtin__/app_functional.py
@@ -162,4 +162,21 @@
         item = seq[i]
         if func(item):
             result.append(item)
-    return tuple(result)
\ No newline at end of file
+    return tuple(result)
+
+def zip(*sequences):
+    """zip(seq1 [, seq2 [...]]) -> [(seq1[0], seq2[0] ...), (...)]
+
+Return a list of tuples, where each tuple contains the i-th element
+from each of the argument sequences.  The returned list is truncated
+in length to the length of the shortest argument sequence."""
+    if not sequences:
+        return []
+    result = []
+    iterators = [iter(seq) for seq in sequences]
+    while True:
+        try:
+            items = [next(it) for it in iterators]
+        except StopIteration:
+            return result
+        result.append(tuple(items))
diff --git a/pypy/module/__builtin__/functional.py b/pypy/module/__builtin__/functional.py
--- a/pypy/module/__builtin__/functional.py
+++ b/pypy/module/__builtin__/functional.py
@@ -201,27 +201,6 @@
     """
     return min_max(space, __args__, "min")
 
- at unwrap_spec(sequences_w="args_w")
-def zip(space, sequences_w):
-    """Return a list of tuples, where the nth tuple contains every nth item of
-    each collection.
-
-    If the collections have different lengths, zip returns a list as long as the
-    shortest collection, ignoring the trailing items in the other collections.
-    """
-    if not sequences_w:
-        return space.newlist([])
-    result_w = []
-    iterators_w = [space.iter(w_seq) for w_seq in sequences_w]
-    while True:
-        try:
-            items_w = [space.next(w_it) for w_it in iterators_w]
-        except OperationError, e:
-            if not e.match(space, space.w_StopIteration):
-                raise
-            return space.newlist(result_w)
-        result_w.append(space.newtuple(items_w))
-
 class W_Enumerate(Wrappable):
 
     def __init__(self, w_iter, w_start):
diff --git a/pypy/rpython/lltypesystem/rbuilder.py b/pypy/rpython/lltypesystem/rbuilder.py
--- a/pypy/rpython/lltypesystem/rbuilder.py
+++ b/pypy/rpython/lltypesystem/rbuilder.py
@@ -29,7 +29,7 @@
         except OverflowError:
             raise MemoryError
         newbuf = mallocfn(new_allocated)
-        copycontentsfn(ll_builder.buf, newbuf, 0, 0, ll_builder.allocated)
+        copycontentsfn(ll_builder.buf, newbuf, 0, 0, ll_builder.used)
         ll_builder.buf = newbuf
         ll_builder.allocated = new_allocated
     return func_with_new_name(stringbuilder_grow, name)
@@ -56,7 +56,7 @@
 class BaseStringBuilderRepr(AbstractStringBuilderRepr):
     def empty(self):
         return nullptr(self.lowleveltype.TO)
-    
+
     @classmethod
     def ll_new(cls, init_size):
         if init_size < 0 or init_size > MAX:


More information about the pypy-commit mailing list