[pypy-svn] r15619 - in pypy/dist/pypy/interpreter: . test

pedronis at codespeak.net pedronis at codespeak.net
Thu Aug 4 15:58:03 CEST 2005


Author: pedronis
Date: Thu Aug  4 15:57:59 2005
New Revision: 15619

Modified:
   pypy/dist/pypy/interpreter/pycode.py
   pypy/dist/pypy/interpreter/test/test_code.py
Log:
fix arg checking to pass test_new



Modified: pypy/dist/pypy/interpreter/pycode.py
==============================================================================
--- pypy/dist/pypy/interpreter/pycode.py	(original)
+++ pypy/dist/pypy/interpreter/pycode.py	Thu Aug  4 15:57:59 2005
@@ -6,6 +6,7 @@
 
 import dis
 from pypy.interpreter import eval
+from pypy.interpreter.error import OperationError
 from pypy.interpreter.gateway import NoneNotWrapped 
 from pypy.interpreter.baseobjspace import ObjSpace, W_Root 
 from pypy.tool.cache import Cache 
@@ -242,8 +243,14 @@
                           w_cellvars=NoneNotWrapped):
         code = space.allocate_instance(PyCode, w_subtype)
         PyCode.__init__(code, space)
-        code.co_argcount   = argcount 
-        code.co_nlocals    = nlocals 
+        if argcount < 0:
+            raise OperationError(space.w_ValueError,
+                                 space.wrap("code: argcount must not be negative"))
+        code.co_argcount   = argcount
+        code.co_nlocals    = nlocals
+        if nlocals < 0:
+            raise OperationError(space.w_ValueError,
+                                 space.wrap("code: nlocals must not be negative"))        
         code.co_stacksize  = stacksize 
         code.co_flags      = flags 
         code.co_code       = codestring 

Modified: pypy/dist/pypy/interpreter/test/test_code.py
==============================================================================
--- pypy/dist/pypy/interpreter/test/test_code.py	(original)
+++ pypy/dist/pypy/interpreter/test/test_code.py	Thu Aug  4 15:57:59 2005
@@ -91,3 +91,32 @@
         d = {}
         exec co in d
         assert d['c'] == 3
+        def f(x):
+            y = 1
+        ccode = f.func_code
+        raises(ValueError, new.code,
+              -ccode.co_argcount,
+              ccode.co_nlocals,
+              ccode.co_stacksize,
+              ccode.co_flags,
+              ccode.co_code,
+              ccode.co_consts,
+              ccode.co_names,
+              ccode.co_varnames,
+              ccode.co_filename,
+              ccode.co_name,
+              ccode.co_firstlineno,
+              ccode.co_lnotab)
+        raises(ValueError, new.code,
+              ccode.co_argcount,
+              -ccode.co_nlocals,
+              ccode.co_stacksize,
+              ccode.co_flags,
+              ccode.co_code,
+              ccode.co_consts,
+              ccode.co_names,
+              ccode.co_varnames,
+              ccode.co_filename,
+              ccode.co_name,
+              ccode.co_firstlineno,
+              ccode.co_lnotab)



More information about the Pypy-commit mailing list