[pypy-svn] r72720 - in pypy/branch/fix-64/pypy/translator/c: . src test

arigo at codespeak.net arigo at codespeak.net
Wed Mar 24 15:57:31 CET 2010


Author: arigo
Date: Wed Mar 24 15:57:29 2010
New Revision: 72720

Modified:
   pypy/branch/fix-64/pypy/translator/c/node.py
   pypy/branch/fix-64/pypy/translator/c/src/exception.h
   pypy/branch/fix-64/pypy/translator/c/test/test_exception.py
Log:
Merge r72589:72591 from the trunk.


Modified: pypy/branch/fix-64/pypy/translator/c/node.py
==============================================================================
--- pypy/branch/fix-64/pypy/translator/c/node.py	(original)
+++ pypy/branch/fix-64/pypy/translator/c/node.py	Wed Mar 24 15:57:29 2010
@@ -926,9 +926,10 @@
         import types, py
         if isinstance(value, (type, types.ClassType)):
             if (issubclass(value, BaseException) and
-                (value.__module__ == 'exceptions'
-                 or value is py.code._AssertionError)):
+                value.__module__ == 'exceptions'):
                 return 'PyExc_' + value.__name__
+            if value is py.code._AssertionError:
+                return 'PyExc_AssertionError'
         raise Exception("don't know how to simply render py object: %r" %
                         (value, ))
     

Modified: pypy/branch/fix-64/pypy/translator/c/src/exception.h
==============================================================================
--- pypy/branch/fix-64/pypy/translator/c/src/exception.h	(original)
+++ pypy/branch/fix-64/pypy/translator/c/src/exception.h	Wed Mar 24 15:57:29 2010
@@ -99,14 +99,18 @@
 	assert(RPyExceptionOccurred());
 	assert(!PyErr_Occurred());
 	clsname = RPyFetchExceptionType()->ov_name->items;
-	pycls = PyDict_GetItemString(PyEval_GetBuiltins(), clsname);
-	if (pycls != NULL && PyExceptionClass_Check(pycls) &&
-	    PyObject_IsSubclass(pycls, PyExc_Exception)) {
-		v = NULL;
+	v = NULL;
+	if (strcmp(clsname, "AssertionError") == 0) {
+		/* workaround against the py lib's BuiltinAssertionError */
+		pycls = PyExc_AssertionError;
 	}
 	else {
-		pycls = PyExc_Exception; /* XXX RPythonError */
-		v = PyString_FromString(clsname);
+		pycls = PyDict_GetItemString(PyEval_GetBuiltins(), clsname);
+		if (pycls == NULL || !PyExceptionClass_Check(pycls) ||
+		    !PyObject_IsSubclass(pycls, PyExc_Exception)) {
+			pycls = PyExc_Exception; /* XXX RPythonError */
+			v = PyString_FromString(clsname);
+		}
 	}
 	Py_INCREF(pycls);
 	tb = NULL;

Modified: pypy/branch/fix-64/pypy/translator/c/test/test_exception.py
==============================================================================
--- pypy/branch/fix-64/pypy/translator/c/test/test_exception.py	(original)
+++ pypy/branch/fix-64/pypy/translator/c/test/test_exception.py	Wed Mar 24 15:57:29 2010
@@ -121,30 +121,16 @@
     def testfn(n):
         assert n >= 0
 
-    # big confusion with py.test's AssertionError handling here...
-    # some hacks to try to disable it for the current test.
-    saved = no_magic()
-    try:
-        f1 = getcompiled(testfn, [int])
-        res = f1(0)
-        assert res is None, repr(res)
-        res = f1(42)
-        assert res is None, repr(res)
-        py.test.raises(AssertionError, f1, -2)
-    finally:
-        restore_magic(saved)
-
-def no_magic():
-    import __builtin__
-    try:
-        py.magic.revert(__builtin__, 'AssertionError')
-        return True
-    except ValueError:
-        return False
-
-def restore_magic(saved):
-    if saved:
-        py.magic.invoke(assertion=True)
+    f1 = getcompiled(testfn, [int])
+    res = f1(0)
+    assert res is None, repr(res)
+    res = f1(42)
+    assert res is None, repr(res)
+    e = py.test.raises(Exception, f1, -2)
+    assert e.type.__name__ == 'AssertionError'
+    # ^^^ indirection, because we really want
+    # the original AssertionError and not the
+    # one patched by the py lib
 
 
 def test_reraise_exception():



More information about the Pypy-commit mailing list