[pypy-svn] pypy default: Obscure workaround for cpyext. Fixes test_structseq.py, which

arigo commits-noreply at bitbucket.org
Sun May 8 12:33:00 CEST 2011


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r43942:2b4ea6060860
Date: 2011-05-08 12:32 +0200
http://bitbucket.org/pypy/pypy/changeset/2b4ea6060860/

Log:	Obscure workaround for cpyext. Fixes test_structseq.py, which has
	been failing since 6ee045ccb063. Blame new-dict-proxy devs for not
	running tests before merging...

diff --git a/pypy/module/cpyext/test/test_cpyext.py b/pypy/module/cpyext/test/test_cpyext.py
--- a/pypy/module/cpyext/test/test_cpyext.py
+++ b/pypy/module/cpyext/test/test_cpyext.py
@@ -304,7 +304,12 @@
             self.unimport_module(name)
         self.cleanup_references(self.space)
         if self.check_and_print_leaks():
-            assert False, "Test leaks or loses object(s)."
+            assert False, (
+                "Test leaks or loses object(s).  You should also check if "
+                "the test actually passed in the first place; if it failed "
+                "it is likely to reach this place.")
+            # XXX find out how to disable check_and_print_leaks() if the
+            # XXX test failed...
 
 
 class AppTestCpythonExtension(AppTestCpythonExtensionBase):
diff --git a/pypy/module/cpyext/test/test_structseq.py b/pypy/module/cpyext/test/test_structseq.py
--- a/pypy/module/cpyext/test/test_structseq.py
+++ b/pypy/module/cpyext/test/test_structseq.py
@@ -30,6 +30,7 @@
              """
                  PyObject *seq;
                  PyStructSequence_InitType(&PyDatatype, &Data_desc);
+                 if (PyErr_Occurred()) return NULL;
                  seq = PyStructSequence_New(&PyDatatype);
                  if (!seq) return NULL;
                  PyStructSequence_SET_ITEM(seq, 0, PyInt_FromLong(42));
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
@@ -29,7 +29,18 @@
             raise OperationError(space.w_TypeError, space.wrap("cannot add non-string keys to dict of a type"))
 
     def impl_setitem_str(self, name, w_value):
-        self.w_type.setdictvalue(self.space, name, w_value)
+        try:
+            self.w_type.setdictvalue(self.space, name, w_value)
+        except OperationError, e:
+            if not e.match(self.space, self.space.w_TypeError):
+                raise
+            w_type = self.w_type
+            if not w_type.is_cpytype():
+                raise
+            # xxx obscure workaround: allow cpyext to write to type->tp_dict.
+            # xxx like CPython, we assume that this is only done early after
+            # xxx the type is created, and we don't invalidate any cache.
+            w_type.dict_w[name] = w_value
 
     def impl_setdefault(self, w_key, w_default):
         space = self.space


More information about the Pypy-commit mailing list