[pypy-svn] r17745 - in pypy/dist/pypy: doc interpreter module/__builtin__ objspace objspace/std

arigo at codespeak.net arigo at codespeak.net
Wed Sep 21 21:00:44 CEST 2005


Author: arigo
Date: Wed Sep 21 21:00:39 2005
New Revision: 17745

Modified:
   pypy/dist/pypy/doc/coding-guide.txt
   pypy/dist/pypy/interpreter/function.py
   pypy/dist/pypy/interpreter/typedef.py
   pypy/dist/pypy/module/__builtin__/functional.py
   pypy/dist/pypy/objspace/descroperation.py
   pypy/dist/pypy/objspace/std/fake.py
Log:
* removed all remaining 'if w_obj == space.w_None'.  This is definitely
  something that breaks the thunk space, so it is better made illegal.
  Removed from the coding guide too.

* related details in descroperation.is_true(): trying to make the logic
  safe against probably uncommon patterns of usages in object spaces like
  the thunk.



Modified: pypy/dist/pypy/doc/coding-guide.txt
==============================================================================
--- pypy/dist/pypy/doc/coding-guide.txt	(original)
+++ pypy/dist/pypy/doc/coding-guide.txt	Wed Sep 21 21:00:39 2005
@@ -436,11 +436,7 @@
   writing ``if w_x:``) will give you an error reminding you of
   the problem.
 
-* ``w_x == w_y`` or ``w_x is w_y``: DON'T DO THAT.  The only
-  half-official exception is to check if ``w_x`` contains a
-  wrapped ``None``: you can write ``w_x == space.w_None``.
-  Follow this rule; the case of ``None`` is easy to fix
-  globally later if we find out that we need to.  The
+* ``w_x == w_y`` or ``w_x is w_y``: DON'T DO THAT.  The
   rationale for this rule is that there is no reason that two
   wrappers are related in any way even if they contain what
   looks like the same object at application-level.  To check

Modified: pypy/dist/pypy/interpreter/function.py
==============================================================================
--- pypy/dist/pypy/interpreter/function.py	(original)
+++ pypy/dist/pypy/interpreter/function.py	Wed Sep 21 21:00:39 2005
@@ -176,8 +176,6 @@
                         not space.is_w(w_obj, space.w_None) or
                         space.is_w(w_cls, space.type(space.w_None)))
     if asking_for_bound:
-        #if w_cls == space.w_None:
-        #    w_cls = space.type(w_obj)
         return space.wrap(Method(space, w_function, w_obj, w_cls))
     else:
         return space.wrap(Method(space, w_function, None, w_cls))
@@ -249,8 +247,6 @@
             return space.wrap(self)    # already bound
         else:
             # only allow binding to a more specific class than before
-            #if w_cls == space.w_None:
-            #    w_cls = space.type(w_obj)
             if (w_cls is not None and
                 not space.is_w(w_cls, space.w_None) and
                 not space.is_true(space.abstract_issubclass(w_cls, self.w_class))):

Modified: pypy/dist/pypy/interpreter/typedef.py
==============================================================================
--- pypy/dist/pypy/interpreter/typedef.py	(original)
+++ pypy/dist/pypy/interpreter/typedef.py	Wed Sep 21 21:00:39 2005
@@ -202,7 +202,8 @@
         """property.__get__(obj[, type]) -> value
         Read the value of the property of the given obj."""
         # XXX HAAAAAAAAAAAACK (but possibly a good one)
-        if w_obj == space.w_None and not space.is_w(w_cls, space.type(space.w_None)):
+        if (space.is_w(w_obj, space.w_None)
+            and not space.is_w(w_cls, space.type(space.w_None))):
             #print property, w_obj, w_cls
             return space.wrap(property)
         else:

Modified: pypy/dist/pypy/module/__builtin__/functional.py
==============================================================================
--- pypy/dist/pypy/module/__builtin__/functional.py	(original)
+++ pypy/dist/pypy/module/__builtin__/functional.py	Wed Sep 21 21:00:39 2005
@@ -71,7 +71,7 @@
     try:
         # save duplication by redirecting every error to applevel
         x = space.int_w(w_x)
-        if w_y is space.w_None:
+        if space.is_w(w_y, space.w_None):
             start, stop = 0, x
         else:
             start, stop = x, space.int_w(w_y)

Modified: pypy/dist/pypy/objspace/descroperation.py
==============================================================================
--- pypy/dist/pypy/objspace/descroperation.py	(original)
+++ pypy/dist/pypy/objspace/descroperation.py	Wed Sep 21 21:00:39 2005
@@ -168,11 +168,12 @@
         return space.get_and_call_function(w_descr, w_obj, w_name)
 
     def is_true(space, w_obj):
-        if w_obj == space.w_False:
+        # first a few shortcuts for performance
+        if w_obj is space.w_False:
             return False
-        if w_obj == space.w_True:
+        if w_obj is space.w_True:
             return True
-        if w_obj == space.w_None:
+        if w_obj is space.w_None:
             return False
         w_descr = space.lookup(w_obj, '__nonzero__')
         if w_descr is None:
@@ -180,10 +181,15 @@
             if w_descr is None:
                 return True
         w_res = space.get_and_call_function(w_descr, w_obj)
+        # more shortcuts for common cases
+        if w_res is space.w_False:
+            return False
+        if w_res is space.w_True:
+            return True
         w_restype = space.type(w_res)
         if (space.is_w(w_restype, space.w_bool) or
             space.is_w(w_restype, space.w_int)):
-            return space.is_true(w_res)
+            return space.int_w(w_res) != 0
         else:
             raise OperationError(space.w_TypeError,
                                  space.wrap('__nonzero__ should return '

Modified: pypy/dist/pypy/objspace/std/fake.py
==============================================================================
--- pypy/dist/pypy/objspace/std/fake.py	(original)
+++ pypy/dist/pypy/objspace/std/fake.py	Wed Sep 21 21:00:39 2005
@@ -203,7 +203,8 @@
 
     def descr_descriptor_get(space, descr, w_obj, w_cls=None):
         # XXX HAAAAAAAAAAAACK (but possibly a good one)
-        if w_obj == space.w_None and not space.is_w(w_cls, space.type(space.w_None)):
+        if (space.is_w(w_obj, space.w_None)
+            and not space.is_w(w_cls, space.type(space.w_None))):
             #print descr, w_obj, w_cls
             return space.wrap(descr)
         else:



More information about the Pypy-commit mailing list