[pypy-svn] pypy arm-backend-2: merge default

bivab commits-noreply at bitbucket.org
Mon Feb 21 14:20:14 CET 2011


Author: David Schneider <david.schneider at picle.org>
Branch: arm-backend-2
Changeset: r42194:84a9fd2d73a8
Date: 2011-02-18 09:45 +0100
http://bitbucket.org/pypy/pypy/changeset/84a9fd2d73a8/

Log:	merge default

diff --git a/pypy/interpreter/function.py b/pypy/interpreter/function.py
--- a/pypy/interpreter/function.py
+++ b/pypy/interpreter/function.py
@@ -186,10 +186,8 @@
             raise OperationError( space.w_TypeError, space.wrap("setting function's dictionary to a non-dict") )
         self.w_func_dict = w_dict
 
-    # unwrapping is done through unwrap_specs in typedef.py
-
     def descr_function__new__(space, w_subtype, w_code, w_globals,
-                            w_name=None, w_argdefs=None, w_closure=None):
+                              w_name=None, w_argdefs=None, w_closure=None):
         code = space.interp_w(Code, w_code)
         if not space.is_true(space.isinstance(w_globals, space.w_dict)):
             raise OperationError(space.w_TypeError, space.wrap("expected dict"))
@@ -326,13 +324,13 @@
         self.defs_w    = space.fixedview(w_defs_w)
         self.w_module = w_module
 
-    def fget_func_defaults(space, self):
+    def fget_func_defaults(self, space):
         values_w = self.defs_w
         if not values_w or None in values_w:
             return space.w_None
         return space.newtuple(values_w)
 
-    def fset_func_defaults(space, self, w_defaults):
+    def fset_func_defaults(self, space, w_defaults):
         if space.is_w(w_defaults, space.w_None):
             self.defs_w = []
             return
@@ -340,21 +338,21 @@
             raise OperationError( space.w_TypeError, space.wrap("func_defaults must be set to a tuple object or None") )
         self.defs_w = space.fixedview(w_defaults)
 
-    def fdel_func_defaults(space, self):
+    def fdel_func_defaults(self, space):
         self.defs_w = []
 
-    def fget_func_doc(space, self):
+    def fget_func_doc(self, space):
         if self.w_doc is None:
             self.w_doc = self.code.getdocstring(space)
         return self.w_doc
 
-    def fset_func_doc(space, self, w_doc):
+    def fset_func_doc(self, space, w_doc):
         self.w_doc = w_doc
 
-    def fget_func_name(space, self):
+    def fget_func_name(self, space):
         return space.wrap(self.name)
 
-    def fset_func_name(space, self, w_name):
+    def fset_func_name(self, space, w_name):
         try:
             self.name = space.str_w(w_name)
         except OperationError, e:
@@ -365,10 +363,10 @@
             raise
 
 
-    def fdel_func_doc(space, self):
+    def fdel_func_doc(self, space):
         self.w_doc = space.w_None
 
-    def fget___module__(space, self):
+    def fget___module__(self, space):
         if self.w_module is None:
             if self.w_func_globals is not None and not space.is_w(self.w_func_globals, space.w_None):
                 self.w_module = space.call_method( self.w_func_globals, "get", space.wrap("__name__") )
@@ -376,16 +374,16 @@
                 self.w_module = space.w_None
         return self.w_module
 
-    def fset___module__(space, self, w_module):
+    def fset___module__(self, space, w_module):
         self.w_module = w_module
 
-    def fdel___module__(space, self):
+    def fdel___module__(self, space):
         self.w_module = space.w_None
 
-    def fget_func_code(space, self):
+    def fget_func_code(self, space):
         return space.wrap(self.code)
 
-    def fset_func_code(space, self, w_code):
+    def fset_func_code(self, space, w_code):
         from pypy.interpreter.pycode import PyCode
         if not self.can_change_code:
             raise OperationError(space.w_TypeError,
@@ -400,7 +398,7 @@
                 self.name, closure_len, len(code.co_freevars))
         self.code = code
 
-    def fget_func_closure(space, self):
+    def fget_func_closure(self, space):
         if self.closure is not None:
             w_res = space.newtuple( [ space.wrap(i) for i in self.closure ] )
         else:

diff --git a/pypy/jit/backend/llsupport/regalloc.py b/pypy/jit/backend/llsupport/regalloc.py
--- a/pypy/jit/backend/llsupport/regalloc.py
+++ b/pypy/jit/backend/llsupport/regalloc.py
@@ -158,9 +158,10 @@
 
     def _pick_variable_to_spill(self, v, forbidden_vars, selected_reg=None,
                                 need_lower_byte=False):
-        """ Silly algorithm.
+        """ Slightly less silly algorithm.
         """
-        candidates = []
+        cur_max_age = -1
+        candidate = None
         for next in self.reg_bindings:
             reg = self.reg_bindings[next]
             if next in forbidden_vars:
@@ -172,8 +173,13 @@
                     continue
             if need_lower_byte and reg in self.no_lower_byte_regs:
                 continue
-            return next
-        raise NoVariableToSpill
+            max_age = self.longevity[next][1]
+            if cur_max_age < max_age:
+                cur_max_age = max_age
+                candidate = next
+        if candidate is None:
+            raise NoVariableToSpill
+        return candidate
 
     def force_allocate_reg(self, v, forbidden_vars=[], selected_reg=None,
                            need_lower_byte=False):

diff --git a/pypy/interpreter/pycode.py b/pypy/interpreter/pycode.py
--- a/pypy/interpreter/pycode.py
+++ b/pypy/interpreter/pycode.py
@@ -9,8 +9,7 @@
 from pypy.interpreter import eval
 from pypy.interpreter.argument import Signature
 from pypy.interpreter.error import OperationError
-from pypy.interpreter.gateway import NoneNotWrapped 
-from pypy.interpreter.baseobjspace import ObjSpace, W_Root
+from pypy.interpreter.gateway import NoneNotWrapped, unwrap_spec
 from pypy.interpreter.astcompiler.consts import (CO_OPTIMIZED,
     CO_OPTIMIZED, CO_NEWLOCALS, CO_VARARGS, CO_VARKEYWORDS, CO_NESTED,
     CO_GENERATOR, CO_CONTAINSGLOBALS)
@@ -268,19 +267,19 @@
         co = self._to_code()
         dis.dis(co)
 
-    def fget_co_consts(space, self):
+    def fget_co_consts(self, space):
         return space.newtuple(self.co_consts_w)
     
-    def fget_co_names(space, self):
+    def fget_co_names(self, space):
         return space.newtuple(self.co_names_w)
 
-    def fget_co_varnames(space, self):
+    def fget_co_varnames(self, space):
         return space.newtuple([space.wrap(name) for name in self.co_varnames])
 
-    def fget_co_cellvars(space, self):
+    def fget_co_cellvars(self, space):
         return space.newtuple([space.wrap(name) for name in self.co_cellvars])
 
-    def fget_co_freevars(space, self):
+    def fget_co_freevars(self, space):
         return space.newtuple([space.wrap(name) for name in self.co_freevars])    
 
     def descr_code__eq__(self, w_other):
@@ -330,14 +329,10 @@
             w_result = space.xor(w_result, space.hash(w_const))
         return w_result
 
-    unwrap_spec =        [ObjSpace, W_Root, 
-                          int, int, int, int,
-                          str, W_Root, W_Root, 
-                          W_Root, str, str, int, 
-                          str, W_Root, 
-                          W_Root, int]
-
-
+    @unwrap_spec(argcount=int, nlocals=int, stacksize=int, flags=int,
+                 codestring=str,
+                 filename=str, name=str, firstlineno=int,
+                 lnotab=str, magic=int)
     def descr_code__new__(space, w_subtype,
                           argcount, nlocals, stacksize, flags,
                           codestring, w_constants, w_names,
@@ -369,7 +364,6 @@
         PyCode.__init__(code, space, argcount, nlocals, stacksize, flags, codestring, consts_w[:], names,
                       varnames, filename, name, firstlineno, lnotab, freevars, cellvars, magic=magic)
         return space.wrap(code)
-    descr_code__new__.unwrap_spec = unwrap_spec 
 
     def descr__reduce__(self, space):
         from pypy.interpreter.mixedmodule import MixedModule
@@ -402,4 +396,3 @@
 
     def repr(self, space):
         return space.wrap(self.get_repr())
-    repr.unwrap_spec = ['self', ObjSpace]

diff --git a/pypy/module/cpyext/api.py b/pypy/module/cpyext/api.py
--- a/pypy/module/cpyext/api.py
+++ b/pypy/module/cpyext/api.py
@@ -16,7 +16,7 @@
 from pypy.translator import platform
 from pypy.module.cpyext.state import State
 from pypy.interpreter.error import OperationError, operationerrfmt
-from pypy.interpreter.baseobjspace import W_Root, ObjSpace
+from pypy.interpreter.baseobjspace import W_Root
 from pypy.interpreter.gateway import unwrap_spec
 from pypy.interpreter.nestedscope import Cell
 from pypy.interpreter.module import Module
@@ -939,7 +939,7 @@
     copy_header_files(trunk_include)
 
 initfunctype = lltype.Ptr(lltype.FuncType([], lltype.Void))
- at unwrap_spec(ObjSpace, str, str)
+ at unwrap_spec(path=str, name=str)
 def load_extension_module(space, path, name):
     if os.sep not in path:
         path = os.curdir + os.sep + path      # force a '/' in the path

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
@@ -5,10 +5,10 @@
 import sys, os, stat
 
 from pypy.interpreter.module import Module
-from pypy.interpreter.gateway import Arguments, interp2app, unwrap_spec
+from pypy.interpreter.gateway import interp2app, unwrap_spec
 from pypy.interpreter.typedef import TypeDef, generic_new_descr
 from pypy.interpreter.error import OperationError, operationerrfmt
-from pypy.interpreter.baseobjspace import W_Root, ObjSpace, Wrappable
+from pypy.interpreter.baseobjspace import Wrappable
 from pypy.interpreter.eval import Code
 from pypy.rlib import streamio, jit, rposix
 from pypy.rlib.streamio import StreamErrors
@@ -108,6 +108,7 @@
 def check_sys_modules_w(space, modulename):
     return space.finditem_str(space.sys.get('modules'), modulename)
 
+ at unwrap_spec(name=str, level=int)
 def importhook(space, name, w_globals=None,
                w_locals=None, w_fromlist=None, level=-1):
     modulename = name
@@ -186,8 +187,6 @@
         space.setitem(space.sys.get('modules'), w(rel_modulename), space.w_None)
     space.timer.stop_name("importhook", modulename)
     return w_mod
-#
-importhook.unwrap_spec = [ObjSpace, str, W_Root, W_Root, W_Root, int]
 
 @jit.dont_look_inside
 def absolute_import(space, modulename, baselevel, fromlist_w, tentative):
@@ -330,7 +329,7 @@
     def __init__(self, space):
         pass
 
-    @unwrap_spec('self', ObjSpace, str)
+    @unwrap_spec(path=str)
     def descr_init(self, space, path):
         if not path:
             raise OperationError(space.w_ImportError, space.wrap(
@@ -346,7 +345,6 @@
                 raise OperationError(space.w_ImportError, space.wrap(
                     "existing directory"))
 
-    @unwrap_spec('self', ObjSpace, Arguments)
     def find_module_w(self, space, __args__):
         return space.wrap(None)
 

diff --git a/pypy/objspace/std/mapdict.py b/pypy/objspace/std/mapdict.py
--- a/pypy/objspace/std/mapdict.py
+++ b/pypy/objspace/std/mapdict.py
@@ -685,8 +685,9 @@
 
     @jit.dont_look_inside
     def is_valid_for_map(self, map):
+        # note that 'map' can be None here
         mymap = self.map_wref()
-        if mymap is map:     # also handles the case self.map_wref()->None
+        if mymap is not None and mymap is map:
             version_tag = map.terminator.w_cls.version_tag()
             if version_tag is self.version_tag:
                 # everything matches, it's incredibly fast

diff --git a/lib-python/conftest.py b/lib-python/conftest.py
--- a/lib-python/conftest.py
+++ b/lib-python/conftest.py
@@ -195,7 +195,7 @@
     RegrTest('test_dbm.py'),
     RegrTest('test_decimal.py'),
     RegrTest('test_decorators.py', core=True),
-    RegrTest('test_deque.py', core=True),
+    RegrTest('test_deque.py', core=True, usemodules='_collections'),
     RegrTest('test_descr.py', core=True, usemodules='_weakref'),
     RegrTest('test_descrtut.py', core=True),
     RegrTest('test_dict.py', core=True),
@@ -499,7 +499,7 @@
     RegrTest('test_complex_args.py'),
     RegrTest('test_contextlib.py', usemodules="thread"),
     RegrTest('test_ctypes.py', usemodules="_rawffi"),
-    RegrTest('test_defaultdict.py'),
+    RegrTest('test_defaultdict.py', usemodules='_collections'),
     RegrTest('test_email_renamed.py'),
     RegrTest('test_exception_variations.py'),
     RegrTest('test_float.py'),
@@ -716,8 +716,10 @@
         if test_stderr.rfind(26*"=" + "skipped" + 26*"=") != -1:
             skipped = True
         outcome = 'OK'
-        if not exit_status: 
-            if 'FAIL' in test_stdout or re.search('[^:]ERROR', test_stderr):
+        if not exit_status:
+            # match "FAIL" but not e.g. "FAILURE", which is in the output of a
+            # test in test_zipimport_support.py
+            if re.search(r'\bFAIL\b', test_stdout) or re.search('[^:]ERROR', test_stderr):
                 outcome = 'FAIL'
                 exit_status = 2  
         elif timedout: 

diff --git a/pypy/module/array/interp_array.py b/pypy/module/array/interp_array.py
--- a/pypy/module/array/interp_array.py
+++ b/pypy/module/array/interp_array.py
@@ -3,25 +3,20 @@
 from pypy.interpreter.error import OperationError
 from pypy.interpreter.typedef import TypeDef, GetSetProperty, make_weakref_descr
 from pypy.rpython.lltypesystem import lltype, rffi
-from pypy.interpreter.gateway import interp2app, ObjSpace, W_Root, \
-     ApplevelClass
-from pypy.rlib.jit import dont_look_inside
-from pypy.rlib import rgc
+from pypy.interpreter.gateway import interp2app, unwrap_spec
 from pypy.rlib.unroll import unrolling_iterable
 from pypy.rlib.rarithmetic import ovfcheck
-from pypy.rlib.rstruct.runpack import runpack
-from pypy.interpreter.argument import Arguments, Signature
-from pypy.interpreter.baseobjspace import ObjSpace, W_Root, Wrappable
+from pypy.interpreter.baseobjspace import Wrappable
 from pypy.objspace.std.stdtypedef import SMM, StdTypeDef
 from pypy.objspace.std.register_all import register_all
 from pypy.objspace.std.model import W_Object
-from pypy.interpreter.argument import Arguments, Signature
 from pypy.module._file.interp_file import W_File
 from pypy.interpreter.buffer import RWBuffer
 from pypy.objspace.std.multimethod import FailedToImplement
 
-def w_array(space, w_cls, typecode, w_args=None):
-    if len(w_args.arguments_w) > 1:
+ at unwrap_spec(typecode=str)
+def w_array(space, w_cls, typecode, __args__):
+    if len(__args__.arguments_w) > 1:
         msg = 'array() takes at most 2 arguments'
         raise OperationError(space.w_TypeError, space.wrap(msg))
     if len(typecode) != 1:
@@ -30,7 +25,7 @@
     typecode = typecode[0]
 
     if space.is_w(w_cls, space.gettypeobject(W_ArrayBase.typedef)):
-        if w_args.keywords: # XXX this might be forbidden fishing
+        if __args__.keywords:
             msg = 'array.array() does not take keyword arguments'
             raise OperationError(space.w_TypeError, space.wrap(msg))
 
@@ -39,8 +34,8 @@
             a = space.allocate_instance(types[tc].w_class, w_cls)
             a.__init__(space)
 
-            if len(w_args.arguments_w) > 0:
-                w_initializer = w_args.arguments_w[0]
+            if len(__args__.arguments_w) > 0:
+                w_initializer = __args__.arguments_w[0]
                 if space.type(w_initializer) is space.w_str:
                     a.fromstring(w_initializer)
                 elif space.type(w_initializer) is space.w_unicode:
@@ -55,7 +50,6 @@
         raise OperationError(space.w_ValueError, space.wrap(msg))
 
     return a
-w_array.unwrap_spec = (ObjSpace, W_Root, str, Arguments)
 
 
 array_append = SMM('append', 2)

diff --git a/pypy/config/pypyoption.py b/pypy/config/pypyoption.py
--- a/pypy/config/pypyoption.py
+++ b/pypy/config/pypyoption.py
@@ -32,7 +32,8 @@
      "crypt", "signal", "_rawffi", "termios", "zlib", "bz2",
      "struct", "_hashlib", "_md5", "_sha", "_minimal_curses", "cStringIO",
      "thread", "itertools", "pyexpat", "_ssl", "cpyext", "array",
-     "_bisect", "binascii", "_multiprocessing", '_warnings']
+     "_bisect", "binascii", "_multiprocessing", '_warnings',
+     "_collections"]
 ))
 
 translation_modules = default_modules.copy()

diff --git a/pypy/objspace/std/dictmultiobject.py b/pypy/objspace/std/dictmultiobject.py
--- a/pypy/objspace/std/dictmultiobject.py
+++ b/pypy/objspace/std/dictmultiobject.py
@@ -794,9 +794,8 @@
         w_dict.setitem(w_key, w_default)
         return w_default
 
-def dict_pop__DictMulti_ANY(space, w_dict, w_key, w_defaults):
-    defaults = space.listview(w_defaults)
-    len_defaults = len(defaults)
+def dict_pop__DictMulti_ANY(space, w_dict, w_key, defaults_w):
+    len_defaults = len(defaults_w)
     if len_defaults > 1:
         raise operationerrfmt(space.w_TypeError,
                               "pop expected at most 2 arguments, got %d",
@@ -804,7 +803,7 @@
     w_item = w_dict.getitem(w_key)
     if w_item is None:
         if len_defaults > 0:
-            return defaults[0]
+            return defaults_w[0]
         else:
             space.raise_key_error(w_key)
     else:

diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -1009,6 +1009,38 @@
         return self.call_args(w_func, args)
     appexec._annspecialcase_ = 'specialize:arg(2)'
 
+    def _next_or_none(self, w_it):
+        try:
+            return self.next(w_it)
+        except OperationError, e:
+            if not e.match(self, self.w_StopIteration):
+                raise
+            return None
+
+    def compare_by_iteration(self, w_iterable1, w_iterable2, op):
+        w_it1 = self.iter(w_iterable1)
+        w_it2 = self.iter(w_iterable2)
+        while True:
+            w_x1 = self._next_or_none(w_it1)
+            w_x2 = self._next_or_none(w_it2)
+            if w_x1 is None or w_x2 is None:
+                if op == 'eq': return self.newbool(w_x1 is w_x2)  # both None
+                if op == 'ne': return self.newbool(w_x1 is not w_x2)
+                if op == 'lt': return self.newbool(w_x2 is not None)
+                if op == 'le': return self.newbool(w_x1 is None)
+                if op == 'gt': return self.newbool(w_x1 is not None)
+                if op == 'ge': return self.newbool(w_x2 is None)
+                assert False, "bad value for op"
+            if not self.eq_w(w_x1, w_x2):
+                if op == 'eq': return self.w_False
+                if op == 'ne': return self.w_True
+                if op == 'lt': return self.lt(w_x1, w_x2)
+                if op == 'le': return self.le(w_x1, w_x2)
+                if op == 'gt': return self.gt(w_x1, w_x2)
+                if op == 'ge': return self.ge(w_x1, w_x2)
+                assert False, "bad value for op"
+    compare_by_iteration._annspecialcase_ = 'specialize:arg(3)'
+
     def decode_index(self, w_index_or_slice, seqlength):
         """Helper for custom sequence implementations
              -> (index, 0, 0) or

diff --git a/pypy/module/gc/interp_gc.py b/pypy/module/gc/interp_gc.py
--- a/pypy/module/gc/interp_gc.py
+++ b/pypy/module/gc/interp_gc.py
@@ -1,4 +1,4 @@
-from pypy.interpreter.gateway import ObjSpace
+from pypy.interpreter.gateway import unwrap_spec
 from pypy.interpreter.error import OperationError
 from pypy.rlib import rgc
 from pypy.rlib.streamio import open_file_as_stream
@@ -16,8 +16,6 @@
             cache.clear()
     rgc.collect()
     return space.wrap(0)
-    
-collect.unwrap_spec = [ObjSpace]
 
 def enable_finalizers(space):
     if space.user_del_action.finalizers_lock_count == 0:
@@ -25,14 +23,13 @@
                              space.wrap("finalizers are already enabled"))
     space.user_del_action.finalizers_lock_count -= 1
     space.user_del_action.fire()
-enable_finalizers.unwrap_spec = [ObjSpace]
 
 def disable_finalizers(space):
     space.user_del_action.finalizers_lock_count += 1
-disable_finalizers.unwrap_spec = [ObjSpace]
 
 # ____________________________________________________________
 
+ at unwrap_spec(filename=str)
 def dump_heap_stats(space, filename):
     tb = rgc._heap_stats()
     if not tb:
@@ -43,4 +40,3 @@
         f.write("%d %d " % (tb[i].count, tb[i].size))
         f.write(",".join([str(tb[i].links[j]) for j in range(len(tb))]) + "\n")
     f.close()
-dump_heap_stats.unwrap_spec = [ObjSpace, str]

diff --git a/pypy/module/_rawffi/test/test__rawffi.py b/pypy/module/_rawffi/test/test__rawffi.py
--- a/pypy/module/_rawffi/test/test__rawffi.py
+++ b/pypy/module/_rawffi/test/test__rawffi.py
@@ -494,9 +494,10 @@
 
     def test_invalid_bitfields(self):
         import _rawffi
-        raises(ValueError, _rawffi.Structure, [('A', 'c', 1)])
+        raises(TypeError, _rawffi.Structure, [('A', 'c', 1)])
         raises(ValueError, _rawffi.Structure, [('A', 'I', 129)])
         raises(ValueError, _rawffi.Structure, [('A', 'I', -1)])
+        raises(ValueError, _rawffi.Structure, [('A', 'I', 0)])
 
     def test_packed_structure(self):
         import _rawffi

diff --git a/pypy/module/pypyjit/test/test_pypy_c.py b/pypy/module/pypyjit/test/test_pypy_c.py
--- a/pypy/module/pypyjit/test/test_pypy_c.py
+++ b/pypy/module/pypyjit/test/test_pypy_c.py
@@ -105,9 +105,9 @@
                 pass
 
             def check(args, expected):
-                print >> sys.stderr, 'trying:', args
+                #print >> sys.stderr, 'trying:', args
                 result = main(*args)
-                print >> sys.stderr, 'got:', repr(result)
+                #print >> sys.stderr, 'got:', repr(result)
                 assert result == expected
                 assert type(result) is type(expected)
         """ % threshold)

diff --git a/pypy/module/pypyjit/interp_jit.py b/pypy/module/pypyjit/interp_jit.py
--- a/pypy/module/pypyjit/interp_jit.py
+++ b/pypy/module/pypyjit/interp_jit.py
@@ -9,7 +9,6 @@
 from pypy.rlib.jit import current_trace_length
 import pypy.interpreter.pyopcode   # for side-effects
 from pypy.interpreter.error import OperationError, operationerrfmt
-from pypy.interpreter.gateway import ObjSpace, Arguments, W_Root
 from pypy.interpreter.pycode import PyCode, CO_GENERATOR
 from pypy.interpreter.pyframe import PyFrame
 from pypy.interpreter.pyopcode import ExitFrame
@@ -119,13 +118,13 @@
 #
 # Public interface    
 
-def set_param(space, args):
+def set_param(space, __args__):
     '''Configure the tunable JIT parameters.
         * set_param(name=value, ...)            # as keyword arguments
         * set_param("name=value,name=value")    # as a user-supplied string
     '''
     # XXXXXXXXX
-    args_w, kwds_w = args.unpack()
+    args_w, kwds_w = __args__.unpack()
     if len(args_w) > 1:
         msg = "set_param() takes at most 1 non-keyword argument, %d given"
         raise operationerrfmt(space.w_TypeError, msg, len(args_w))
@@ -144,11 +143,8 @@
             raise operationerrfmt(space.w_TypeError,
                                   "no JIT parameter '%s'", key)
 
-set_param.unwrap_spec = [ObjSpace, Arguments]
-
 @dont_look_inside
-def residual_call(space, w_callable, args):
+def residual_call(space, w_callable, __args__):
     '''For testing.  Invokes callable(...), but without letting
     the JIT follow the call.'''
-    return space.call_args(w_callable, args)
-residual_call.unwrap_spec = [ObjSpace, W_Root, Arguments]
+    return space.call_args(w_callable, __args__)

diff --git a/pypy/module/gc/referents.py b/pypy/module/gc/referents.py
--- a/pypy/module/gc/referents.py
+++ b/pypy/module/gc/referents.py
@@ -1,7 +1,7 @@
 from pypy.rlib import rgc
 from pypy.interpreter.baseobjspace import W_Root, Wrappable
 from pypy.interpreter.typedef import TypeDef
-from pypy.interpreter.gateway import ObjSpace
+from pypy.interpreter.gateway import unwrap_spec
 from pypy.interpreter.error import wrap_oserror, OperationError
 from pypy.rlib.objectmodel import we_are_translated
 
@@ -140,7 +140,6 @@
         gcref = rgc.cast_instance_to_gcref(w_obj)
         _list_w_obj_referents(gcref, result)
     return space.newlist(result)
-get_referents.unwrap_spec = [ObjSpace, 'args_w']
 
 def get_referrers(space, args_w):
     """Return the list of objects that directly refer to any of objs."""
@@ -167,8 +166,8 @@
                         result_w[w_obj] = None
                 pending_w += referents_w
     return space.newlist(result_w.keys())
-get_referrers.unwrap_spec = [ObjSpace, 'args_w']
 
+ at unwrap_spec(fd=int)
 def _dump_rpy_heap(space, fd):
     try:
         ok = rgc.dump_rpy_heap(fd)
@@ -176,10 +175,8 @@
         raise wrap_oserror(space, e)
     if not ok:
         raise missing_operation(space)
-_dump_rpy_heap.unwrap_spec = [ObjSpace, int]
 
 def get_typeids_z(space):
     a = rgc.get_typeids_z()
     s = ''.join([a[i] for i in range(len(a))])
     return space.wrap(s)
-get_typeids_z.unwrap_spec = [ObjSpace]

diff --git a/pypy/rpython/lltypesystem/lltype.py b/pypy/rpython/lltypesystem/lltype.py
--- a/pypy/rpython/lltypesystem/lltype.py
+++ b/pypy/rpython/lltypesystem/lltype.py
@@ -13,6 +13,29 @@
 
 TLS = tlsobject()
 
+class WeakValueDictionary(weakref.WeakValueDictionary):
+    """A subclass of weakref.WeakValueDictionary
+    which resets the 'nested_hash_level' when keys are being deleted.
+    """
+    def __init__(self, *args, **kwargs):
+        weakref.WeakValueDictionary.__init__(self, *args, **kwargs)
+        remove_base = self._remove
+        def remove(*args):
+            if TLS is None: # Happens when the interpreter is shutting down
+                return remove_base(*args)
+            nested_hash_level = TLS.nested_hash_level
+            try:
+                # The 'remove' function is called when an object dies.  This
+                # can happen anywhere when they are reference cycles,
+                # especially when we are already computing another __hash__
+                # value.  It's not really a recursion in this case, so we
+                # reset the counter; otherwise the hash value may be be
+                # incorrect and the key won't be deleted.
+                TLS.nested_hash_level = 0
+                remove_base(*args)
+            finally:
+                TLS.nested_hash_level = nested_hash_level
+        self._remove = remove
 
 class _uninitialized(object):
     def __init__(self, TYPE):
@@ -397,7 +420,7 @@
     # behaves more or less like a Struct with fields item0, item1, ...
     # but also supports __getitem__(), __setitem__(), __len__().
 
-    _cache = weakref.WeakValueDictionary() # cache the length-1 FixedSizeArrays
+    _cache = WeakValueDictionary() # cache the length-1 FixedSizeArrays
     def __new__(cls, OF, length, **kwds):
         if length == 1 and not kwds:
             try:
@@ -620,7 +643,7 @@
 class Ptr(LowLevelType):
     __name__ = property(lambda self: '%sPtr' % self.TO.__name__)
 
-    _cache = weakref.WeakValueDictionary()  # cache the Ptrs
+    _cache = WeakValueDictionary()  # cache the Ptrs
     def __new__(cls, TO, use_cache=True):
         if not isinstance(TO, ContainerType):
             raise TypeError, ("can only point to a Container type, "

diff --git a/pypy/module/signal/interp_signal.py b/pypy/module/signal/interp_signal.py
--- a/pypy/module/signal/interp_signal.py
+++ b/pypy/module/signal/interp_signal.py
@@ -1,6 +1,5 @@
 from __future__ import with_statement
 from pypy.interpreter.error import OperationError, exception_from_errno
-from pypy.interpreter.baseobjspace import W_Root, ObjSpace
 from pypy.interpreter.executioncontext import AsyncAction, AbstractActionFlag
 from pypy.interpreter.executioncontext import PeriodicAsyncAction
 from pypy.interpreter.gateway import unwrap_spec
@@ -192,6 +191,7 @@
             self.fire_after_thread_switch()
 
 
+ at unwrap_spec(signum=int)
 def getsignal(space, signum):
     """
     getsignal(sig) -> action
@@ -207,18 +207,16 @@
     if signum in action.handlers_w:
         return action.handlers_w[signum]
     return space.wrap(SIG_DFL)
-getsignal.unwrap_spec = [ObjSpace, int]
 
 @jit.dont_look_inside
+ at unwrap_spec(timeout=int)
 def alarm(space, timeout):
     return space.wrap(c_alarm(timeout))
-alarm.unwrap_spec = [ObjSpace, int]
 
 @jit.dont_look_inside
 def pause(space):
     c_pause()
     return space.w_None
-pause.unwrap_spec = [ObjSpace]
 
 def check_signum(space, signum):
     if signum < 1 or signum >= NSIG:
@@ -226,6 +224,7 @@
                              space.wrap("signal number out of range"))
 
 @jit.dont_look_inside
+ at unwrap_spec(signum=int)
 def signal(space, signum, w_handler):
     """
     signal(sig, action) -> action
@@ -262,8 +261,8 @@
         pypysig_setflag(signum)
         action.handlers_w[signum] = w_handler
     return old_handler
-signal.unwrap_spec = [ObjSpace, int, W_Root]
 
+ at unwrap_spec(fd=int)
 def set_wakeup_fd(space, fd):
     """Sets the fd to be written to (with '\0') when a signal
     comes in.  Returns the old fd.  A library can use this to
@@ -280,14 +279,13 @@
                 space.wrap("set_wakeup_fd only works in main thread"))
     old_fd = pypysig_set_wakeup_fd(fd)
     return space.wrap(intmask(old_fd))
-set_wakeup_fd.unwrap_spec = [ObjSpace, int]
 
+ at unwrap_spec(signum=int, flag=int)
 def siginterrupt(space, signum, flag):
     check_signum(space, signum)
     if rffi.cast(lltype.Signed, c_siginterrupt(signum, flag)) < 0:
         errno = rposix.get_errno()
         raise OperationError(space.w_RuntimeError, space.wrap(errno))
-siginterrupt.unwrap_spec = [ObjSpace, int, int]
 
 
 #__________________________________________________________
@@ -310,7 +308,7 @@
     return space.getattr(mod, space.wrap("ItimerError"))
 
 @jit.dont_look_inside
- at unwrap_spec(ObjSpace, int, float, float)
+ at unwrap_spec(which=int, first=float, interval=float)
 def setitimer(space, which, first, interval=0):
     with lltype.scoped_alloc(itimervalP.TO, 1) as new:
 
@@ -327,7 +325,7 @@
             return itimer_retval(space, old[0])
 
 @jit.dont_look_inside
- at unwrap_spec(ObjSpace, int)
+ at unwrap_spec(which=int)
 def getitimer(space, which):
     with lltype.scoped_alloc(itimervalP.TO, 1) as old:
 

diff --git a/pypy/module/sys/state.py b/pypy/module/sys/state.py
--- a/pypy/module/sys/state.py
+++ b/pypy/module/sys/state.py
@@ -3,7 +3,7 @@
 """
 import pypy
 from pypy.interpreter.error import OperationError
-from pypy.interpreter.gateway import ObjSpace
+from pypy.interpreter.gateway import unwrap_spec
 
 import sys, os, stat, errno
 
@@ -64,6 +64,7 @@
     #
     return importlist
 
+ at unwrap_spec(srcdir=str)
 def pypy_initial_path(space, srcdir):
     try:
         path = getinitialpath(srcdir)
@@ -76,8 +77,6 @@
                                         space.wrap(srcdir))
         return space.newlist([space.wrap(p) for p in path])
 
-pypy_initial_path.unwrap_spec = [ObjSpace, str]
-
 def get(space):
     return space.fromcache(State)
 

diff --git a/pypy/module/math/_genmath.py b/pypy/module/math/_genmath.py
deleted file mode 100644
--- a/pypy/module/math/_genmath.py
+++ /dev/null
@@ -1,62 +0,0 @@
-# ONESHOT SCRIPT (probably can go away soon)
-# to generate the mixed module 'math' (see same directory) 
-import py
-import math
-import re
-import sys
-rex_arg = re.compile(".*\((.*)\).*")
-
-if __name__ == '__main__': 
-    print py.code.Source("""
-        import math 
-        from pypy.interpreter.gateway import ObjSpace
-
-    """)
-    names = []
-    for name, func in math.__dict__.items(): 
-        if not callable(func): 
-            continue
-        sig = func.__doc__.split('\n')[0].strip()
-        sig = sig.split('->')[0].strip()
-        m = rex_arg.match(sig) 
-        assert m
-        args = m.group(1)
-        args = ", ".join(args.split(','))
-        sig = sig.replace('(', '(space,')
-        sig = ", ".join(sig.split(','))
-        argc = len(args.split(','))
-        unwrap_spec = ['ObjSpace']
-        unwrap_spec += ['float'] * argc 
-        unwrap_spec = ", ".join(unwrap_spec)
-        doc = func.__doc__.replace('\n', '\n       ')
-        
-        print py.code.Source('''
-            def %(sig)s: 
-                """%(doc)s
-                """
-                return space.wrap(math.%(name)s(%(args)s))
-            %(name)s.unwrap_spec = [%(unwrap_spec)s]
-        ''' % locals())
-        names.append(name) 
-
-    print >>sys.stderr, py.code.Source("""
-        # Package initialisation
-        from pypy.interpreter.mixedmodule import MixedModule
-
-        class Module(MixedModule):
-            appleveldefs = {
-            }
-            interpleveldefs = {
-    """)
-        
-    for name in names: 
-        space = " " * (15-len(name))
-        print >>sys.stderr, (
-            "       %(name)r%(space)s: 'interp_math.%(name)s'," % locals())
-    print >>sys.stderr, py.code.Source("""
-        }
-    """) 
-            
-        
-        
-        


More information about the Pypy-commit mailing list