Author: Matti Picus <matti.pi...@gmail.com>
Branch: cpyext-pickle
Changeset: r84713:874feb6ee033
Date: 2016-05-26 22:22 +0300
http://bitbucket.org/pypy/pypy/changeset/874feb6ee033/

Log:    merge default into branch

diff too long, truncating to 2000 out of 2136 lines

diff --git a/lib_pypy/cffi/commontypes.py b/lib_pypy/cffi/commontypes.py
--- a/lib_pypy/cffi/commontypes.py
+++ b/lib_pypy/cffi/commontypes.py
@@ -35,8 +35,11 @@
                                "you call ffi.set_unicode()" % (commontype,))
         else:
             if commontype == cdecl:
-                raise api.FFIError("Unsupported type: %r.  Please file a bug "
-                                   "if you think it should be." % 
(commontype,))
+                raise api.FFIError(
+                    "Unsupported type: %r.  Please look at "
+        "http://cffi.readthedocs.io/en/latest/cdef.html#ffi-cdef-limitations "
+                    "and file an issue if you think this type should really "
+                    "be supported." % (commontype,))
             result, quals = parser.parse_type_and_quals(cdecl)   # recursive
 
         assert isinstance(result, model.BaseTypeByIdentity)
diff --git a/pypy/interpreter/astcompiler/test/test_ast.py 
b/pypy/interpreter/astcompiler/test/test_ast.py
--- a/pypy/interpreter/astcompiler/test/test_ast.py
+++ b/pypy/interpreter/astcompiler/test/test_ast.py
@@ -1,8 +1,8 @@
 from pypy.interpreter.astcompiler import ast
 class TestAstToObject:
     def test_types(self, space):
-        assert space.is_true(space.issubtype(
-                ast.get(space).w_Module, ast.get(space).w_mod))
+        assert space.issubtype_w(
+                ast.get(space).w_Module, ast.get(space).w_mod)
                                   
     def test_num(self, space):
         value = space.wrap(42)
diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -1215,7 +1215,7 @@
 
     def abstract_issubclass_w(self, w_cls1, w_cls2):
         # Equivalent to 'issubclass(cls1, cls2)'.
-        return self.is_true(self.issubtype(w_cls1, w_cls2))
+        return self.issubtype_w(w_cls1, w_cls2)
 
     def abstract_isinstance_w(self, w_obj, w_cls):
         # Equivalent to 'isinstance(obj, cls)'.
@@ -1237,16 +1237,16 @@
     def exception_is_valid_obj_as_class_w(self, w_obj):
         if not self.isinstance_w(w_obj, self.w_type):
             return False
-        return self.is_true(self.issubtype(w_obj, self.w_BaseException))
+        return self.issubtype_w(w_obj, self.w_BaseException)
 
     def exception_is_valid_class_w(self, w_cls):
-        return self.is_true(self.issubtype(w_cls, self.w_BaseException))
+        return self.issubtype_w(w_cls, self.w_BaseException)
 
     def exception_getclass(self, w_obj):
         return self.type(w_obj)
 
     def exception_issubclass_w(self, w_cls1, w_cls2):
-        return self.is_true(self.issubtype(w_cls1, w_cls2))
+        return self.issubtype_w(w_cls1, w_cls2)
 
     def new_exception_class(self, *args, **kwargs):
         "NOT_RPYTHON; convenience method to create excceptions in modules"
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
@@ -86,8 +86,8 @@
         'max'           : 'functional.max',
         'reversed'      : 'functional.reversed',
         'super'         : 'descriptor.W_Super',
-        'staticmethod'  : 'descriptor.StaticMethod',
-        'classmethod'   : 'descriptor.ClassMethod',
+        'staticmethod'  : 'pypy.interpreter.function.StaticMethod',
+        'classmethod'   : 'pypy.interpreter.function.ClassMethod',
         'property'      : 'descriptor.W_Property',
 
         'globals'       : 'interp_inspect.globals',
diff --git a/pypy/module/__builtin__/abstractinst.py 
b/pypy/module/__builtin__/abstractinst.py
--- a/pypy/module/__builtin__/abstractinst.py
+++ b/pypy/module/__builtin__/abstractinst.py
@@ -76,11 +76,10 @@
             w_pretendtype = space.getattr(w_obj, space.wrap('__class__'))
             if space.is_w(w_pretendtype, space.type(w_obj)):
                 return False     # common case: obj.__class__ is type(obj)
-            if allow_override:
-                w_result = space.issubtype_allow_override(w_pretendtype,
-                                                          w_klass_or_tuple)
-            else:
-                w_result = space.issubtype(w_pretendtype, w_klass_or_tuple)
+            if not allow_override:
+                return space.issubtype_w(w_pretendtype, w_klass_or_tuple)
+            w_result = space.issubtype_allow_override(w_pretendtype,
+                                                      w_klass_or_tuple)
         except OperationError as e:
             if e.async(space):
                 raise
@@ -137,11 +136,9 @@
 
     # -- case (type, type)
     try:
-        if allow_override:
-            w_result = space.issubtype_allow_override(w_derived,
-                                                      w_klass_or_tuple)
-        else:
-            w_result = space.issubtype(w_derived, w_klass_or_tuple)
+        if not allow_override:
+            return space.issubtype_w(w_derived, w_klass_or_tuple)
+        w_result = space.issubtype_allow_override(w_derived, w_klass_or_tuple)
     except OperationError as e:   # if one of the args was not a type, ignore 
it
         if not e.match(space, space.w_TypeError):
             raise       # propagate other errors
diff --git a/pypy/module/__builtin__/descriptor.py 
b/pypy/module/__builtin__/descriptor.py
--- a/pypy/module/__builtin__/descriptor.py
+++ b/pypy/module/__builtin__/descriptor.py
@@ -1,31 +1,39 @@
 from pypy.interpreter.baseobjspace import W_Root
 from pypy.interpreter.error import OperationError, oefmt
-from pypy.interpreter.function import StaticMethod, ClassMethod
-from pypy.interpreter.gateway import interp2app, unwrap_spec, WrappedDefault
-from pypy.interpreter.typedef import (TypeDef, interp_attrproperty_w,
-    generic_new_descr)
+from pypy.interpreter.gateway import WrappedDefault, interp2app, unwrap_spec
+from pypy.interpreter.typedef import (
+    TypeDef, generic_new_descr, interp_attrproperty_w)
 from pypy.objspace.descroperation import object_getattribute
 
 
 class W_Super(W_Root):
-    def __init__(self, space, w_starttype, w_objtype, w_self):
+
+    def __init__(self, space):
+        self.w_starttype = None
+        self.w_objtype = None
+        self.w_self = None
+
+    def descr_init(self, space, w_starttype, w_obj_or_type=None):
+        if space.is_none(w_obj_or_type):
+            w_type = None  # unbound super object
+            w_obj_or_type = space.w_None
+        else:
+            w_type = _super_check(space, w_starttype, w_obj_or_type)
         self.w_starttype = w_starttype
-        self.w_objtype = w_objtype
-        self.w_self = w_self
+        self.w_objtype = w_type
+        self.w_self = w_obj_or_type
 
     def get(self, space, w_obj, w_type=None):
-        w = space.wrap
         if self.w_self is None or space.is_w(w_obj, space.w_None):
-            return w(self)
+            return self
         else:
             # if type(self) is W_Super:
             #     XXX write a fast path for this common case
-            w_selftype = space.type(w(self))
+            w_selftype = space.type(self)
             return space.call_function(w_selftype, self.w_starttype, w_obj)
 
-    @unwrap_spec(name=str)
-    def getattribute(self, space, name):
-        w = space.wrap
+    def getattribute(self, space, w_name):
+        name = space.str_w(w_name)
         # only use a special logic for bound super objects and not for
         # getting the __class__ of the super object itself.
         if self.w_objtype is not None and name != '__class__':
@@ -45,44 +53,42 @@
                 return space.get_and_call_function(w_get, w_value,
                                                    w_obj, self.w_objtype)
         # fallback to object.__getattribute__()
-        return space.call_function(object_getattribute(space),
-                                   w(self), w(name))
+        return space.call_function(object_getattribute(space), self, w_name)
 
-def descr_new_super(space, w_subtype, w_starttype, w_obj_or_type=None):
-    if space.is_none(w_obj_or_type):
-        w_type = None  # unbound super object
-        w_obj_or_type = space.w_None
-    else:
-        w_objtype = space.type(w_obj_or_type)
-        if space.is_true(space.issubtype(w_objtype, space.w_type)) and \
-            space.is_true(space.issubtype(w_obj_or_type, w_starttype)):
-            w_type = w_obj_or_type # special case for class methods
-        elif space.is_true(space.issubtype(w_objtype, w_starttype)):
-            w_type = w_objtype # normal case
-        else:
-            try:
-                w_type = space.getattr(w_obj_or_type, space.wrap('__class__'))
-            except OperationError as o:
-                if not o.match(space, space.w_AttributeError):
-                    raise
-                w_type = w_objtype
-            if not space.is_true(space.issubtype(w_type, w_starttype)):
-                raise oefmt(space.w_TypeError,
-                            "super(type, obj): obj must be an instance or "
-                            "subtype of type")
-    # XXX the details of how allocate_instance() should be used are not
-    # really well defined
-    w_result = space.allocate_instance(W_Super, w_subtype)
-    W_Super.__init__(w_result, space, w_starttype, w_type, w_obj_or_type)
-    return w_result
+def _super_check(space, w_starttype, w_obj_or_type):
+    """Check that the super() call makes sense. Returns a type"""
+    w_objtype = space.type(w_obj_or_type)
+
+    if (space.issubtype_w(w_objtype, space.w_type) and
+        space.issubtype_w(w_obj_or_type, w_starttype)):
+        # special case for class methods
+        return w_obj_or_type
+
+    if space.issubtype_w(w_objtype, w_starttype):
+        # normal case
+        return w_objtype
+
+    try:
+        w_type = space.getattr(w_obj_or_type, space.wrap('__class__'))
+    except OperationError as e:
+        if not e.match(space, space.w_AttributeError):
+            raise
+        w_type = w_objtype
+
+    if space.issubtype_w(w_type, w_starttype):
+        return w_type
+    raise oefmt(space.w_TypeError,
+                "super(type, obj): obj must be an instance or subtype of type")
 
 W_Super.typedef = TypeDef(
     'super',
-    __new__          = interp2app(descr_new_super),
+    __new__          = generic_new_descr(W_Super),
+    __init__         = interp2app(W_Super.descr_init),
     __thisclass__    = interp_attrproperty_w("w_starttype", W_Super),
     __getattribute__ = interp2app(W_Super.getattribute),
     __get__          = interp2app(W_Super.get),
-    __doc__          =     """super(type) -> unbound super object
+    __doc__          =     """\
+super(type) -> unbound super object
 super(type, obj) -> bound super object; requires isinstance(obj, type)
 super(type, type2) -> bound super object; requires issubclass(type2, type)
 
@@ -100,10 +106,10 @@
     def __init__(self, space):
         pass
 
-    @unwrap_spec(w_fget = WrappedDefault(None),
-                 w_fset = WrappedDefault(None),
-                 w_fdel = WrappedDefault(None),
-                 w_doc = WrappedDefault(None))
+    @unwrap_spec(w_fget=WrappedDefault(None),
+                 w_fset=WrappedDefault(None),
+                 w_fdel=WrappedDefault(None),
+                 w_doc=WrappedDefault(None))
     def init(self, space, w_fget=None, w_fset=None, w_fdel=None, w_doc=None):
         self.w_fget = w_fget
         self.w_fset = w_fset
@@ -113,18 +119,17 @@
         # our __doc__ comes from the getter if we don't have an explicit one
         if (space.is_w(self.w_doc, space.w_None) and
             not space.is_w(self.w_fget, space.w_None)):
-            w_getter_doc = space.findattr(self.w_fget, space.wrap("__doc__"))
+            w_getter_doc = space.findattr(self.w_fget, space.wrap('__doc__'))
             if w_getter_doc is not None:
                 if type(self) is W_Property:
                     self.w_doc = w_getter_doc
                 else:
-                    space.setattr(space.wrap(self), space.wrap("__doc__"),
-                                  w_getter_doc)
+                    space.setattr(self, space.wrap('__doc__'), w_getter_doc)
                 self.getter_doc = True
 
     def get(self, space, w_obj, w_objtype=None):
         if space.is_w(w_obj, space.w_None):
-            return space.wrap(self)
+            return self
         if space.is_w(self.w_fget, space.w_None):
             raise oefmt(space.w_AttributeError, "unreadable attribute")
         return space.call_function(self.w_fget, w_obj)
@@ -162,11 +167,13 @@
         else:
             w_doc = self.w_doc
         w_type = self.getclass(space)
-        return space.call_function(w_type, w_getter, w_setter, w_deleter, 
w_doc)
+        return space.call_function(w_type, w_getter, w_setter, w_deleter,
+                                   w_doc)
 
 W_Property.typedef = TypeDef(
     'property',
-    __doc__ = '''property(fget=None, fset=None, fdel=None, doc=None) -> 
property attribute
+    __doc__ = '''\
+property(fget=None, fset=None, fdel=None, doc=None) -> property attribute
 
 fget is a function to be used for getting an attribute value, and likewise
 fset is a function for setting, and fdel a function for deleting, an
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
@@ -145,8 +145,17 @@
         else:
             compare = space.lt
             jitdriver = min_jitdriver
+        any_kwds = bool(args.keywords)
         args_w = args.arguments_w
         if len(args_w) > 1:
+            if unroll and len(args_w) == 2 and not any_kwds:
+                # a fast path for the common case, useful for interpreted
+                # mode and to reduce the length of the jit trace
+                w0, w1 = args_w
+                if space.is_true(compare(w1, w0)):
+                    return w1
+                else:
+                    return w0
             w_sequence = space.newtuple(args_w)
         elif len(args_w):
             w_sequence = args_w[0]
@@ -155,8 +164,8 @@
                         "%s() expects at least one argument",
                         implementation_of)
         w_key = None
-        kwds = args.keywords
-        if kwds:
+        if any_kwds:
+            kwds = args.keywords
             if kwds[0] == "key" and len(kwds) == 1:
                 w_key = args.keywords_w[0]
             else:
diff --git a/pypy/module/__builtin__/test/test_functional.py 
b/pypy/module/__builtin__/test/test_functional.py
--- a/pypy/module/__builtin__/test/test_functional.py
+++ b/pypy/module/__builtin__/test/test_functional.py
@@ -296,6 +296,11 @@
         assert min([1, 2, 3]) == 1
         raises(TypeError, min, 1, 2, bar=2)
         raises(TypeError, min, 1, 2, key=lambda x: x, bar=2)
+        assert type(min(1, 1.0)) is int
+        assert type(min(1.0, 1)) is float
+        assert type(min(1, 1.0, 1L)) is int
+        assert type(min(1.0, 1L, 1)) is float
+        assert type(min(1L, 1, 1.0)) is long
 
     def test_max(self):
         assert max(1, 2) == 2
@@ -303,3 +308,8 @@
         assert max([1, 2, 3]) == 3
         raises(TypeError, max, 1, 2, bar=2)
         raises(TypeError, max, 1, 2, key=lambda x: x, bar=2)
+        assert type(max(1, 1.0)) is int
+        assert type(max(1.0, 1)) is float
+        assert type(max(1, 1.0, 1L)) is int
+        assert type(max(1.0, 1L, 1)) is float
+        assert type(max(1L, 1, 1.0)) is long
diff --git a/pypy/module/_cffi_backend/ctypeobj.py 
b/pypy/module/_cffi_backend/ctypeobj.py
--- a/pypy/module/_cffi_backend/ctypeobj.py
+++ b/pypy/module/_cffi_backend/ctypeobj.py
@@ -233,10 +233,9 @@
     # __________ app-level attributes __________
     def dir(self):
         space = self.space
-        w_self = space.wrap(self)
         lst = [space.wrap(name)
                   for name in _name_of_attributes
-                  if space.findattr(w_self, space.wrap(name)) is not None]
+                  if space.findattr(self, space.wrap(name)) is not None]
         return space.newlist(lst)
 
     def _fget(self, attrchar):
diff --git a/pypy/module/_cffi_backend/lib_obj.py 
b/pypy/module/_cffi_backend/lib_obj.py
--- a/pypy/module/_cffi_backend/lib_obj.py
+++ b/pypy/module/_cffi_backend/lib_obj.py
@@ -196,9 +196,13 @@
                 if is_getattr and attr == '__dict__':
                     return self.full_dict_copy()
                 if is_getattr and attr == '__class__':
-                    return self.space.type(self)
+                    # used to be space.type(self).  But HAAAAAACK!
+                    # That makes help() behave correctly.  I couldn't
+                    # find a more reasonable way.  Urgh.
+                    from pypy.interpreter.module import Module
+                    return self.space.gettypeobject(Module.typedef)
                 if is_getattr and attr == '__name__':
-                    return self.descr_repr()
+                    return self.space.wrap("%s.lib" % self.libname)
                 raise oefmt(self.space.w_AttributeError,
                             "cffi library '%s' has no function, constant "
                             "or global variable named '%s'",
diff --git a/pypy/module/_cffi_backend/test/test_recompiler.py 
b/pypy/module/_cffi_backend/test/test_recompiler.py
--- a/pypy/module/_cffi_backend/test/test_recompiler.py
+++ b/pypy/module/_cffi_backend/test/test_recompiler.py
@@ -1039,8 +1039,8 @@
         assert MYFOO == 42
         assert hasattr(lib, '__dict__')
         assert lib.__all__ == ['MYFOO', 'mybar']   # but not 'myvar'
-        assert lib.__name__ == repr(lib)
-        assert lib.__class__ is type(lib)
+        assert lib.__name__ == '_CFFI_test_import_from_lib.lib'
+        assert lib.__class__ is type(sys)   # !! hack for help()
 
     def test_macro_var_callback(self):
         ffi, lib = self.prepare(
diff --git a/pypy/module/_collections/interp_deque.py 
b/pypy/module/_collections/interp_deque.py
--- a/pypy/module/_collections/interp_deque.py
+++ b/pypy/module/_collections/interp_deque.py
@@ -389,20 +389,18 @@
     def copy(self):
         "Return a shallow copy of a deque."
         space = self.space
-        w_self = space.wrap(self)
         if self.maxlen == sys.maxint:
-            return space.call_function(space.type(w_self), w_self)
+            return space.call_function(space.type(self), self)
         else:
-            return space.call_function(space.type(w_self), w_self,
+            return space.call_function(space.type(self), self,
                                        space.wrap(self.maxlen))
 
     def reduce(self):
         "Return state information for pickling."
         space = self.space
-        w_self = space.wrap(self)
-        w_type = space.type(w_self)
-        w_dict = space.findattr(w_self, space.wrap('__dict__'))
-        w_list = space.call_function(space.w_list, w_self)
+        w_type = space.type(self)
+        w_dict = space.findattr(self, space.wrap('__dict__'))
+        w_list = space.call_function(space.w_list, self)
         if w_dict is None:
             if self.maxlen == sys.maxint:
                 result = [
diff --git a/pypy/module/_weakref/interp__weakref.py 
b/pypy/module/_weakref/interp__weakref.py
--- a/pypy/module/_weakref/interp__weakref.py
+++ b/pypy/module/_weakref/interp__weakref.py
@@ -156,12 +156,12 @@
 
 
 class W_WeakrefBase(W_Root):
-    def __init__(w_self, space, w_obj, w_callable):
+    def __init__(self, space, w_obj, w_callable):
         assert w_callable is not space.w_None    # should be really None
-        w_self.space = space
+        self.space = space
         assert w_obj is not None
-        w_self.w_obj_weak = weakref.ref(w_obj)
-        w_self.w_callable = w_callable
+        self.w_obj_weak = weakref.ref(w_obj)
+        self.w_callable = w_callable
 
     @jit.dont_look_inside
     def dereference(self):
@@ -171,8 +171,8 @@
     def clear(self):
         self.w_obj_weak = dead_ref
 
-    def activate_callback(w_self):
-        w_self.space.call_function(w_self.w_callable, w_self)
+    def activate_callback(self):
+        self.space.call_function(self.w_callable, self)
 
     def descr__repr__(self, space):
         w_obj = self.dereference()
@@ -189,9 +189,9 @@
 
 
 class W_Weakref(W_WeakrefBase):
-    def __init__(w_self, space, w_obj, w_callable):
-        W_WeakrefBase.__init__(w_self, space, w_obj, w_callable)
-        w_self.w_hash = None
+    def __init__(self, space, w_obj, w_callable):
+        W_WeakrefBase.__init__(self, space, w_obj, w_callable)
+        self.w_hash = None
 
     def descr__init__weakref(self, space, w_obj, w_callable=None,
                              __args__=None):
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
@@ -706,7 +706,7 @@
         w_obj_type = space.type(w_obj)
         w_type = get_w_type(space)
         return (space.is_w(w_obj_type, w_type) or
-                space.is_true(space.issubtype(w_obj_type, w_type)))
+                space.issubtype_w(w_obj_type, w_type))
     def check_exact(space, w_obj):
         "Implements the Py_Xxx_CheckExact function"
         w_obj_type = space.type(w_obj)
diff --git a/pypy/module/cpyext/cdatetime.py b/pypy/module/cpyext/cdatetime.py
--- a/pypy/module/cpyext/cdatetime.py
+++ b/pypy/module/cpyext/cdatetime.py
@@ -1,4 +1,5 @@
 from rpython.rtyper.lltypesystem import rffi, lltype
+from rpython.rtyper.annlowlevel import llhelper
 from pypy.module.cpyext.pyobject import PyObject, make_ref
 from pypy.module.cpyext.api import (cpython_api, CANNOT_FAIL, cpython_struct,
     PyObjectFields)
@@ -16,6 +17,23 @@
      ('TimeType', PyTypeObjectPtr),
      ('DeltaType', PyTypeObjectPtr),
      ('TZInfoType', PyTypeObjectPtr),
+
+     ('Date_FromDate', lltype.Ptr(lltype.FuncType(
+         [rffi.INT_real, rffi.INT_real, rffi.INT_real, PyTypeObjectPtr],
+         PyObject))),
+     ('Time_FromTime', lltype.Ptr(lltype.FuncType(
+         [rffi.INT_real, rffi.INT_real, rffi.INT_real, rffi.INT_real,
+          PyObject, PyTypeObjectPtr],
+         PyObject))),
+     ('DateTime_FromDateAndTime', lltype.Ptr(lltype.FuncType(
+         [rffi.INT_real, rffi.INT_real, rffi.INT_real,
+          rffi.INT_real, rffi.INT_real, rffi.INT_real, rffi.INT_real,
+          PyObject, PyTypeObjectPtr],
+         PyObject))),
+     ('Delta_FromDelta', lltype.Ptr(lltype.FuncType(
+         [rffi.INT_real, rffi.INT_real, rffi.INT_real, rffi.INT_real,
+          PyTypeObjectPtr],
+         PyObject))),
      ))
 
 @cpython_api([], lltype.Ptr(PyDateTime_CAPI))
@@ -45,6 +63,19 @@
     datetimeAPI.c_TZInfoType = rffi.cast(
         PyTypeObjectPtr, make_ref(space, w_type))
 
+    datetimeAPI.c_Date_FromDate = llhelper(
+        _PyDate_FromDate.api_func.functype,
+        _PyDate_FromDate.api_func.get_wrapper(space))
+    datetimeAPI.c_Time_FromTime = llhelper(
+        _PyTime_FromTime.api_func.functype,
+        _PyTime_FromTime.api_func.get_wrapper(space))
+    datetimeAPI.c_DateTime_FromDateAndTime = llhelper(
+        _PyDateTime_FromDateAndTime.api_func.functype,
+        _PyDateTime_FromDateAndTime.api_func.get_wrapper(space))
+    datetimeAPI.c_Delta_FromDelta = llhelper(
+        _PyDelta_FromDelta.api_func.functype,
+        _PyDelta_FromDelta.api_func.get_wrapper(space))
+
     return datetimeAPI
 
 PyDateTime_DateStruct = lltype.ForwardReference()
@@ -94,36 +125,40 @@
 make_check_function("PyDelta_Check", "timedelta")
 make_check_function("PyTZInfo_Check", "tzinfo")
 
-# Constructors
+# Constructors. They are better used as macros.
 
-@cpython_api([rffi.INT_real, rffi.INT_real, rffi.INT_real], PyObject)
-def PyDate_FromDate(space, year, month, day):
+@cpython_api([rffi.INT_real, rffi.INT_real, rffi.INT_real, PyTypeObjectPtr],
+             PyObject)
+def _PyDate_FromDate(space, year, month, day, w_type):
     """Return a datetime.date object with the specified year, month and day.
     """
     year = rffi.cast(lltype.Signed, year)
     month = rffi.cast(lltype.Signed, month)
     day = rffi.cast(lltype.Signed, day)
-    w_datetime = PyImport_Import(space, space.wrap("datetime"))
-    return space.call_method(
-        w_datetime, "date",
+    return space.call_function(
+        w_type,
         space.wrap(year), space.wrap(month), space.wrap(day))
 
-@cpython_api([rffi.INT_real, rffi.INT_real, rffi.INT_real, rffi.INT_real], 
PyObject)
-def PyTime_FromTime(space, hour, minute, second, usecond):
+@cpython_api([rffi.INT_real, rffi.INT_real, rffi.INT_real, rffi.INT_real,
+              PyObject, PyTypeObjectPtr], PyObject)
+def _PyTime_FromTime(space, hour, minute, second, usecond, w_tzinfo, w_type):
     """Return a ``datetime.time`` object with the specified hour, minute, 
second and
     microsecond."""
     hour = rffi.cast(lltype.Signed, hour)
     minute = rffi.cast(lltype.Signed, minute)
     second = rffi.cast(lltype.Signed, second)
     usecond = rffi.cast(lltype.Signed, usecond)
-    w_datetime = PyImport_Import(space, space.wrap("datetime"))
-    return space.call_method(
-        w_datetime, "time",
+    return space.call_function(
+        w_type,
         space.wrap(hour), space.wrap(minute), space.wrap(second),
-        space.wrap(usecond))
+        space.wrap(usecond), w_tzinfo)
 
-@cpython_api([rffi.INT_real, rffi.INT_real, rffi.INT_real, rffi.INT_real, 
rffi.INT_real, rffi.INT_real, rffi.INT_real], PyObject)
-def PyDateTime_FromDateAndTime(space, year, month, day, hour, minute, second, 
usecond):
+@cpython_api([rffi.INT_real, rffi.INT_real, rffi.INT_real,
+              rffi.INT_real, rffi.INT_real, rffi.INT_real, rffi.INT_real,
+              PyObject, PyTypeObjectPtr], PyObject)
+def _PyDateTime_FromDateAndTime(space, year, month, day,
+                                hour, minute, second, usecond,
+                                w_tzinfo, w_type):
     """Return a datetime.datetime object with the specified year, month, day, 
hour,
     minute, second and microsecond.
     """
@@ -134,12 +169,11 @@
     minute = rffi.cast(lltype.Signed, minute)
     second = rffi.cast(lltype.Signed, second)
     usecond = rffi.cast(lltype.Signed, usecond)
-    w_datetime = PyImport_Import(space, space.wrap("datetime"))
-    return space.call_method(
-        w_datetime, "datetime",
+    return space.call_function(
+        w_type,
         space.wrap(year), space.wrap(month), space.wrap(day),
         space.wrap(hour), space.wrap(minute), space.wrap(second),
-        space.wrap(usecond))
+        space.wrap(usecond), w_tzinfo)
 
 @cpython_api([PyObject], PyObject)
 def PyDateTime_FromTimestamp(space, w_args):
@@ -161,8 +195,10 @@
     w_method = space.getattr(w_type, space.wrap("fromtimestamp"))
     return space.call(w_method, w_args)
 
-@cpython_api([rffi.INT_real, rffi.INT_real, rffi.INT_real], PyObject)
-def PyDelta_FromDSU(space, days, seconds, useconds):
+@cpython_api([rffi.INT_real, rffi.INT_real, rffi.INT_real, rffi.INT_real,
+              PyTypeObjectPtr],
+             PyObject)
+def _PyDelta_FromDelta(space, days, seconds, useconds, normalize, w_type):
     """Return a datetime.timedelta object representing the given number of 
days,
     seconds and microseconds.  Normalization is performed so that the resulting
     number of microseconds and seconds lie in the ranges documented for
@@ -171,9 +207,8 @@
     days = rffi.cast(lltype.Signed, days)
     seconds = rffi.cast(lltype.Signed, seconds)
     useconds = rffi.cast(lltype.Signed, useconds)
-    w_datetime = PyImport_Import(space, space.wrap("datetime"))
-    return space.call_method(
-        w_datetime, "timedelta",
+    return space.call_function(
+        w_type,
         space.wrap(days), space.wrap(seconds), space.wrap(useconds))
 
 # Accessors
diff --git a/pypy/module/cpyext/include/datetime.h 
b/pypy/module/cpyext/include/datetime.h
--- a/pypy/module/cpyext/include/datetime.h
+++ b/pypy/module/cpyext/include/datetime.h
@@ -12,6 +12,13 @@
     PyTypeObject *TimeType;
     PyTypeObject *DeltaType;
     PyTypeObject *TZInfoType;
+
+    /* constructors */
+    PyObject *(*Date_FromDate)(int, int, int, PyTypeObject*);
+    PyObject *(*DateTime_FromDateAndTime)(int, int, int, int, int, int, int,
+        PyObject*, PyTypeObject*);
+    PyObject *(*Time_FromTime)(int, int, int, int, PyObject*, PyTypeObject*);
+    PyObject *(*Delta_FromDelta)(int, int, int, int, PyTypeObject*);
 } PyDateTime_CAPI;
 
 PyAPI_DATA(PyDateTime_CAPI*) PyDateTimeAPI;
@@ -41,6 +48,22 @@
     PyObject_HEAD
 } PyDateTime_TZInfo;
 
+/* Macros for accessing constructors in a simplified fashion. */
+#define PyDate_FromDate(year, month, day) \
+    PyDateTimeAPI->Date_FromDate(year, month, day, PyDateTimeAPI->DateType)
+
+#define PyDateTime_FromDateAndTime(year, month, day, hour, min, sec, usec) \
+    PyDateTimeAPI->DateTime_FromDateAndTime(year, month, day, hour, \
+        min, sec, usec, Py_None, PyDateTimeAPI->DateTimeType)
+
+#define PyTime_FromTime(hour, minute, second, usecond) \
+    PyDateTimeAPI->Time_FromTime(hour, minute, second, usecond, \
+        Py_None, PyDateTimeAPI->TimeType)
+
+#define PyDelta_FromDSU(days, seconds, useconds) \
+    PyDateTimeAPI->Delta_FromDelta(days, seconds, useconds, 1, \
+        PyDateTimeAPI->DeltaType)
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/pypy/module/cpyext/modsupport.py b/pypy/module/cpyext/modsupport.py
--- a/pypy/module/cpyext/modsupport.py
+++ b/pypy/module/cpyext/modsupport.py
@@ -113,7 +113,7 @@
     w_type = space.gettypeobject(Module.typedef)
     w_obj_type = space.type(w_obj)
     return int(space.is_w(w_type, w_obj_type) or
-               space.is_true(space.issubtype(w_obj_type, w_type)))
+               space.issubtype_w(w_obj_type, w_type))
 
 @cpython_api([PyObject], PyObject, result_borrowed=True)
 def PyModule_GetDict(space, w_mod):
diff --git a/pypy/module/cpyext/ndarrayobject.py 
b/pypy/module/cpyext/ndarrayobject.py
--- a/pypy/module/cpyext/ndarrayobject.py
+++ b/pypy/module/cpyext/ndarrayobject.py
@@ -35,7 +35,7 @@
     w_obj_type = space.type(w_obj)
     w_type = space.gettypeobject(W_NDimArray.typedef)
     return (space.is_w(w_obj_type, w_type) or
-            space.is_true(space.issubtype(w_obj_type, w_type)))
+            space.issubtype_w(w_obj_type, w_type))
 
 @cpython_api([PyObject], rffi.INT_real, error=CANNOT_FAIL, header=HEADER)
 def _PyArray_CheckExact(space, w_obj):
diff --git a/pypy/module/cpyext/slotdefs.py b/pypy/module/cpyext/slotdefs.py
--- a/pypy/module/cpyext/slotdefs.py
+++ b/pypy/module/cpyext/slotdefs.py
@@ -78,8 +78,7 @@
     args_w = space.fixedview(w_args)
     ref = make_ref(space, w_self)
     if (not ref.c_ob_type.c_tp_flags & Py_TPFLAGS_CHECKTYPES and
-        not space.is_true(space.issubtype(space.type(args_w[0]),
-                                         space.type(w_self)))):
+        not space.issubtype_w(space.type(args_w[0]), space.type(w_self))):
         return space.w_NotImplemented
     Py_DecRef(space, ref)
     return generic_cpy_call(space, func_binary, w_self, args_w[0])
@@ -90,8 +89,7 @@
     args_w = space.fixedview(w_args)
     ref = make_ref(space, w_self)
     if (not ref.c_ob_type.c_tp_flags & Py_TPFLAGS_CHECKTYPES and
-        not space.is_true(space.issubtype(space.type(args_w[0]),
-                                         space.type(w_self)))):
+        not space.issubtype_w(space.type(args_w[0]), space.type(w_self))):
         return space.w_NotImplemented
     Py_DecRef(space, ref)
     return generic_cpy_call(space, func_binary, args_w[0], w_self)
@@ -113,8 +111,7 @@
     args_w = space.fixedview(w_args)
     ref = make_ref(space, w_self)
     if (not ref.c_ob_type.c_tp_flags & Py_TPFLAGS_CHECKTYPES and
-        not space.is_true(space.issubtype(space.type(args_w[0]),
-                                         space.type(w_self)))):
+        not space.issubtype_w(space.type(args_w[0]), space.type(w_self))):
         return space.w_NotImplemented
     Py_DecRef(space, ref)
     arg3 = space.w_None
@@ -346,8 +343,7 @@
     check_num_args(space, w_args, 1)
     w_other, = space.fixedview(w_args)
 
-    if not space.is_true(space.issubtype(space.type(w_self),
-                                         space.type(w_other))):
+    if not space.issubtype_w(space.type(w_self), space.type(w_other)):
         raise oefmt(space.w_TypeError,
                     "%T.__cmp__(x,y) requires y to be a '%T', not a '%T'",
                     w_self, w_self, w_other)
diff --git a/pypy/module/cpyext/test/test_datetime.py 
b/pypy/module/cpyext/test/test_datetime.py
--- a/pypy/module/cpyext/test/test_datetime.py
+++ b/pypy/module/cpyext/test/test_datetime.py
@@ -4,7 +4,8 @@
 
 class TestDatetime(BaseApiTest):
     def test_date(self, space, api):
-        w_date = api.PyDate_FromDate(2010, 06, 03)
+        date_api = api._PyDateTime_Import()
+        w_date = api._PyDate_FromDate(2010, 06, 03, date_api.c_DateType)
         assert space.unwrap(space.str(w_date)) == '2010-06-03'
 
         assert api.PyDate_Check(w_date)
@@ -15,7 +16,9 @@
         assert api.PyDateTime_GET_DAY(w_date) == 3
 
     def test_time(self, space, api):
-        w_time = api.PyTime_FromTime(23, 15, 40, 123456)
+        date_api = api._PyDateTime_Import()
+        w_time = api._PyTime_FromTime(23, 15, 40, 123456,
+                                      space.w_None, date_api.c_TimeType)
         assert space.unwrap(space.str(w_time)) == '23:15:40.123456'
 
         assert api.PyTime_Check(w_time)
@@ -27,8 +30,10 @@
         assert api.PyDateTime_TIME_GET_MICROSECOND(w_time) == 123456
 
     def test_datetime(self, space, api):
-        w_date = api.PyDateTime_FromDateAndTime(
-            2010, 06, 03, 23, 15, 40, 123456)
+        date_api = api._PyDateTime_Import()
+        w_date = api._PyDateTime_FromDateAndTime(
+            2010, 06, 03, 23, 15, 40, 123456,
+            space.w_None, date_api.c_DateTimeType)
         assert space.unwrap(space.str(w_date)) == '2010-06-03 23:15:40.123456'
 
         assert api.PyDateTime_Check(w_date)
@@ -45,6 +50,7 @@
         assert api.PyDateTime_DATE_GET_MICROSECOND(w_date) == 123456
 
     def test_delta(self, space, api):
+        date_api = api._PyDateTime_Import()
         w_delta = space.appexec(
             [space.wrap(3), space.wrap(15)], """(days, seconds):
             from datetime import timedelta
@@ -53,7 +59,7 @@
         assert api.PyDelta_Check(w_delta)
         assert api.PyDelta_CheckExact(w_delta)
 
-        w_delta = api.PyDelta_FromDSU(10, 20, 30)
+        w_delta = api._PyDelta_FromDelta(10, 20, 30, True, 
date_api.c_DeltaType)
         assert api.PyDelta_Check(w_delta)
         assert api.PyDelta_CheckExact(w_delta)
 
@@ -118,6 +124,31 @@
                                       datetime.tzinfo)
         module.clear_types()
 
+    def test_constructors(self):
+        module = self.import_extension('foo', [
+            ("new_date", "METH_NOARGS",
+             """ PyDateTime_IMPORT;
+                 return PyDateTimeAPI->Date_FromDate(
+                    2000, 6, 6, PyDateTimeAPI->DateType);
+             """),
+            ("new_time", "METH_NOARGS",
+             """ PyDateTime_IMPORT;
+                 return PyDateTimeAPI->Time_FromTime(
+                    6, 6, 6, 6, Py_None, PyDateTimeAPI->TimeType);
+             """),
+            ("new_datetime", "METH_NOARGS",
+             """ PyDateTime_IMPORT;
+                 return PyDateTimeAPI->DateTime_FromDateAndTime(
+                    2000, 6, 6, 6, 6, 6, 6, Py_None,
+                    PyDateTimeAPI->DateTimeType);
+             """),
+        ])
+        import datetime
+        assert module.new_date() == datetime.date(2000, 6, 6)
+        assert module.new_time() == datetime.time(6, 6, 6, 6)
+        assert module.new_datetime() == datetime.datetime(
+            2000, 6, 6, 6, 6, 6, 6)
+
     def test_macros(self):
         module = self.import_extension('foo', [
             ("test_date_macros", "METH_NOARGS",
@@ -222,3 +253,9 @@
                  return obj;
              """),
             ])
+        import datetime
+        assert module.test_date_macros() == datetime.date(2000, 6, 6)
+        assert module.test_datetime_macros() == datetime.datetime(
+            2000, 6, 6, 6, 6, 6, 6)
+        assert module.test_time_macros() == datetime.time(6, 6, 6, 6)
+        assert module.test_delta_macros() == datetime.timedelta(6, 6, 6)
diff --git a/pypy/module/cpyext/test/test_typeobject.py 
b/pypy/module/cpyext/test/test_typeobject.py
--- a/pypy/module/cpyext/test/test_typeobject.py
+++ b/pypy/module/cpyext/test/test_typeobject.py
@@ -744,7 +744,7 @@
                 int intval;
                 PyObject *name;
 
-                if (!PyArg_ParseTuple(args, "l", &intval))
+                if (!PyArg_ParseTuple(args, "i", &intval))
                     return NULL;
 
                 IntLike_Type.tp_flags |= Py_TPFLAGS_DEFAULT;
diff --git a/pypy/module/cpyext/tupleobject.py 
b/pypy/module/cpyext/tupleobject.py
--- a/pypy/module/cpyext/tupleobject.py
+++ b/pypy/module/cpyext/tupleobject.py
@@ -47,7 +47,7 @@
 def tuple_check_ref(space, ref):
     w_type = from_ref(space, rffi.cast(PyObject, ref.c_ob_type))
     return (w_type is space.w_tuple or
-            space.is_true(space.issubtype(w_type, space.w_tuple)))
+            space.issubtype_w(w_type, space.w_tuple))
 
 def new_empty_tuple(space, length):
     """
diff --git a/pypy/module/cpyext/unicodeobject.py 
b/pypy/module/cpyext/unicodeobject.py
--- a/pypy/module/cpyext/unicodeobject.py
+++ b/pypy/module/cpyext/unicodeobject.py
@@ -225,7 +225,7 @@
     buffer, NULL if unicode is not a Unicode object."""
     # Don't use PyUnicode_Check, it will realize the object :-(
     w_type = from_ref(space, rffi.cast(PyObject, ref.c_ob_type))
-    if not space.is_true(space.issubtype(w_type, space.w_unicode)):
+    if not space.issubtype_w(w_type, space.w_unicode):
         raise oefmt(space.w_TypeError, "expected unicode object")
     return PyUnicode_AS_UNICODE(space, rffi.cast(rffi.VOIDP, ref))
 
diff --git a/pypy/module/micronumpy/boxes.py b/pypy/module/micronumpy/boxes.py
--- a/pypy/module/micronumpy/boxes.py
+++ b/pypy/module/micronumpy/boxes.py
@@ -355,8 +355,8 @@
     def descr_view(self, space, w_dtype):
         from pypy.module.micronumpy.descriptor import W_Dtype
         try:
-            subclass = space.is_true(space.issubtype(
-                w_dtype, space.gettypefor(W_NDimArray)))
+            subclass = space.issubtype_w(w_dtype,
+                                         space.gettypefor(W_NDimArray))
         except OperationError as e:
             if e.match(space, space.w_TypeError):
                 subclass = False
diff --git a/pypy/module/micronumpy/compile.py 
b/pypy/module/micronumpy/compile.py
--- a/pypy/module/micronumpy/compile.py
+++ b/pypy/module/micronumpy/compile.py
@@ -124,6 +124,9 @@
             return w_obj.getdictvalue(self, w_attr)
         return None
 
+    def issubtype_w(self, w_sub, w_type):
+        return w_sub is w_type
+
     def isinstance_w(self, w_obj, w_tp):
         try:
             return w_obj.tp == w_tp
diff --git a/pypy/module/micronumpy/descriptor.py 
b/pypy/module/micronumpy/descriptor.py
--- a/pypy/module/micronumpy/descriptor.py
+++ b/pypy/module/micronumpy/descriptor.py
@@ -1082,7 +1082,7 @@
         if w_dtype is dtype.w_box_type:
             return _set_metadata_and_copy(space, w_metadata, dtype, copy)
         if space.isinstance_w(w_dtype, space.w_type) and \
-           space.is_true(space.issubtype(w_dtype, dtype.w_box_type)):
+           space.issubtype_w(w_dtype, dtype.w_box_type):
             return _set_metadata_and_copy( space, w_metadata,
                             W_Dtype(dtype.itemtype, w_dtype, elsize=0), copy)
     if space.isinstance_w(w_dtype, space.w_type):
diff --git a/pypy/module/micronumpy/ndarray.py 
b/pypy/module/micronumpy/ndarray.py
--- a/pypy/module/micronumpy/ndarray.py
+++ b/pypy/module/micronumpy/ndarray.py
@@ -977,8 +977,7 @@
     def descr_view(self, space, w_dtype=None, w_type=None):
         if not w_type and w_dtype:
             try:
-                if space.is_true(space.issubtype(
-                        w_dtype, space.gettypefor(W_NDimArray))):
+                if space.issubtype_w(w_dtype, space.gettypefor(W_NDimArray)):
                     w_type = w_dtype
                     w_dtype = None
             except OperationError as e:
diff --git a/pypy/module/micronumpy/ufuncs.py b/pypy/module/micronumpy/ufuncs.py
--- a/pypy/module/micronumpy/ufuncs.py
+++ b/pypy/module/micronumpy/ufuncs.py
@@ -66,10 +66,10 @@
     lhs_for_subtype = w_lhs
     rhs_for_subtype = w_rhs
     #it may be something like a FlatIter, which is not an ndarray
-    if not space.is_true(space.issubtype(lhs_type, w_ndarray)):
+    if not space.issubtype_w(lhs_type, w_ndarray):
         lhs_type = space.type(w_lhs.base)
         lhs_for_subtype = w_lhs.base
-    if not space.is_true(space.issubtype(rhs_type, w_ndarray)):
+    if not space.issubtype_w(rhs_type, w_ndarray):
         rhs_type = space.type(w_rhs.base)
         rhs_for_subtype = w_rhs.base
 
diff --git a/pypy/module/posix/app_posix.py b/pypy/module/posix/app_posix.py
--- a/pypy/module/posix/app_posix.py
+++ b/pypy/module/posix/app_posix.py
@@ -53,8 +53,6 @@
         st_flags = structseqfield(23, "user defined flags for file")
 
     def __init__(self, *args, **kw):
-        super(stat_result, self).__init__(*args, **kw)
-
         # If we have been initialized from a tuple,
         # st_?time might be set to None. Initialize it
         # from the int slots.
diff --git a/pypy/module/test_lib_pypy/cffi_tests/cffi1/test_recompiler.py 
b/pypy/module/test_lib_pypy/cffi_tests/cffi1/test_recompiler.py
--- a/pypy/module/test_lib_pypy/cffi_tests/cffi1/test_recompiler.py
+++ b/pypy/module/test_lib_pypy/cffi_tests/cffi1/test_recompiler.py
@@ -1168,8 +1168,8 @@
     assert MYFOO == 42
     assert hasattr(lib, '__dict__')
     assert lib.__all__ == ['MYFOO', 'mybar']   # but not 'myvar'
-    assert lib.__name__ == repr(lib)
-    assert lib.__class__ is type(lib)
+    assert lib.__name__ == '_CFFI_test_import_from_lib.lib'
+    assert lib.__class__ is type(sys)   # !! hack for help()
 
 def test_macro_var_callback():
     ffi = FFI()
diff --git a/pypy/module/thread/os_local.py b/pypy/module/thread/os_local.py
--- a/pypy/module/thread/os_local.py
+++ b/pypy/module/thread/os_local.py
@@ -50,10 +50,9 @@
         self.dicts[ec] = w_dict
         # call __init__
         try:
-            w_self = space.wrap(self)
-            w_type = space.type(w_self)
+            w_type = space.type(self)
             w_init = space.getattr(w_type, space.wrap("__init__"))
-            space.call_obj_args(w_init, w_self, self.initargs)
+            space.call_obj_args(w_init, self, self.initargs)
         except:
             # failed, forget w_dict and propagate the exception
             del self.dicts[ec]
diff --git a/pypy/objspace/descroperation.py b/pypy/objspace/descroperation.py
--- a/pypy/objspace/descroperation.py
+++ b/pypy/objspace/descroperation.py
@@ -359,7 +359,7 @@
             w_right_src, w_right_impl = space.lookup_in_type_where(w_typ2, 
'__rpow__')
             # sse binop_impl
             if (w_left_src is not w_right_src
-                and space.is_true(space.issubtype(w_typ2, w_typ1))):
+                and space.issubtype_w(w_typ2, w_typ1)):
                 if (w_left_src and w_right_src and
                     not space.abstract_issubclass_w(w_left_src, w_right_src) 
and
                     not space.abstract_issubclass_w(w_typ1, w_right_src)):
@@ -475,7 +475,7 @@
         else:
             w_right_src, w_right_impl = space.lookup_in_type_where(w_typ2, 
'__coerce__')
             if (w_left_src is not w_right_src
-                and space.is_true(space.issubtype(w_typ2, w_typ1))):
+                and space.issubtype_w(w_typ2, w_typ1)):
                 w_obj1, w_obj2 = w_obj2, w_obj1
                 w_left_impl, w_right_impl = w_right_impl, w_left_impl
 
@@ -495,8 +495,11 @@
                         "coercion should return None or 2-tuple")
         return w_res
 
+    def issubtype_w(space, w_sub, w_type):
+        return space._type_issubtype(w_sub, w_type)
+
     def issubtype(space, w_sub, w_type):
-        return space._type_issubtype(w_sub, w_type)
+        return space.wrap(space._type_issubtype(w_sub, w_type))
 
     @specialize.arg_or_var(2)
     def isinstance_w(space, w_inst, w_type):
@@ -553,7 +556,7 @@
     else:
         w_right_src, w_right_impl = space.lookup_in_type_where(w_typ2, 
'__cmp__')
         if (w_left_src is not w_right_src
-            and space.is_true(space.issubtype(w_typ2, w_typ1))):
+            and space.issubtype_w(w_typ2, w_typ1)):
             w_obj1, w_obj2 = w_obj2, w_obj1
             w_left_impl, w_right_impl = w_right_impl, w_left_impl
             do_neg1, do_neg2 = do_neg2, do_neg1
@@ -690,7 +693,7 @@
                 if ((seq_bug_compat and w_typ1.flag_sequence_bug_compat
                                     and not w_typ2.flag_sequence_bug_compat)
                         # the non-bug-compat part is the following check:
-                        or space.is_true(space.issubtype(w_typ2, w_typ1))):
+                        or space.issubtype_w(w_typ2, w_typ1)):
                     if (not space.abstract_issubclass_w(w_left_src, 
w_right_src) and
                         not space.abstract_issubclass_w(w_typ1, w_right_src)):
                         w_obj1, w_obj2 = w_obj2, w_obj1
@@ -729,7 +732,7 @@
                 # if the type is the same, *or* if both are old-style classes,
                 # then don't reverse: try left first, right next.
                 pass
-            elif space.is_true(space.issubtype(w_typ2, w_typ1)):
+            elif space.issubtype_w(w_typ2, w_typ1):
                 # for new-style classes, if typ2 is a subclass of typ1.
                 w_obj1, w_obj2 = w_obj2, w_obj1
                 w_left_impl, w_right_impl = w_right_impl, w_left_impl
diff --git a/pypy/objspace/fake/objspace.py b/pypy/objspace/fake/objspace.py
--- a/pypy/objspace/fake/objspace.py
+++ b/pypy/objspace/fake/objspace.py
@@ -281,6 +281,11 @@
     def type(self, w_obj):
         return w_some_type()
 
+    def issubtype_w(self, w_sub, w_type):
+        is_root(w_sub)
+        is_root(w_type)
+        return NonConstant(True)
+
     def isinstance_w(self, w_inst, w_type):
         is_root(w_inst)
         is_root(w_type)
diff --git a/pypy/objspace/std/dictproxyobject.py 
b/pypy/objspace/std/dictproxyobject.py
--- a/pypy/objspace/std/dictproxyobject.py
+++ b/pypy/objspace/std/dictproxyobject.py
@@ -12,8 +12,8 @@
     erase = staticmethod(erase)
     unerase = staticmethod(unerase)
 
-    def __init__(w_self, space):
-        DictStrategy.__init__(w_self, space)
+    def __init__(self, space):
+        DictStrategy.__init__(self, space)
 
     def getitem(self, w_dict, w_key):
         space = self.space
diff --git a/pypy/objspace/std/noneobject.py b/pypy/objspace/std/noneobject.py
--- a/pypy/objspace/std/noneobject.py
+++ b/pypy/objspace/std/noneobject.py
@@ -4,7 +4,7 @@
 
 
 class W_NoneObject(W_Root):
-    def unwrap(w_self, space):
+    def unwrap(self, space):
         return None
 
     def descr_nonzero(self, space):
diff --git a/pypy/objspace/std/objectobject.py 
b/pypy/objspace/std/objectobject.py
--- a/pypy/objspace/std/objectobject.py
+++ b/pypy/objspace/std/objectobject.py
@@ -84,23 +84,23 @@
     'object()' call."""
 
 
+def _excess_args(__args__):
+    return bool(__args__.arguments_w) or bool(__args__.keywords)
+
 def descr__new__(space, w_type, __args__):
-    from pypy.objspace.std.objectobject import W_ObjectObject
     from pypy.objspace.std.typeobject import _precheck_for_new
+    w_type = _precheck_for_new(space, w_type)
+
     # don't allow arguments if the default object.__init__() is about
     # to be called
-    w_type = _precheck_for_new(space, w_type)
-    w_parentinit, _ = w_type.lookup_where('__init__')
-    if w_parentinit is space.w_object:
-        try:
-            __args__.fixedunpack(0)
-        except ValueError:
+    if _excess_args(__args__):
+        w_parent_init, _ = space.lookup_in_type_where(w_type, '__init__')
+        if w_parent_init is space.w_object:
             raise oefmt(space.w_TypeError,
-                        "default __new__ takes no parameters")
+                        "object() takes no parameters")
     if w_type.is_abstract():
         _abstract_method_error(space, w_type)
-    w_obj = space.allocate_instance(W_ObjectObject, w_type)
-    return w_obj
+    return space.allocate_instance(W_ObjectObject, w_type)
 
 
 def descr___subclasshook__(space, __args__):
@@ -109,12 +109,10 @@
 
 def descr__init__(space, w_obj, __args__):
     # don't allow arguments unless __new__ is overridden
-    w_type = space.type(w_obj)
-    w_parent_new, _ = space.lookup_in_type_where(w_type, '__new__')
-    if w_parent_new is space.w_object:
-        try:
-            __args__.fixedunpack(0)
-        except ValueError:
+    if _excess_args(__args__):
+        w_type = space.type(w_obj)
+        w_parent_new, _ = space.lookup_in_type_where(w_type, '__new__')
+        if w_parent_new is space.w_object:
             raise oefmt(space.w_TypeError,
                         "object.__init__() takes no parameters")
 
diff --git a/pypy/objspace/std/objspace.py b/pypy/objspace/std/objspace.py
--- a/pypy/objspace/std/objspace.py
+++ b/pypy/objspace/std/objspace.py
@@ -617,7 +617,7 @@
 
     def _type_issubtype(self, w_sub, w_type):
         if isinstance(w_sub, W_TypeObject) and isinstance(w_type, 
W_TypeObject):
-            return self.wrap(w_sub.issubtype(w_type))
+            return w_sub.issubtype(w_type)
         raise oefmt(self.w_TypeError, "need type objects")
 
     @specialize.arg_or_var(2)
diff --git a/pypy/objspace/std/sliceobject.py b/pypy/objspace/std/sliceobject.py
--- a/pypy/objspace/std/sliceobject.py
+++ b/pypy/objspace/std/sliceobject.py
@@ -12,13 +12,13 @@
 class W_SliceObject(W_Root):
     _immutable_fields_ = ['w_start', 'w_stop', 'w_step']
 
-    def __init__(w_self, w_start, w_stop, w_step):
+    def __init__(self, w_start, w_stop, w_step):
         assert w_start is not None
         assert w_stop is not None
         assert w_step is not None
-        w_self.w_start = w_start
-        w_self.w_stop = w_stop
-        w_self.w_step = w_step
+        self.w_start = w_start
+        self.w_stop = w_stop
+        self.w_step = w_step
 
     def unwrap(w_slice, space):
         return slice(space.unwrap(w_slice.w_start), 
space.unwrap(w_slice.w_stop), space.unwrap(w_slice.w_step))
diff --git a/pypy/objspace/std/strbufobject.py 
b/pypy/objspace/std/strbufobject.py
--- a/pypy/objspace/std/strbufobject.py
+++ b/pypy/objspace/std/strbufobject.py
@@ -26,10 +26,10 @@
         else:
             return self.w_str._value
 
-    def __repr__(w_self):
+    def __repr__(self):
         """ representation for debugging purposes """
         return "%s(%r[:%d])" % (
-            w_self.__class__.__name__, w_self.builder, w_self.length)
+            self.__class__.__name__, self.builder, self.length)
 
     def unwrap(self, space):
         return self.force()
diff --git a/pypy/objspace/std/transparent.py b/pypy/objspace/std/transparent.py
--- a/pypy/objspace/std/transparent.py
+++ b/pypy/objspace/std/transparent.py
@@ -52,15 +52,15 @@
         raise oefmt(space.w_TypeError, "controller should be function")
 
     if isinstance(w_type, W_TypeObject):
-        if space.is_true(space.issubtype(w_type, 
space.gettypeobject(Function.typedef))):
+        if space.issubtype_w(w_type, space.gettypeobject(Function.typedef)):
             return W_TransparentFunction(space, w_type, w_controller)
-        if space.is_true(space.issubtype(w_type, 
space.gettypeobject(PyTraceback.typedef))):
+        if space.issubtype_w(w_type, space.gettypeobject(PyTraceback.typedef)):
             return W_TransparentTraceback(space, w_type, w_controller)
-        if space.is_true(space.issubtype(w_type, 
space.gettypeobject(PyFrame.typedef))):
+        if space.issubtype_w(w_type, space.gettypeobject(PyFrame.typedef)):
             return W_TransparentFrame(space, w_type, w_controller)
-        if space.is_true(space.issubtype(w_type, 
space.gettypeobject(GeneratorIterator.typedef))):
+        if space.issubtype_w(w_type, 
space.gettypeobject(GeneratorIterator.typedef)):
             return W_TransparentGenerator(space, w_type, w_controller)
-        if space.is_true(space.issubtype(w_type, 
space.gettypeobject(PyCode.typedef))):
+        if space.issubtype_w(w_type, space.gettypeobject(PyCode.typedef)):
             return W_TransparentCode(space, w_type, w_controller)
         if w_type.layout.typedef is space.w_object.layout.typedef:
             return W_Transparent(space, w_type, w_controller)
diff --git a/pypy/objspace/std/typeobject.py b/pypy/objspace/std/typeobject.py
--- a/pypy/objspace/std/typeobject.py
+++ b/pypy/objspace/std/typeobject.py
@@ -153,223 +153,223 @@
     w_new_function = None
 
     @dont_look_inside
-    def __init__(w_self, space, name, bases_w, dict_w,
+    def __init__(self, space, name, bases_w, dict_w,
                  overridetypedef=None, force_new_layout=False):
-        w_self.space = space
-        w_self.name = name
-        w_self.bases_w = bases_w
-        w_self.dict_w = dict_w
-        w_self.hasdict = False
-        w_self.hasuserdel = False
-        w_self.weakrefable = False
-        w_self.w_doc = space.w_None
-        w_self.weak_subclasses = []
-        w_self.flag_heaptype = False
-        w_self.flag_cpytype = False
-        w_self.flag_abstract = False
-        w_self.flag_sequence_bug_compat = False
-        w_self.flag_map_or_seq = '?'   # '?' means "don't know, check 
otherwise"
+        self.space = space
+        self.name = name
+        self.bases_w = bases_w
+        self.dict_w = dict_w
+        self.hasdict = False
+        self.hasuserdel = False
+        self.weakrefable = False
+        self.w_doc = space.w_None
+        self.weak_subclasses = []
+        self.flag_heaptype = False
+        self.flag_cpytype = False
+        self.flag_abstract = False
+        self.flag_sequence_bug_compat = False
+        self.flag_map_or_seq = '?'   # '?' means "don't know, check otherwise"
 
         if overridetypedef is not None:
             assert not force_new_layout
-            layout = setup_builtin_type(w_self, overridetypedef)
+            layout = setup_builtin_type(self, overridetypedef)
         else:
-            layout = setup_user_defined_type(w_self, force_new_layout)
-        w_self.layout = layout
+            layout = setup_user_defined_type(self, force_new_layout)
+        self.layout = layout
 
-        if not is_mro_purely_of_types(w_self.mro_w):
+        if not is_mro_purely_of_types(self.mro_w):
             pass
         else:
             # the _version_tag should change, whenever the content of
             # dict_w of any of the types in the mro changes, or if the mro
             # itself changes
-            w_self._version_tag = VersionTag()
+            self._version_tag = VersionTag()
         from pypy.objspace.std.mapdict import DictTerminator, NoDictTerminator
         # if the typedef has a dict, then the rpython-class does all the dict
         # management, which means from the point of view of mapdict there is no
         # dict. However, W_InstanceObjects are an exception to this
         from pypy.module.__builtin__.interp_classobj import W_InstanceObject
-        typedef = w_self.layout.typedef
-        if (w_self.hasdict and not typedef.hasdict or
+        typedef = self.layout.typedef
+        if (self.hasdict and not typedef.hasdict or
                 typedef is W_InstanceObject.typedef):
-            w_self.terminator = DictTerminator(space, w_self)
+            self.terminator = DictTerminator(space, self)
         else:
-            w_self.terminator = NoDictTerminator(space, w_self)
+            self.terminator = NoDictTerminator(space, self)
 
     def __repr__(self):
         "NOT_RPYTHON"
         return '<W_TypeObject %r at 0x%x>' % (self.name, id(self))
 
-    def mutated(w_self, key):
+    def mutated(self, key):
         """
         The type is being mutated. key is either the string containing the
         specific attribute which is being deleted/set or None to indicate a
         generic mutation.
         """
-        space = w_self.space
-        assert w_self.is_heaptype() or w_self.is_cpytype()
+        space = self.space
+        assert self.is_heaptype() or self.is_cpytype()
 
-        w_self.uses_object_getattribute = False
+        self.uses_object_getattribute = False
         # ^^^ conservative default, fixed during real usage
 
         if (key is None or key == '__eq__' or
             key == '__cmp__' or key == '__hash__'):
-            w_self.compares_by_identity_status = UNKNOWN
+            self.compares_by_identity_status = UNKNOWN
 
         if space.config.objspace.std.newshortcut:
-            w_self.w_new_function = None
+            self.w_new_function = None
 
-        if w_self._version_tag is not None:
-            w_self._version_tag = VersionTag()
+        if self._version_tag is not None:
+            self._version_tag = VersionTag()
 
-        subclasses_w = w_self.get_subclasses()
+        subclasses_w = self.get_subclasses()
         for w_subclass in subclasses_w:
             assert isinstance(w_subclass, W_TypeObject)
             w_subclass.mutated(key)
 
-    def version_tag(w_self):
-        if not we_are_jitted() or w_self.is_heaptype():
-            return w_self._version_tag
+    def version_tag(self):
+        if not we_are_jitted() or self.is_heaptype():
+            return self._version_tag
         # prebuilt objects cannot get their version_tag changed
-        return w_self._pure_version_tag()
+        return self._pure_version_tag()
 
     @elidable_promote()
-    def _pure_version_tag(w_self):
-        return w_self._version_tag
+    def _pure_version_tag(self):
+        return self._version_tag
 
-    def getattribute_if_not_from_object(w_self):
+    def getattribute_if_not_from_object(self):
         """ this method returns the applevel __getattribute__ if that is not
         the one from object, in which case it returns None """
         from pypy.objspace.descroperation import object_getattribute
         if not we_are_jitted():
-            if not w_self.uses_object_getattribute:
+            if not self.uses_object_getattribute:
                 # slow path: look for a custom __getattribute__ on the class
-                w_descr = w_self.lookup('__getattribute__')
+                w_descr = self.lookup('__getattribute__')
                 # if it was not actually overriden in the class, we remember 
this
                 # fact for the next time.
-                if w_descr is object_getattribute(w_self.space):
-                    w_self.uses_object_getattribute = True
+                if w_descr is object_getattribute(self.space):
+                    self.uses_object_getattribute = True
                 else:
                     return w_descr
             return None
         # in the JIT case, just use a lookup, because it is folded away
         # correctly using the version_tag
-        w_descr = w_self.lookup('__getattribute__')
-        if w_descr is not object_getattribute(w_self.space):
+        w_descr = self.lookup('__getattribute__')
+        if w_descr is not object_getattribute(self.space):
             return w_descr
 
-    def has_object_getattribute(w_self):
-        return w_self.getattribute_if_not_from_object() is None
+    def has_object_getattribute(self):
+        return self.getattribute_if_not_from_object() is None
 
-    def compares_by_identity(w_self):
+    def compares_by_identity(self):
         from pypy.objspace.descroperation import object_hash, type_eq
         #
-        if w_self.compares_by_identity_status != UNKNOWN:
+        if self.compares_by_identity_status != UNKNOWN:
             # fast path
-            return w_self.compares_by_identity_status == COMPARES_BY_IDENTITY
+            return self.compares_by_identity_status == COMPARES_BY_IDENTITY
         #
-        default_hash = object_hash(w_self.space)
-        my_eq = w_self.lookup('__eq__')
-        overrides_eq = (my_eq and my_eq is not type_eq(w_self.space))
+        default_hash = object_hash(self.space)
+        my_eq = self.lookup('__eq__')
+        overrides_eq = (my_eq and my_eq is not type_eq(self.space))
         overrides_eq_cmp_or_hash = (overrides_eq or
-                                    w_self.lookup('__cmp__') or
-                                    w_self.lookup('__hash__') is not 
default_hash)
+                                    self.lookup('__cmp__') or
+                                    self.lookup('__hash__') is not 
default_hash)
         if overrides_eq_cmp_or_hash:
-            w_self.compares_by_identity_status = OVERRIDES_EQ_CMP_OR_HASH
+            self.compares_by_identity_status = OVERRIDES_EQ_CMP_OR_HASH
         else:
-            w_self.compares_by_identity_status = COMPARES_BY_IDENTITY
-        return w_self.compares_by_identity_status == COMPARES_BY_IDENTITY
+            self.compares_by_identity_status = COMPARES_BY_IDENTITY
+        return self.compares_by_identity_status == COMPARES_BY_IDENTITY
 
-    def ready(w_self):
-        for w_base in w_self.bases_w:
+    def ready(self):
+        for w_base in self.bases_w:
             if not isinstance(w_base, W_TypeObject):
                 continue
-            w_base.add_subclass(w_self)
+            w_base.add_subclass(self)
 
     # compute a tuple that fully describes the instance layout
-    def get_full_instance_layout(w_self):
-        layout = w_self.layout
-        return (layout, w_self.hasdict, w_self.weakrefable)
+    def get_full_instance_layout(self):
+        layout = self.layout
+        return (layout, self.hasdict, self.weakrefable)
 
-    def compute_default_mro(w_self):
-        return compute_C3_mro(w_self.space, w_self)
+    def compute_default_mro(self):
+        return compute_C3_mro(self.space, self)
 
-    def getdictvalue(w_self, space, attr):
-        version_tag = w_self.version_tag()
+    def getdictvalue(self, space, attr):
+        version_tag = self.version_tag()
         if version_tag is not None:
             return unwrap_cell(
                 space,
-                w_self._pure_getdictvalue_no_unwrapping(
+                self._pure_getdictvalue_no_unwrapping(
                     space, version_tag, attr))
-        w_value = w_self._getdictvalue_no_unwrapping(space, attr)
+        w_value = self._getdictvalue_no_unwrapping(space, attr)
         return unwrap_cell(space, w_value)
 
-    def _getdictvalue_no_unwrapping(w_self, space, attr):
-        w_value = w_self.dict_w.get(attr, None)
-        if w_self.lazyloaders and w_value is None:
-            if attr in w_self.lazyloaders:
+    def _getdictvalue_no_unwrapping(self, space, attr):
+        w_value = self.dict_w.get(attr, None)
+        if self.lazyloaders and w_value is None:
+            if attr in self.lazyloaders:
                 # very clever next line: it forces the attr string
                 # to be interned.
                 space.new_interned_str(attr)
-                loader = w_self.lazyloaders[attr]
-                del w_self.lazyloaders[attr]
+                loader = self.lazyloaders[attr]
+                del self.lazyloaders[attr]
                 w_value = loader()
                 if w_value is not None:   # None means no such attribute
-                    w_self.dict_w[attr] = w_value
+                    self.dict_w[attr] = w_value
                     return w_value
         return w_value
 
     @elidable
-    def _pure_getdictvalue_no_unwrapping(w_self, space, version_tag, attr):
-        return w_self._getdictvalue_no_unwrapping(space, attr)
+    def _pure_getdictvalue_no_unwrapping(self, space, version_tag, attr):
+        return self._getdictvalue_no_unwrapping(space, attr)
 
-    def setdictvalue(w_self, space, name, w_value):
-        if not w_self.is_heaptype():
+    def setdictvalue(self, space, name, w_value):
+        if not self.is_heaptype():
             raise oefmt(space.w_TypeError,
-                        "can't set attributes on type object '%N'", w_self)
-        if name == "__del__" and name not in w_self.dict_w:
+                        "can't set attributes on type object '%N'", self)
+        if name == "__del__" and name not in self.dict_w:
             msg = ("a __del__ method added to an existing type will not be "
                    "called")
             space.warn(space.wrap(msg), space.w_RuntimeWarning)
-        version_tag = w_self.version_tag()
+        version_tag = self.version_tag()
         if version_tag is not None:
-            w_curr = w_self._pure_getdictvalue_no_unwrapping(
+            w_curr = self._pure_getdictvalue_no_unwrapping(
                     space, version_tag, name)
             w_value = write_cell(space, w_curr, w_value)
             if w_value is None:
                 return True
-        w_self.mutated(name)
-        w_self.dict_w[name] = w_value
+        self.mutated(name)
+        self.dict_w[name] = w_value
         return True
 
-    def deldictvalue(w_self, space, key):
-        if w_self.lazyloaders:
-            w_self._cleanup_()    # force un-lazification
-        if not w_self.is_heaptype():
+    def deldictvalue(self, space, key):
+        if self.lazyloaders:
+            self._cleanup_()    # force un-lazification
+        if not self.is_heaptype():
             raise oefmt(space.w_TypeError,
-                        "can't delete attributes on type object '%N'", w_self)
+                        "can't delete attributes on type object '%N'", self)
         try:
-            del w_self.dict_w[key]
+            del self.dict_w[key]
         except KeyError:
             return False
         else:
-            w_self.mutated(key)
+            self.mutated(key)
             return True
 
-    def lookup(w_self, name):
+    def lookup(self, name):
         # note that this doesn't call __get__ on the result at all
-        space = w_self.space
-        return w_self.lookup_where_with_method_cache(name)[1]
+        space = self.space
+        return self.lookup_where_with_method_cache(name)[1]
 
-    def lookup_where(w_self, name):
-        space = w_self.space
-        return w_self.lookup_where_with_method_cache(name)
+    def lookup_where(self, name):
+        space = self.space
+        return self.lookup_where_with_method_cache(name)
 
     @unroll_safe
-    def lookup_starting_at(w_self, w_starttype, name):
-        space = w_self.space
+    def lookup_starting_at(self, w_starttype, name):
+        space = self.space
         look = False
-        for w_class in w_self.mro_w:
+        for w_class in self.mro_w:
             if w_class is w_starttype:
                 look = True
             elif look:
@@ -379,54 +379,54 @@
         return None
 
     @unroll_safe
-    def _lookup(w_self, key):
+    def _lookup(self, key):
         # nowadays, only called from ../../tool/ann_override.py
-        space = w_self.space
-        for w_class in w_self.mro_w:
+        space = self.space
+        for w_class in self.mro_w:
             w_value = w_class.getdictvalue(space, key)
             if w_value is not None:
                 return w_value
         return None
 
     @unroll_safe
-    def _lookup_where(w_self, key):
+    def _lookup_where(self, key):
         # like _lookup() but also returns the parent class in which the
         # attribute was found
-        space = w_self.space
-        for w_class in w_self.mro_w:
+        space = self.space
+        for w_class in self.mro_w:
             w_value = w_class.getdictvalue(space, key)
             if w_value is not None:
                 return w_class, w_value
         return None, None
 
-    def _lookup_where_all_typeobjects(w_self, key):
-        # like _lookup_where(), but when we know that w_self.mro_w only
+    def _lookup_where_all_typeobjects(self, key):
+        # like _lookup_where(), but when we know that self.mro_w only
         # contains W_TypeObjects.  (It differs from _lookup_where() mostly
         # from a JIT point of view: it cannot invoke arbitrary Python code.)
-        space = w_self.space
-        for w_class in w_self.mro_w:
+        space = self.space
+        for w_class in self.mro_w:
             assert isinstance(w_class, W_TypeObject)
             w_value = w_class._getdictvalue_no_unwrapping(space, key)
             if w_value is not None:
                 return w_class, w_value
         return None, None
 
-    def lookup_where_with_method_cache(w_self, name):
-        space = w_self.space
-        promote(w_self)
-        version_tag = promote(w_self.version_tag())
+    def lookup_where_with_method_cache(self, name):
+        space = self.space
+        promote(self)
+        version_tag = promote(self.version_tag())
         if version_tag is None:
-            tup = w_self._lookup_where(name)
+            tup = self._lookup_where(name)
             return tup
-        tup_w = w_self._pure_lookup_where_with_method_cache(name, version_tag)
+        tup_w = self._pure_lookup_where_with_method_cache(name, version_tag)
         w_class, w_value = tup_w
         if isinstance(w_value, MutableCell):
             return w_class, w_value.unwrap_cell(space)
         return tup_w   # don't make a new tuple, reuse the old one
 
     @elidable
-    def _pure_lookup_where_with_method_cache(w_self, name, version_tag):
-        space = w_self.space
+    def _pure_lookup_where_with_method_cache(self, name, version_tag):
+        space = self.space
         cache = space.fromcache(MethodCache)
         SHIFT2 = r_uint.BITS - space.config.objspace.std.methodcachesizeexp
         SHIFT1 = SHIFT2 - 5
@@ -451,70 +451,70 @@
                 tup = cache.lookup_where[method_hash]
                 if space.config.objspace.std.withmethodcachecounter:
                     cache.hits[name] = cache.hits.get(name, 0) + 1
-#                print "hit", w_self, name
+#                print "hit", self, name
                 return tup
-        tup = w_self._lookup_where_all_typeobjects(name)
+        tup = self._lookup_where_all_typeobjects(name)
         cache.versions[method_hash] = version_tag
         cache.names[method_hash] = name
         cache.lookup_where[method_hash] = tup
         if space.config.objspace.std.withmethodcachecounter:
             cache.misses[name] = cache.misses.get(name, 0) + 1
-#        print "miss", w_self, name
+#        print "miss", self, name
         return tup
 
-    def check_user_subclass(w_self, w_subtype):
-        space = w_self.space
+    def check_user_subclass(self, w_subtype):
+        space = self.space
         if not isinstance(w_subtype, W_TypeObject):
             raise oefmt(space.w_TypeError,
                         "X is not a type object ('%T')", w_subtype)
-        if not w_subtype.issubtype(w_self):
+        if not w_subtype.issubtype(self):
             raise oefmt(space.w_TypeError,
                         "%N.__new__(%N): %N is not a subtype of %N",
-                        w_self, w_subtype, w_subtype, w_self)
-        if w_self.layout.typedef is not w_subtype.layout.typedef:
+                        self, w_subtype, w_subtype, self)
+        if self.layout.typedef is not w_subtype.layout.typedef:
             raise oefmt(space.w_TypeError,
                         "%N.__new__(%N) is not safe, use %N.__new__()",
-                        w_self, w_subtype, w_subtype)
+                        self, w_subtype, w_subtype)
         return w_subtype
 
-    def _cleanup_(w_self):
+    def _cleanup_(self):
         "NOT_RPYTHON.  Forces the lazy attributes to be computed."
-        if 'lazyloaders' in w_self.__dict__:
-            for attr in w_self.lazyloaders.keys():
-                w_self.getdictvalue(w_self.space, attr)
-            del w_self.lazyloaders
+        if 'lazyloaders' in self.__dict__:
+            for attr in self.lazyloaders.keys():
+                self.getdictvalue(self.space, attr)
+            del self.lazyloaders
 
-    def getdict(w_self, space): # returning a dict-proxy!
+    def getdict(self, space): # returning a dict-proxy!
         from pypy.objspace.std.dictproxyobject import DictProxyStrategy
         from pypy.objspace.std.dictmultiobject import W_DictObject
-        if w_self.lazyloaders:
-            w_self._cleanup_()    # force un-lazification
+        if self.lazyloaders:
+            self._cleanup_()    # force un-lazification
         strategy = space.fromcache(DictProxyStrategy)
-        storage = strategy.erase(w_self)
+        storage = strategy.erase(self)
         return W_DictObject(space, strategy, storage)
 
-    def is_heaptype(w_self):
-        return w_self.flag_heaptype
+    def is_heaptype(self):
+        return self.flag_heaptype
 
-    def is_cpytype(w_self):
-        return w_self.flag_cpytype
+    def is_cpytype(self):
+        return self.flag_cpytype
 
-    def is_abstract(w_self):
-        return w_self.flag_abstract
+    def is_abstract(self):
+        return self.flag_abstract
 
-    def set_abstract(w_self, abstract):
-        w_self.flag_abstract = bool(abstract)
+    def set_abstract(self, abstract):
+        self.flag_abstract = bool(abstract)
 
-    def issubtype(w_self, w_type):
-        promote(w_self)
+    def issubtype(self, w_type):
+        promote(self)
         promote(w_type)
         if we_are_jitted():
-            version_tag1 = w_self.version_tag()
+            version_tag1 = self.version_tag()
             version_tag2 = w_type.version_tag()
             if version_tag1 is not None and version_tag2 is not None:
-                res = _pure_issubtype(w_self, w_type, version_tag1, 
version_tag2)
+                res = _pure_issubtype(self, w_type, version_tag1, version_tag2)
                 return res
-        return _issubtype(w_self, w_type)
+        return _issubtype(self, w_type)
 
     def get_module(self):
         space = self.space
@@ -538,8 +538,8 @@
             else:
                 return self.name
 
-    def add_subclass(w_self, w_subclass):
-        space = w_self.space
+    def add_subclass(self, w_subclass):
+        space = self.space
         if not space.config.translation.rweakref:
             # We don't have weakrefs!  In this case, every class stores
             # subclasses in a non-weak list.  ALL CLASSES LEAK!  To make
@@ -552,26 +552,26 @@
 
         assert isinstance(w_subclass, W_TypeObject)
         newref = weakref.ref(w_subclass)
-        for i in range(len(w_self.weak_subclasses)):
-            ref = w_self.weak_subclasses[i]
+        for i in range(len(self.weak_subclasses)):
+            ref = self.weak_subclasses[i]
             if ref() is None:
-                w_self.weak_subclasses[i] = newref
+                self.weak_subclasses[i] = newref
                 return
         else:
-            w_self.weak_subclasses.append(newref)
+            self.weak_subclasses.append(newref)
 
-    def remove_subclass(w_self, w_subclass):
-        space = w_self.space
-        for i in range(len(w_self.weak_subclasses)):
-            ref = w_self.weak_subclasses[i]
+    def remove_subclass(self, w_subclass):
+        space = self.space
+        for i in range(len(self.weak_subclasses)):
+            ref = self.weak_subclasses[i]
             if ref() is w_subclass:
-                del w_self.weak_subclasses[i]
+                del self.weak_subclasses[i]
                 return
 
-    def get_subclasses(w_self):
-        space = w_self.space
+    def get_subclasses(self):
+        space = self.space
         subclasses_w = []
-        for ref in w_self.weak_subclasses:
+        for ref in self.weak_subclasses:
             w_ob = ref()
             if w_ob is not None:
                 subclasses_w.append(w_ob)
@@ -697,9 +697,9 @@
         w_typ = space.type(base)
         if space.is_w(w_typ, space.w_classobj):
             continue # special-case old-style classes
-        if space.is_true(space.issubtype(w_winner, w_typ)):
+        if space.issubtype_w(w_winner, w_typ):
             continue
-        if space.is_true(space.issubtype(w_typ, w_winner)):
+        if space.issubtype_w(w_typ, w_winner):
             w_winner = w_typ
             continue
         raise oefmt(space.w_TypeError,
diff --git a/pypy/objspace/std/unicodeobject.py 
b/pypy/objspace/std/unicodeobject.py
--- a/pypy/objspace/std/unicodeobject.py
+++ b/pypy/objspace/std/unicodeobject.py
@@ -28,22 +28,22 @@
     import_from_mixin(StringMethods)
     _immutable_fields_ = ['_value']
 
-    def __init__(w_self, unistr):
+    def __init__(self, unistr):
         assert isinstance(unistr, unicode)
-        w_self._value = unistr
+        self._value = unistr
 
-    def __repr__(w_self):
+    def __repr__(self):
         """representation for debugging purposes"""
-        return "%s(%r)" % (w_self.__class__.__name__, w_self._value)
+        return "%s(%r)" % (self.__class__.__name__, self._value)
 
-    def unwrap(w_self, space):
+    def unwrap(self, space):
         # for testing
-        return w_self._value
+        return self._value
 
-    def create_if_subclassed(w_self):
-        if type(w_self) is W_UnicodeObject:
-            return w_self
-        return W_UnicodeObject(w_self._value)
+    def create_if_subclassed(self):
+        if type(self) is W_UnicodeObject:
+            return self
+        return W_UnicodeObject(self._value)
 
     def is_w(self, space, w_other):
         if not isinstance(w_other, W_UnicodeObject):
@@ -78,8 +78,8 @@
 
     charbuf_w = str_w
 
-    def listview_unicode(w_self):
-        return _create_list_from_unicode(w_self._value)
+    def listview_unicode(self):
+        return _create_list_from_unicode(self._value)
 
     def ord(self, space):
         if len(self._value) != 1:
diff --git a/pypy/objspace/test/test_descroperation.py 
b/pypy/objspace/test/test_descroperation.py
--- a/pypy/objspace/test/test_descroperation.py
+++ b/pypy/objspace/test/test_descroperation.py
@@ -25,7 +25,7 @@
             pass
         return Base, Sub""")
         w_base, w_sub = space.unpackiterable(w_tup)
-        assert space.is_true(space.issubtype(w_sub, w_base))
+        assert space.issubtype_w(w_sub, w_base)
         w_inst = space.call_function(w_sub)
         assert space.isinstance_w(w_inst, w_base)
 
diff --git a/rpython/annotator/annrpython.py b/rpython/annotator/annrpython.py
--- a/rpython/annotator/annrpython.py
+++ b/rpython/annotator/annrpython.py
@@ -237,7 +237,10 @@
     def setbinding(self, arg, s_value):
         s_old = arg.annotation
         if s_old is not None:
-            assert s_value.contains(s_old)
+            if not s_value.contains(s_old):
+                log.WARNING("%s does not contain %s" % (s_value, s_old))
+                log.WARNING("%s" % annmodel.unionof(s_value, s_old))
+                assert False
         arg.annotation = s_value
 
     def warning(self, msg, pos=None):
diff --git a/rpython/flowspace/model.py b/rpython/flowspace/model.py
--- a/rpython/flowspace/model.py
+++ b/rpython/flowspace/model.py
@@ -172,6 +172,9 @@
                                           #  Constant(last_exception), see 
below
         self.exits = []                   # list of Link(s)
 
+    def is_final_block(self):
+        return self.operations == ()      # return or except block
+
     def at(self):
         if self.operations and self.operations[0].offset >= 0:
             return "@%d" % self.operations[0].offset
diff --git a/rpython/jit/backend/ppc/regalloc.py 
b/rpython/jit/backend/ppc/regalloc.py
--- a/rpython/jit/backend/ppc/regalloc.py
+++ b/rpython/jit/backend/ppc/regalloc.py
@@ -605,6 +605,8 @@
     def prepare_guard_value(self, op):
         l0 = self.ensure_reg(op.getarg(0))
         l1 = self.ensure_reg_or_16bit_imm(op.getarg(1))
+        op.getdescr().make_a_counter_per_value(op,
+            self.cpu.all_reg_indexes[l0.value])
         arglocs = self._prepare_guard(op, [l0, l1])
         return arglocs
 
diff --git a/rpython/jit/backend/x86/test/test_rx86_32_auto_encoding.py 
b/rpython/jit/backend/x86/test/test_rx86_32_auto_encoding.py
--- a/rpython/jit/backend/x86/test/test_rx86_32_auto_encoding.py
+++ b/rpython/jit/backend/x86/test/test_rx86_32_auto_encoding.py
@@ -1,4 +1,4 @@
-import os, random, struct
+import sys, os, random, struct
 import py
 from rpython.jit.backend.x86 import rx86
 from rpython.rlib.rarithmetic import intmask
@@ -257,6 +257,9 @@
         g.close()
         error = [line for line in got.splitlines() if 'error' in line.lower()]
         if error:
+            if (sys.maxint <= 2**32 and
+                    'no compiled in support for x86_64' in error[0]):
+                py.test.skip(error)
             raise Exception("Assembler got an error: %r" % error[0])
         error = [line for line in got.splitlines()
                  if 'warning' in line.lower()]
diff --git a/rpython/rlib/rfloat.py b/rpython/rlib/rfloat.py
--- a/rpython/rlib/rfloat.py
+++ b/rpython/rlib/rfloat.py
@@ -281,6 +281,35 @@
             return (u - 1.) * x / math.log(u)
         return math.exp(x) - 1.
 
+def log2(x):
+    # Uses an algorithm that should:
+    #   (a) produce exact results for powers of 2, and
+    #   (b) be monotonic, assuming that the system log is monotonic.
+    if not isfinite(x):
+        if isnan(x):
+            return x  # log2(nan) = nan
+        elif x > 0.0:
+            return x  # log2(+inf) = +inf
+        else:
+            # log2(-inf) = nan, invalid-operation
+            raise ValueError("math domain error")
+
+    if x > 0.0:
+        if 0:  # HAVE_LOG2
+            return math.log2(x)
+        m, e = math.frexp(x)
+        # We want log2(m * 2**e) == log(m) / log(2) + e.  Care is needed when
+        # x is just greater than 1.0: in that case e is 1, log(m) is negative,
+        # and we get significant cancellation error from the addition of
+        # log(m) / log(2) to e.  The slight rewrite of the expression below
+        # avoids this problem.
+        if x >= 1.0:
+            return math.log(2.0 * m) / math.log(2.0) + (e - 1)
+        else:
+            return math.log(m) / math.log(2.0) + e
+    else:
+        raise ValueError("math domain error")
+
 def round_away(x):
     # round() from libm, which is not available on all platforms!
     absx = abs(x)
diff --git a/rpython/rlib/rposix.py b/rpython/rlib/rposix.py
--- a/rpython/rlib/rposix.py
+++ b/rpython/rlib/rposix.py
@@ -1045,15 +1045,23 @@
         win32traits = make_win32_traits(traits)
         path1 = traits.as_str0(path1)
         path2 = traits.as_str0(path2)
-        if not win32traits.MoveFile(path1, path2):
+        if not win32traits.MoveFileEx(path1, path2, 0):
             raise rwin32.lastSavedWindowsError()
 
 @specialize.argtype(0, 1)
 def replace(path1, path2):
-    if os.name == 'nt':
-        raise NotImplementedError(
-            'On windows, os.replace() should overwrite the destination')
-    return rename(path1, path2)
+    if _WIN32:
+        traits = _preferred_traits(path1)
+        win32traits = make_win32_traits(traits)
+        path1 = traits.as_str0(path1)
+        path2 = traits.as_str0(path2)
+        ret = win32traits.MoveFileEx(path1, path2,
+                     win32traits.MOVEFILE_REPLACE_EXISTING)
+        if not ret:
+            raise rwin32.lastSavedWindowsError()
+    else:
+        ret = rename(path1, path2)
+    return ret
 
 #___________________________________________________________________
 
@@ -1211,21 +1219,14 @@
         if times is None:
             error = c_utime(path, lltype.nullptr(UTIMBUFP.TO))
         else:
-            actime, modtime = times
             if HAVE_UTIMES:
-                import math
-                l_times = lltype.malloc(TIMEVAL2P.TO, 2, flavor='raw')
-                fracpart, intpart = math.modf(actime)
-                rffi.setintfield(l_times[0], 'c_tv_sec', int(intpart))
-                rffi.setintfield(l_times[0], 'c_tv_usec', int(fracpart * 1e6))
-                fracpart, intpart = math.modf(modtime)
-                rffi.setintfield(l_times[1], 'c_tv_sec', int(intpart))
-                rffi.setintfield(l_times[1], 'c_tv_usec', int(fracpart * 1e6))
-                error = c_utimes(path, l_times)
-                lltype.free(l_times, flavor='raw')
+                with lltype.scoped_alloc(TIMEVAL2P.TO, 2) as l_timeval2p:
+                    times_to_timeval2p(times, l_timeval2p)
+                    error = c_utimes(path, l_timeval2p)
             else:
                 # we only have utime(), which does not allow
                 # sub-second resolution
+                actime, modtime = times
                 l_utimbuf = lltype.malloc(UTIMBUFP.TO, flavor='raw')
                 l_utimbuf.c_actime  = rffi.r_time_t(actime)
                 l_utimbuf.c_modtime = rffi.r_time_t(modtime)
@@ -1268,6 +1269,17 @@
             lltype.free(atime, flavor='raw')
             lltype.free(mtime, flavor='raw')
 
+def times_to_timeval2p(times, l_timeval2p):
+    actime, modtime = times
+    _time_to_timeval(actime, l_timeval2p[0])
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to