[pypy-svn] r14494 - pypy/dist/pypy/rpython

arigo at codespeak.net arigo at codespeak.net
Mon Jul 11 13:48:57 CEST 2005


Author: arigo
Date: Mon Jul 11 13:48:55 2005
New Revision: 14494

Modified:
   pypy/dist/pypy/rpython/rclass.py
   pypy/dist/pypy/rpython/rmodel.py
   pypy/dist/pypy/rpython/rpbc.py
Log:
Issue warnings instead of crashing when prebuilt instances are missing an
attribute that the annotator says should be there.


Modified: pypy/dist/pypy/rpython/rclass.py
==============================================================================
--- pypy/dist/pypy/rpython/rclass.py	(original)
+++ pypy/dist/pypy/rpython/rclass.py	Mon Jul 11 13:48:55 2005
@@ -2,7 +2,7 @@
 from pypy.annotation.pairtype import pairtype
 from pypy.annotation import model as annmodel
 from pypy.annotation.classdef import isclassdef
-from pypy.rpython.rmodel import Repr, TyperError, inputconst
+from pypy.rpython.rmodel import Repr, TyperError, inputconst, warning
 from pypy.rpython.lltype import ForwardReference, GcForwardReference
 from pypy.rpython.lltype import Ptr, Struct, GcStruct, malloc
 from pypy.rpython.lltype import cast_pointer, castable, nullptr
@@ -404,7 +404,12 @@
                 if r.lowleveltype == Void:
                     llattrvalue = None
                 else:
-                    attrvalue = getattr(value, name)
+                    try:
+                        attrvalue = getattr(value, name)
+                    except AttributeError:
+                        warning("prebuilt instance %r has no attribute %r" % (
+                            value, name))
+                        continue
                     llattrvalue = r.convert_const(attrvalue)
                 setattr(result, mangled_name, llattrvalue)
         else:

Modified: pypy/dist/pypy/rpython/rmodel.py
==============================================================================
--- pypy/dist/pypy/rpython/rmodel.py	(original)
+++ pypy/dist/pypy/rpython/rmodel.py	Mon Jul 11 13:48:55 2005
@@ -4,6 +4,7 @@
 from pypy.rpython.lltype import Void, Bool, Float, Signed, Char, UniChar
 from pypy.rpython.lltype import typeOf, LowLevelType, Ptr, PyObject
 from pypy.rpython.lltype import FuncType, functionptr
+from pypy.tool.ansi_print import ansi_print
 
 
 class Repr:
@@ -235,3 +236,5 @@
     _callable = getattr(graphfunc, '_specializedversionof_', graphfunc)
     return functionptr(FT, graphfunc.func_name, graph = graph, _callable = _callable)
 
+def warning(msg):
+    ansi_print("*** WARNING: %s" % (msg,), esc="31") # RED

Modified: pypy/dist/pypy/rpython/rpbc.py
==============================================================================
--- pypy/dist/pypy/rpython/rpbc.py	(original)
+++ pypy/dist/pypy/rpython/rpbc.py	Mon Jul 11 13:48:55 2005
@@ -5,7 +5,7 @@
 from pypy.objspace.flow.model import Constant
 from pypy.rpython.lltype import typeOf, Void, ForwardReference, Struct, Bool
 from pypy.rpython.lltype import Ptr, malloc, nullptr
-from pypy.rpython.rmodel import Repr, TyperError, inputconst
+from pypy.rpython.rmodel import Repr, TyperError, inputconst, warning
 from pypy.rpython import rclass
 from pypy.rpython.rtyper import HighLevelOp
 from pypy.rpython import robject
@@ -191,8 +191,12 @@
             for attr, (mangled_name, r_value) in self.llfieldmap.items():
                 try: 
                     thisattrvalue = self.access_set.values[(pbc, attr)] 
-                except KeyError: 
-                    thisattrvalue = getattr(pbc, attr)
+                except KeyError:
+                    try:
+                        thisattrvalue = getattr(pbc, attr)
+                    except AttributeError:
+                        warning("PBC %r has no attribute %r" % (pbc, name))
+                        continue
                 llvalue = r_value.convert_const(thisattrvalue)
                 setattr(result, mangled_name, llvalue)
             return result



More information about the Pypy-commit mailing list