[pypy-svn] r73204 - in pypy/trunk/pypy/interpreter: . test

fijal at codespeak.net fijal at codespeak.net
Wed Mar 31 07:00:06 CEST 2010


Author: fijal
Date: Wed Mar 31 07:00:02 2010
New Revision: 73204

Modified:
   pypy/trunk/pypy/interpreter/function.py
   pypy/trunk/pypy/interpreter/test/test_function.py
Log:
Handle *somehow* the case of passing wrong args to function.__setstate__.
At the very least don't explode with RPython ValueError


Modified: pypy/trunk/pypy/interpreter/function.py
==============================================================================
--- pypy/trunk/pypy/interpreter/function.py	(original)
+++ pypy/trunk/pypy/interpreter/function.py	Wed Mar 31 07:00:02 2010
@@ -295,8 +295,13 @@
     def descr_function__setstate__(self, space, w_args):
         from pypy.interpreter.pycode import PyCode
         args_w = space.unpackiterable(w_args)
-        (w_name, w_doc, w_code, w_func_globals, w_closure, w_defs_w,
-         w_func_dict, w_module) = args_w
+        try:
+            (w_name, w_doc, w_code, w_func_globals, w_closure, w_defs_w,
+             w_func_dict, w_module) = args_w
+        except ValueError:
+            # wrong args
+            raise OperationError(space.w_ValueError,
+                         space.wrap("Wrong arguments to function.__setstate__"))
 
         self.space = space
         self.name = space.str_w(w_name)

Modified: pypy/trunk/pypy/interpreter/test/test_function.py
==============================================================================
--- pypy/trunk/pypy/interpreter/test/test_function.py	(original)
+++ pypy/trunk/pypy/interpreter/test/test_function.py	Wed Mar 31 07:00:02 2010
@@ -288,6 +288,11 @@
         f = lambda: 42
         assert f.func_doc is None
 
+    def test_setstate_called_with_wrong_args(self):
+        f = lambda: 42
+        # not sure what it should raise, since CPython doesn't have setstate
+        # on function types
+        raises(ValueError, type(f).__setstate__, f, (1, 2, 3))
 
 class AppTestMethod: 
     def test_simple_call(self):



More information about the Pypy-commit mailing list