Author: Raffael Tfirst <[email protected]>
Branch: py3.5-async
Changeset: r86117:b7ea325def94
Date: 2016-08-09 17:53 +0200
http://bitbucket.org/pypy/pypy/changeset/b7ea325def94/

Log:    Merge with py3.5-async-translate

diff --git a/pypy/interpreter/astcompiler/codegen.py 
b/pypy/interpreter/astcompiler/codegen.py
--- a/pypy/interpreter/astcompiler/codegen.py
+++ b/pypy/interpreter/astcompiler/codegen.py
@@ -1310,7 +1310,7 @@
                     nsubkwargs += 1
                 elif nsubkwargs:
                     # A keyword argument and we already have a dict.
-                    self.load_const(kw.arg)
+                    self.load_const(self.space.wrap(kw.arg.decode('utf-8')))
                     kw.value.walkabout(self)
                     nseen += 1
                 else:
diff --git a/pypy/interpreter/generator.py b/pypy/interpreter/generator.py
--- a/pypy/interpreter/generator.py
+++ b/pypy/interpreter/generator.py
@@ -581,12 +581,13 @@
         # position, then raise a GeneratorExit.  Otherwise, there is
         # no point.
         # If coroutine was never awaited on issue a RuntimeWarning.
-        if self.pycode is not None:
-            if self.frame is not None:
-                if self.frame.fget_f_lasti(self.frame).int_w(self.space) == -1:
-                    raise oefmt(space.w_RuntimeWarning,
-                                "coroutine '%s' was never awaited",
-                                self.pycode.co_name)
+        if self.pycode is not None and \
+           self.frame is not None and \
+           self.frame.last_instr == -1:
+            # XXX PyErr_Occured in condition?
+            raise oefmt(self.space.w_RuntimeWarning,
+                        "coroutine '%s' was never awaited",
+                        self.pycode.co_name)
         if self.frame is not None:
             block = self.frame.lastblock
             while block is not None:
diff --git a/pypy/interpreter/pyopcode.py b/pypy/interpreter/pyopcode.py
--- a/pypy/interpreter/pyopcode.py
+++ b/pypy/interpreter/pyopcode.py
@@ -6,7 +6,7 @@
 
 from rpython.rlib import jit, rstackovf, rstring
 from rpython.rlib.debug import check_nonneg
-from rpython.rlib.objectmodel import we_are_translated
+from rpython.rlib.objectmodel import we_are_translated, always_inline
 from rpython.rlib.rarithmetic import r_uint, intmask
 from rpython.tool.sourcetools import func_with_new_name
 
@@ -45,6 +45,26 @@
 
     return func_with_new_name(opimpl, "opcode_impl_for_%s" % operationname)
 
+def get_func_desc(space, func):
+    if isinstance(func,function.Function):
+        return "()"
+    elif isinstance(func, function.Method):
+        return "()"
+    else:
+        return " object";
+
+@always_inline
+def list_unpack_helper(frame, itemcount):
+    space = frame.space
+    w_sum = space.newlist([], sizehint=itemcount)
+    for i in range(itemcount, 0, -1):
+        w_item = frame.peekvalue(i-1)
+        w_sum.extend(w_item)
+    while itemcount != 0:
+        frame.popvalue()
+        itemcount -= 1
+    return w_sum
+
 
 opcodedesc = bytecode_spec.opcodedesc
 HAVE_ARGUMENT = bytecode_spec.HAVE_ARGUMENT
@@ -1351,74 +1371,73 @@
             self.space.call_method(w_set, 'add', w_item)
         self.pushvalue(w_set)
 
-    def unpack_helper(self, itemcount, next_instr):
-        w_sum = []
+    def BUILD_SET_UNPACK(self, itemcount, next_instr):
+        space = self.space
+        w_sum = space.newset()
         for i in range(itemcount, 0, -1):
             w_item = self.peekvalue(i-1)
-            items = self.space.fixedview(w_item)
-            w_sum.extend(items)
+            # cannot use w_sum.update, w_item might not be a set
+            iterator = w_item.itervalues()
+            while True:
+                w_value = iterator.next_value()
+                if w_value is None:
+                    break
+                w_sum.add(w_value)
         while itemcount != 0:
             self.popvalue()
             itemcount -= 1
-        return w_sum
-
-    def BUILD_SET_UNPACK(self, itemcount, next_instr):
-        w_sum = self.unpack_helper(itemcount, next_instr)
-        self.pushvalue(self.space.newset(w_sum))
+        self.pushvalue(w_sum)
 
     def BUILD_TUPLE_UNPACK(self, itemcount, next_instr):
-        w_sum = self.unpack_helper(itemcount, next_instr)
-        self.pushvalue(self.space.newtuple(w_sum))
-        
+        w_list = list_unpack_helper(self, itemcount)
+        items = [w_obj for w_obj in w_list.getitems_unroll()]
+        self.pushvalue(self.space.newtuple(items))
+
     def BUILD_LIST_UNPACK(self, itemcount, next_instr):
-        w_sum = self.unpack_helper(itemcount, next_instr)
-        self.pushvalue(self.space.newlist(w_sum))
-        
-    def getFuncDesc(self, func):
-        if self.space.type(func).name.decode('utf-8') == 'method':
-            return "()"
-        elif self.space.type(func).name.decode('utf-8') == 'function':
-            return "()"
-        else:
-            return " object";
-    
+        w_sum = list_unpack_helper(self, itemcount)
+        self.pushvalue(w_sum)
+
     def BUILD_MAP_UNPACK_WITH_CALL(self, itemcount, next_instr):
+        space = self.space
         num_maps = itemcount & 0xff
         function_location = (itemcount>>8) & 0xff
-        w_dict = self.space.newdict()
-        dict_class = w_dict.__class__
+        w_dict = space.newdict()
         for i in range(num_maps, 0, -1):
             w_item = self.peekvalue(i-1)
-            if not issubclass(w_item.__class__, dict_class):
-                raise oefmt(self.space.w_TypeError,
+            if not space.ismapping_w(w_item):
+                raise oefmt(space.w_TypeError,
                         "'%T' object is not a mapping", w_item)
-            num_items = w_item.length()
-            keys = w_item.w_keys()
-            for j in range(num_items):
-                if self.space.type(keys.getitem(j)).name.decode('utf-8') == 
'method':
+            iterator = w_item.iterkeys()
+            while True:
+                w_key = iterator.next_key()
+                if w_key is None:
+                    break
+                if not isinstance(w_key, space.UnicodeObjectCls):
                     err_fun = self.peekvalue(num_maps + function_location-1)
-                    raise oefmt(self.space.w_TypeError,
-                        "%N%s keywords must be strings", err_fun, 
getFuncDesc(err_fun))
-                if 
self.space.is_true(self.space.contains(w_dict,keys.getitem(j))):
+                    raise oefmt(space.w_TypeError,
+                        "%N%s keywords must be strings", err_fun,
+                                                         get_func_desc(space, 
err_fun))
+                if space.is_true(space.contains(w_dict,w_key)):
                     err_fun = self.peekvalue(num_maps + function_location-1)
-                    err_arg = self.space.unicode_w(keys.getitem(j))
-                    raise oefmt(self.space.w_TypeError,
-                        "%N%s got multiple values for keyword argument '%s'", 
err_fun, self.getFuncDesc(err_fun), err_arg)
-            self.space.call_method(w_dict, 'update', w_item)
+                    err_arg = w_key
+                    raise oefmt(space.w_TypeError,
+                        "%N%s got multiple values for keyword argument '%s'",
+                          err_fun, get_func_desc(space, err_fun), 
space.str_w(err_arg))
+            space.call_method(w_dict, 'update', w_item)
         while num_maps != 0:
             self.popvalue()
             num_maps -= 1
         self.pushvalue(w_dict)
-        
+
     def BUILD_MAP_UNPACK(self, itemcount, next_instr):
-        w_dict = self.space.newdict()
-        dict_class = w_dict.__class__
+        space = self.space
+        w_dict = space.newdict()
         for i in range(itemcount, 0, -1):
             w_item = self.peekvalue(i-1)
-            if not issubclass(w_item.__class__, dict_class):
+            if not space.ismapping_w(w_item):
                 raise oefmt(self.space.w_TypeError,
                         "'%T' object is not a mapping", w_item)
-            self.space.call_method(w_dict, 'update', w_item)
+            space.call_method(w_dict, 'update', w_item)
         while itemcount != 0:
             self.popvalue()
             itemcount -= 1
diff --git a/pypy/module/_asyncio/test/test_asyncio.py 
b/pypy/module/_asyncio/test/test_asyncio.py
--- a/pypy/module/_asyncio/test/test_asyncio.py
+++ b/pypy/module/_asyncio/test/test_asyncio.py
@@ -1,9 +1,13 @@
 class AppTestAsyncIO(object):
     
-    spaceconfig = 
dict(usemodules=["select","_socket","thread","signal","struct","_multiprocessing","array","_posixsubprocess","fcntl","unicodedata"])
+    spaceconfig = dict(usemodules=["select","_socket","thread","signal",
+                                   "struct","_multiprocessing","array",
+                                   "_posixsubprocess","fcntl",
+                                   "unicodedata"])
     
     def test_gil_issue(self):
-        # the problem occured at await asyncio.open_connection after calling 
run_until_complete
+        # the problem occured at await asyncio.open_connection
+        # after calling run_until_complete
         """
         import encodings.idna
         import asyncio
@@ -11,4 +15,6 @@
             reader, writer = await asyncio.open_connection('example.com', 80)
         
         loop = asyncio.get_event_loop()
-        loop.run_until_complete(f())"""
+        loop.run_until_complete(f())
+        print("done with async loop")
+        """
diff --git a/pypy/module/imp/importing.py b/pypy/module/imp/importing.py
--- a/pypy/module/imp/importing.py
+++ b/pypy/module/imp/importing.py
@@ -85,6 +85,7 @@
         pathname = "<frozen %s>" % modulename
         code_w = ec.compiler.compile(source, pathname, 'exec', 0)
         w_mod = add_module(space, space.wrap(modulename))
+        assert isinstance(w_mod, Module) # XXX why is that necessary?
         space.setitem(space.sys.get('modules'), w_mod.w_name, w_mod)
         space.setitem(w_mod.w_dict, space.wrap('__name__'), w_mod.w_name)
         code_w.exec_code(space, w_mod.w_dict, w_mod.w_dict)
diff --git a/pypy/module/zipimport/interp_zipimport.py 
b/pypy/module/zipimport/interp_zipimport.py
--- a/pypy/module/zipimport/interp_zipimport.py
+++ b/pypy/module/zipimport/interp_zipimport.py
@@ -82,7 +82,7 @@
                    for key in self.cache.keys()]
         return space.newlist(items_w)
 
-    def iterkeys(self, space):
+    def iteratekeys(self, space):
         return space.iter(self.keys(space))
 
     def itervalues(self, space):
@@ -106,11 +106,11 @@
     'zip_dict',
     __getitem__ = interp2app(W_ZipCache.getitem),
     __contains__ = interp2app(W_ZipCache.contains),
-    __iter__ = interp2app(W_ZipCache.iterkeys),
+    __iter__ = interp2app(W_ZipCache.iteratekeys),
     items = interp2app(W_ZipCache.items),
     iteritems = interp2app(W_ZipCache.iteritems),
     keys = interp2app(W_ZipCache.keys),
-    iterkeys = interp2app(W_ZipCache.iterkeys),
+    iterkeys = interp2app(W_ZipCache.iteratekeys),
     values = interp2app(W_ZipCache.values),
     itervalues = interp2app(W_ZipCache.itervalues),
     clear = interp2app(W_ZipCache.clear),
diff --git a/pypy/objspace/std/memoryobject.py 
b/pypy/objspace/std/memoryobject.py
--- a/pypy/objspace/std/memoryobject.py
+++ b/pypy/objspace/std/memoryobject.py
@@ -198,7 +198,6 @@
     
     def get_native_fmtchar(self, fmt):
         from rpython.rtyper.lltypesystem import rffi
-        from sys import getsizeof
         size = -1
         if fmt[0] == '@':
             f = fmt[1]
@@ -215,7 +214,7 @@
         elif f == 'q' or f == 'Q':
             size = rffi.sizeof(rffi.LONGLONG)
         elif f == 'n' or f == 'N':
-            size = getsizeof(rffi.r_ssize_t)
+            size = rffi.sizeof(rffi.SIZE_T)
         elif f == 'f':
             size = rffi.sizeof(rffi.FLOAT)
         elif f == 'd':
@@ -225,7 +224,7 @@
         elif f == 'P':
             size = rffi.sizeof(rffi.VOIDP)
         return size
-    
+
     def descr_cast(self, space, w_format, w_shape=None):
         # XXX fixme. does not do anything near cpython (see memoryobjet.c 
memory_cast)
         self._check_released(space)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to