Author: Alex Gaynor <alex.gay...@gmail.com> Branch: kill-someobject Changeset: r57810:42d771824b52 Date: 2012-10-07 06:18 -0700 http://bitbucket.org/pypy/pypy/changeset/42d771824b52/
Log: Progress into removing allow_someobjects and PyObject from the rtyper diff --git a/pypy/annotation/policy.py b/pypy/annotation/policy.py --- a/pypy/annotation/policy.py +++ b/pypy/annotation/policy.py @@ -79,6 +79,3 @@ def specialize__ll_and_arg(pol, *args): from pypy.rpython.annlowlevel import LowLevelAnnotatorPolicy return LowLevelAnnotatorPolicy.specialize__ll_and_arg(*args) - -class StrictAnnotatorPolicy(AnnotatorPolicy): - allow_someobjects = False diff --git a/pypy/annotation/test/test_annrpython.py b/pypy/annotation/test/test_annrpython.py --- a/pypy/annotation/test/test_annrpython.py +++ b/pypy/annotation/test/test_annrpython.py @@ -3000,7 +3000,6 @@ v = -maxint return intmask(v * 10) P = policy.AnnotatorPolicy() - P.allow_someobjects = False a = self.RPythonAnnotator(policy=P) s = a.build_types(fun, [bool]) assert isinstance(s, annmodel.SomeInteger) diff --git a/pypy/jit/codewriter/support.py b/pypy/jit/codewriter/support.py --- a/pypy/jit/codewriter/support.py +++ b/pypy/jit/codewriter/support.py @@ -43,7 +43,6 @@ for key, value in translationoptions.items(): setattr(t.config.translation, key, value) annpolicy = AnnotatorPolicy() - annpolicy.allow_someobjects = False a = t.buildannotator(policy=annpolicy) argtypes = getargtypes(a, values) a.build_types(func, argtypes, main_entry_point=True) diff --git a/pypy/objspace/fake/objspace.py b/pypy/objspace/fake/objspace.py --- a/pypy/objspace/fake/objspace.py +++ b/pypy/objspace/fake/objspace.py @@ -275,7 +275,6 @@ t = TranslationContext(config=config) self.t = t # for debugging ann = t.buildannotator() - ann.policy.allow_someobjects = False if func is not None: ann.build_types(func, argtypes, complete_now=False) # diff --git a/pypy/rlib/test/test_timer.py b/pypy/rlib/test/test_timer.py --- a/pypy/rlib/test/test_timer.py +++ b/pypy/rlib/test/test_timer.py @@ -22,7 +22,5 @@ def test_compile_timer(): policy = AnnotatorPolicy() - policy.allow_someobjects = False f_compiled = compile(timer_user, [], annotatorpolicy=policy) f_compiled(expected_extra_mallocs=2) - diff --git a/pypy/rpython/annlowlevel.py b/pypy/rpython/annlowlevel.py --- a/pypy/rpython/annlowlevel.py +++ b/pypy/rpython/annlowlevel.py @@ -38,8 +38,6 @@ __repr__ = __str__ class LowLevelAnnotatorPolicy(AnnotatorPolicy): - allow_someobjects = False - def __init__(pol, rtyper=None): pol.rtyper = rtyper diff --git a/pypy/rpython/lltypesystem/exceptiondata.py b/pypy/rpython/lltypesystem/exceptiondata.py --- a/pypy/rpython/lltypesystem/exceptiondata.py +++ b/pypy/rpython/lltypesystem/exceptiondata.py @@ -1,11 +1,11 @@ from pypy.annotation import model as annmodel from pypy.rpython.lltypesystem import rclass -from pypy.rpython.lltypesystem.lltype import \ - Array, malloc, Ptr, PyObject, pyobjectptr, \ - FuncType, functionptr, Signed +from pypy.rpython.lltypesystem.lltype import (Array, malloc, Ptr, FuncType, + functionptr, Signed) from pypy.rpython.exceptiondata import AbstractExceptionData from pypy.annotation.classdef import FORCE_ATTRIBUTES_INTO_CLASSES + class ExceptionData(AbstractExceptionData): """Public information for the code generators to help with exceptions.""" @@ -13,7 +13,6 @@ # create helper functionptrs self.fn_exception_match = self.make_exception_matcher(rtyper) self.fn_type_of_exc_inst = self.make_type_of_exc_inst(rtyper) - self.fn_pyexcclass2exc = self.make_pyexcclass2exc(rtyper) self.fn_raise_OSError = self.make_raise_OSError(rtyper) def make_exception_matcher(self, rtyper): @@ -22,87 +21,11 @@ helper_fn = rtyper.annotate_helper_fn(rclass.ll_issubclass, [s_typeptr, s_typeptr]) return helper_fn - def make_type_of_exc_inst(self, rtyper): # ll_type_of_exc_inst(exception_instance) -> exception_vtable s_excinst = annmodel.SomePtr(self.lltype_of_exception_value) helper_fn = rtyper.annotate_helper_fn(rclass.ll_type, [s_excinst]) return helper_fn - - def make_pyexcclass2exc(self, rtyper): - # ll_pyexcclass2exc(python_exception_class) -> exception_instance - table = {} - Exception_def = rtyper.annotator.bookkeeper.getuniqueclassdef(Exception) - for clsdef in rtyper.class_reprs: - if (clsdef and clsdef is not Exception_def - and clsdef.issubclass(Exception_def)): - if not hasattr(clsdef.classdesc, 'pyobj'): - continue - cls = clsdef.classdesc.pyobj - if cls in self.standardexceptions and cls not in FORCE_ATTRIBUTES_INTO_CLASSES: - is_standard = True - assert not clsdef.attrs, ( - "%r should not have grown attributes" % (cls,)) - else: - is_standard = (cls.__module__ == 'exceptions' - and not clsdef.attrs) - if is_standard: - example = self.get_standard_ll_exc_instance(rtyper, clsdef) - table[cls] = example - #else: - # assert cls.__module__ != 'exceptions', ( - # "built-in exceptions should not grow attributes") - r_inst = rclass.getinstancerepr(rtyper, None) - r_inst.setup() - default_excinst = malloc(self.lltype_of_exception_value.TO, - immortal=True) - default_excinst.typeptr = r_inst.rclass.getvtable() - - # build the table in order base classes first, subclasses last - sortedtable = [] - def add_class(cls): - if cls in table: - for base in cls.__bases__: - add_class(base) - sortedtable.append((cls, table[cls])) - del table[cls] - for cls in table.keys(): - add_class(cls) - assert table == {} - #print sortedtable - - A = Array(('pycls', Ptr(PyObject)), - ('excinst', self.lltype_of_exception_value)) - pycls2excinst = malloc(A, len(sortedtable), immortal=True) - for i in range(len(sortedtable)): - cls, example = sortedtable[i] - pycls2excinst[i].pycls = pyobjectptr(cls) - pycls2excinst[i].excinst = example - - FUNCTYPE = FuncType([Ptr(PyObject), Ptr(PyObject)], Signed) - PyErr_GivenExceptionMatches = functionptr( - FUNCTYPE, "PyErr_GivenExceptionMatches", external="C", - _callable=lambda pyobj1, pyobj2: - int(issubclass(pyobj1._obj.value, pyobj2._obj.value))) - - initial_value_of_i = len(pycls2excinst)-1 - - def ll_pyexcclass2exc(python_exception_class): - """Return an RPython instance of the best approximation of the - Python exception identified by its Python class. - """ - i = initial_value_of_i - while i >= 0: - if PyErr_GivenExceptionMatches(python_exception_class, - pycls2excinst[i].pycls): - return pycls2excinst[i].excinst - i -= 1 - return default_excinst - - s_pyobj = annmodel.SomePtr(Ptr(PyObject)) - helper_fn = rtyper.annotate_helper_fn(ll_pyexcclass2exc, [s_pyobj]) - return helper_fn - def cast_exception(self, TYPE, value): return rclass.ll_cast_to_object(value) diff --git a/pypy/rpython/lltypesystem/llheap.py b/pypy/rpython/lltypesystem/llheap.py --- a/pypy/rpython/lltypesystem/llheap.py +++ b/pypy/rpython/lltypesystem/llheap.py @@ -1,6 +1,6 @@ # only for the LLInterpreter. Don't use directly. -from pypy.rpython.lltypesystem.lltype import pyobjectptr, malloc, free, typeOf +from pypy.rpython.lltypesystem.lltype import malloc, free, typeOf from pypy.rpython.lltypesystem.llmemory import weakref_create, weakref_deref setfield = setattr diff --git a/pypy/rpython/lltypesystem/lltype.py b/pypy/rpython/lltypesystem/lltype.py --- a/pypy/rpython/lltypesystem/lltype.py +++ b/pypy/rpython/lltypesystem/lltype.py @@ -268,7 +268,7 @@ if self._names: first = self._names[0] FIRSTTYPE = self._flds[first] - if (isinstance(FIRSTTYPE, (Struct, PyObjectType)) and + if (isinstance(FIRSTTYPE, Struct) and self._gckind == FIRSTTYPE._gckind): return first, FIRSTTYPE return None, None @@ -587,19 +587,6 @@ def _inline_is_varsize(self, last): raise TypeError, "%r cannot be inlined in structure" % self -class PyObjectType(ContainerType): - _gckind = 'cpy' - __name__ = 'PyObject' - def __str__(self): - return "PyObject" - def _inline_is_varsize(self, last): - return False - def _defl(self, parent=None, parentindex=None): - return _pyobject(None) - def _allocate(self, initialization, parent=None, parentindex=None): - return self._defl(parent=parent, parentindex=parentindex) - -PyObject = PyObjectType() class ForwardReference(ContainerType): _gckind = 'raw' @@ -912,8 +899,8 @@ % (CURTYPE, PTRTYPE)) if CURTYPE == PTRTYPE: return 0 - if (not isinstance(CURTYPE.TO, (Struct, PyObjectType)) or - not isinstance(PTRTYPE.TO, (Struct, PyObjectType))): + if (not isinstance(CURTYPE.TO, Struct) or + not isinstance(PTRTYPE.TO, Struct)): raise InvalidCast(CURTYPE, PTRTYPE) CURSTRUC = CURTYPE.TO PTRSTRUC = PTRTYPE.TO @@ -1958,21 +1945,6 @@ return _parentable._normalizedcontainer(self) -class _pyobject(Hashable, _container): - __slots__ = [] # or we get in trouble with pickling - - _TYPE = PyObject - - def __repr__(self): - return '<%s>' % (self,) - - def __str__(self): - return "pyobject %s" % (Hashable.__str__(self),) - - def _getid(self): - return id(self.value) - - def malloc(T, n=None, flavor='gc', immortal=False, zero=False, track_allocation=True, add_memory_pressure=False): assert flavor in ('gc', 'raw') @@ -2063,9 +2035,6 @@ o = _opaque(TYPE, _name=name, **attrs) return _ptr(Ptr(TYPE), o, solid=True) -def pyobjectptr(obj): - o = _pyobject(obj) - return _ptr(Ptr(PyObject), o) def cast_ptr_to_int(ptr): return ptr._cast_to_int() diff --git a/pypy/rpython/lltypesystem/rbuiltin.py b/pypy/rpython/lltypesystem/rbuiltin.py --- a/pypy/rpython/lltypesystem/rbuiltin.py +++ b/pypy/rpython/lltypesystem/rbuiltin.py @@ -5,18 +5,12 @@ from pypy.rpython.lltypesystem.rdict import rtype_r_dict from pypy.rlib import objectmodel from pypy.rpython.rmodel import TyperError, Constant -from pypy.rpython.robject import pyobj_repr from pypy.rpython.rbool import bool_repr def rtype_builtin_isinstance(hop): hop.exception_cannot_occur() if hop.s_result.is_constant(): return hop.inputconst(lltype.Bool, hop.s_result.const) - if hop.args_r[0] == pyobj_repr or hop.args_r[1] == pyobj_repr: - v_obj, v_typ = hop.inputargs(pyobj_repr, pyobj_repr) - c = hop.inputconst(pyobj_repr, isinstance) - v = hop.genop('simple_call', [c, v_obj, v_typ], resulttype = pyobj_repr) - return hop.llops.convertvar(v, pyobj_repr, bool_repr) if hop.args_s[1].is_constant() and hop.args_s[1].const == list: if hop.args_s[0].knowntype != list: @@ -51,12 +45,8 @@ hop.exception_cannot_occur() if hop.s_result.is_constant(): return hop.inputconst(lltype.Bool, hop.s_result.const) - if hop.args_r[0] == pyobj_repr: - v_obj, v_name = hop.inputargs(pyobj_repr, pyobj_repr) - c = hop.inputconst(pyobj_repr, hasattr) - v = hop.genop('simple_call', [c, v_obj, v_name], resulttype = pyobj_repr) - return hop.llops.convertvar(v, pyobj_repr, bool_repr) - raise TyperError("hasattr is only suported on a constant or on PyObject") + + raise TyperError("hasattr is only suported on a constant") BUILTIN_TYPER = {} BUILTIN_TYPER[objectmodel.instantiate] = rtype_instantiate diff --git a/pypy/rpython/lltypesystem/rclass.py b/pypy/rpython/lltypesystem/rclass.py --- a/pypy/rpython/lltypesystem/rclass.py +++ b/pypy/rpython/lltypesystem/rclass.py @@ -14,9 +14,8 @@ cast_pointer, cast_ptr_to_int, castable, nullptr, \ RuntimeTypeInfo, getRuntimeTypeInfo, typeOf, \ Array, Char, Void, \ - FuncType, Bool, Signed, functionptr, PyObject + FuncType, Bool, Signed, functionptr from pypy.rpython.lltypesystem import lltype -from pypy.rpython.robject import PyObjRepr, pyobj_repr from pypy.rpython.extregistry import ExtRegistryEntry from pypy.annotation import model as annmodel from pypy.rlib.rarithmetic import intmask diff --git a/pypy/rpython/lltypesystem/rstr.py b/pypy/rpython/lltypesystem/rstr.py --- a/pypy/rpython/lltypesystem/rstr.py +++ b/pypy/rpython/lltypesystem/rstr.py @@ -8,7 +8,6 @@ from pypy.rlib.debug import ll_assert from pypy.rlib import jit from pypy.rlib.rarithmetic import ovfcheck -from pypy.rpython.robject import PyObjRepr, pyobj_repr from pypy.rpython.rmodel import inputconst, IntegerRepr from pypy.rpython.rstr import AbstractStringRepr,AbstractCharRepr,\ AbstractUniCharRepr, AbstractStringIteratorRepr,\ @@ -16,7 +15,7 @@ from pypy.rpython.lltypesystem import ll_str from pypy.rpython.lltypesystem.lltype import \ GcStruct, Signed, Array, Char, UniChar, Ptr, malloc, \ - Bool, Void, GcArray, nullptr, pyobjectptr, cast_primitive, typeOf,\ + Bool, Void, GcArray, nullptr, cast_primitive, typeOf,\ staticAdtMethod, GcForwardReference from pypy.rpython.rmodel import Repr from pypy.rpython.lltypesystem import llmemory @@ -193,43 +192,8 @@ class UniCharRepr(AbstractUniCharRepr, UnicodeRepr): lowleveltype = UniChar -class __extend__(pairtype(PyObjRepr, AbstractStringRepr)): - def convert_from_to((r_from, r_to), v, llops): - v_len = llops.gencapicall('PyString_Size', [v], resulttype=Signed) - cstr = inputconst(Void, STR) - cflags = inputconst(Void, {'flavor': 'gc'}) - v_result = llops.genop('malloc_varsize', [cstr, cflags, v_len], - resulttype=Ptr(STR)) - llops.gencapicall('PyString_ToRPyString', [v, v_result]) - string_repr = llops.rtyper.type_system.rstr.string_repr - v_result = llops.convertvar(v_result, string_repr, r_to) - return v_result -class __extend__(pairtype(AbstractStringRepr, PyObjRepr)): - def convert_from_to((r_from, r_to), v, llops): - string_repr = llops.rtyper.type_system.rstr.string_repr - v = llops.convertvar(v, r_from, string_repr) - cchars = inputconst(Void, "chars") - # xxx put in table - return llops.gencapicall( - 'PyString_FromRPyString', - [v], - resulttype=pyobj_repr, - _callable=lambda v: pyobjectptr(''.join(v.chars))) - -class __extend__(pairtype(AbstractUnicodeRepr, PyObjRepr)): - def convert_from_to((r_from, r_to), v, llops): - unicode_repr = llops.rtyper.type_system.rstr.unicode_repr - v = llops.convertvar(v, r_from, unicode_repr) - cchars = inputconst(Void, "chars") - # xxx put in table - return llops.gencapicall( - 'PyUnicode_FromRPyUnicode', - [v], - resulttype=pyobj_repr, - _callable=lambda v: pyobjectptr(u''.join(v.chars))) - # ____________________________________________________________ # # Low-level methods. These can be run for testing, but are meant to diff --git a/pypy/rpython/rbool.py b/pypy/rpython/rbool.py --- a/pypy/rpython/rbool.py +++ b/pypy/rpython/rbool.py @@ -3,7 +3,6 @@ from pypy.rpython.lltypesystem.lltype import Signed, Unsigned, Bool, Float from pypy.rpython.error import TyperError from pypy.rpython.rmodel import IntegerRepr, BoolRepr -from pypy.rpython.robject import PyObjRepr, pyobj_repr from pypy.rpython.rmodel import log @@ -62,18 +61,3 @@ log.debug('explicit cast_int_to_bool') return llops.genop('int_is_true', [v], resulttype=Bool) return NotImplemented - -class __extend__(pairtype(PyObjRepr, BoolRepr)): - def convert_from_to((r_from, r_to), v, llops): - if r_to.lowleveltype == Bool: - # xxx put in table - return llops.gencapicall('PyObject_IsTrue', [v], resulttype=Bool, - _callable=lambda pyo: bool(pyo._obj.value)) - return NotImplemented - -class __extend__(pairtype(BoolRepr, PyObjRepr)): - def convert_from_to((r_from, r_to), v, llops): - if r_from.lowleveltype == Bool: - return llops.gencapicall('PyBool_FromLong', [v], - resulttype = pyobj_repr) - return NotImplemented diff --git a/pypy/rpython/rbuiltin.py b/pypy/rpython/rbuiltin.py --- a/pypy/rpython/rbuiltin.py +++ b/pypy/rpython/rbuiltin.py @@ -10,7 +10,6 @@ from pypy.rpython.rrange import rtype_builtin_enumerate from pypy.rpython import rstr from pypy.rpython import rptr -from pypy.rpython.robject import pyobj_repr from pypy.tool import sourcetools from pypy.rpython import extregistry @@ -25,10 +24,7 @@ # built-in method case assert self.methodname is not None result = BuiltinMethodRepr(rtyper, self.s_self, self.methodname) - if result.self_repr == pyobj_repr: - return pyobj_repr # special case: methods of 'PyObject*' - else: - return result + return result def rtyper_makekey(self): if self.s_self is None: # built-in function case diff --git a/pypy/rpython/rdict.py b/pypy/rpython/rdict.py --- a/pypy/rpython/rdict.py +++ b/pypy/rpython/rdict.py @@ -4,7 +4,6 @@ from pypy.rpython.lltypesystem import lltype from pypy.rlib.rarithmetic import r_uint from pypy.rlib.objectmodel import hlinvoke -from pypy.rpython import robject from pypy.rlib import objectmodel from pypy.rpython import rmodel @@ -16,22 +15,18 @@ s_key = dictkey .s_value s_value = dictvalue.s_value force_non_null = self.dictdef.force_non_null - if (s_key.__class__ is annmodel.SomeObject and s_key.knowntype == object and - s_value.__class__ is annmodel.SomeObject and s_value.knowntype == object): - return robject.pyobj_repr + if dictkey.custom_eq_hash: + custom_eq_hash = lambda: (rtyper.getrepr(dictkey.s_rdict_eqfn), + rtyper.getrepr(dictkey.s_rdict_hashfn)) else: - if dictkey.custom_eq_hash: - custom_eq_hash = lambda: (rtyper.getrepr(dictkey.s_rdict_eqfn), - rtyper.getrepr(dictkey.s_rdict_hashfn)) - else: - custom_eq_hash = None - return rtyper.type_system.rdict.DictRepr(rtyper, - lambda: rtyper.getrepr(s_key), - lambda: rtyper.getrepr(s_value), - dictkey, - dictvalue, - custom_eq_hash, - force_non_null) + custom_eq_hash = None + return rtyper.type_system.rdict.DictRepr(rtyper, + lambda: rtyper.getrepr(s_key), + lambda: rtyper.getrepr(s_value), + dictkey, + dictvalue, + custom_eq_hash, + force_non_null) def rtyper_makekey(self): self.dictdef.dictkey .dont_change_any_more = True diff --git a/pypy/rpython/rfloat.py b/pypy/rpython/rfloat.py --- a/pypy/rpython/rfloat.py +++ b/pypy/rpython/rfloat.py @@ -1,13 +1,11 @@ from pypy.tool.pairtype import pairtype from pypy.annotation import model as annmodel -from pypy.rpython.lltypesystem.lltype import ( - Signed, Unsigned, SignedLongLong, UnsignedLongLong, - Bool, Float, Void, pyobjectptr) +from pypy.rpython.lltypesystem.lltype import (Signed, Unsigned, SignedLongLong, + UnsignedLongLong, Bool, Float) from pypy.rpython.error import TyperError from pypy.rpython.rmodel import FloatRepr from pypy.rpython.rmodel import IntegerRepr, BoolRepr from pypy.rpython.rstr import AbstractStringRepr -from pypy.rpython.robject import PyObjRepr, pyobj_repr from pypy.rpython.rmodel import log from pypy.rlib.rarithmetic import base_int @@ -196,22 +194,6 @@ return llops.genop('float_is_true', [v], resulttype=Bool) return NotImplemented -class __extend__(pairtype(PyObjRepr, FloatRepr)): - def convert_from_to((r_from, r_to), v, llops): - if r_to.lowleveltype == Float: - return llops.gencapicall('PyFloat_AsDouble', [v], - resulttype=Float, - _callable=lambda pyo: float(pyo._obj.value)) - return NotImplemented - -class __extend__(pairtype(FloatRepr, PyObjRepr)): - def convert_from_to((r_from, r_to), v, llops): - if r_from.lowleveltype == Float: - return llops.gencapicall('PyFloat_FromDouble', [v], - resulttype=pyobj_repr, - _callable=lambda x: pyobjectptr(x)) - return NotImplemented - # ______________________________________________________________________ # Support for r_singlefloat and r_longfloat from pypy.rlib.rarithmetic diff --git a/pypy/rpython/rint.py b/pypy/rpython/rint.py --- a/pypy/rpython/rint.py +++ b/pypy/rpython/rint.py @@ -3,11 +3,10 @@ from pypy.annotation import model as annmodel from pypy.objspace.flow.operation import op_appendices from pypy.rpython.lltypesystem.lltype import Signed, Unsigned, Bool, Float, \ - Void, Char, UniChar, malloc, pyobjectptr, UnsignedLongLong, \ + Void, Char, UniChar, malloc, UnsignedLongLong, \ SignedLongLong, build_number, Number, cast_primitive, typeOf, \ SignedLongLongLong from pypy.rpython.rmodel import IntegerRepr, inputconst -from pypy.rpython.robject import PyObjRepr, pyobj_repr from pypy.rlib.rarithmetic import intmask, r_int, r_uint, r_ulonglong, \ r_longlong, is_emulated_long from pypy.rpython.error import TyperError, MissingRTypeOperation @@ -411,7 +410,7 @@ self = self.as_int varg = hop.inputarg(self, 0) true = inputconst(Bool, True) - fn = hop.rtyper.type_system.ll_str.ll_int2oct + fn = hop.rtyper.type_system.ll_str.ll_int2oct return hop.gendirectcall(fn, varg, true) def ll_hash_int(n): @@ -432,46 +431,3 @@ return else: raise ValueError - -# -# _________________________ Conversions _________________________ - - -py_to_ll_conversion_functions = { - UnsignedLongLong: ('RPyLong_AsUnsignedLongLong', lambda pyo: r_ulonglong(pyo._obj.value)), - SignedLongLong: ('RPyLong_AsLongLong', lambda pyo: r_longlong(pyo._obj.value)), - Unsigned: ('RPyLong_AsUnsignedLong', lambda pyo: r_uint(pyo._obj.value)), - Signed: ('PyInt_AsLong', lambda pyo: int(pyo._obj.value)) -} -if is_emulated_long: # win64 - py_to_ll_conversion_functions.update( { - Unsigned: ('RPyLong_AsUnsignedLongLong', lambda pyo: r_ulonglong(pyo._obj.value)), - Signed: ('RPyLong_AsLongLong', lambda pyo: r_longlong(pyo._obj.value)), - } ) - -ll_to_py_conversion_functions = { - UnsignedLongLong: ('PyLong_FromUnsignedLongLong', lambda i: pyobjectptr(i)), - SignedLongLong: ('PyLong_FromLongLong', lambda i: pyobjectptr(i)), - Unsigned: ('PyLong_FromUnsignedLong', lambda i: pyobjectptr(i)), - Signed: ('PyInt_FromLong', lambda i: pyobjectptr(i)), -} -if is_emulated_long: # win64 - ll_to_py_conversion_functions.update( { - Unsigned: ('PyLong_FromUnsignedLongLong', lambda i: pyobjectptr(i)), - Signed: ('PyLong_FromLongLong', lambda i: pyobjectptr(i)), - } ) - - -class __extend__(pairtype(PyObjRepr, IntegerRepr)): - def convert_from_to((r_from, r_to), v, llops): - tolltype = r_to.lowleveltype - fnname, callable = py_to_ll_conversion_functions[tolltype] - return llops.gencapicall(fnname, [v], - resulttype=r_to, _callable=callable) - -class __extend__(pairtype(IntegerRepr, PyObjRepr)): - def convert_from_to((r_from, r_to), v, llops): - fromlltype = r_from.lowleveltype - fnname, callable = ll_to_py_conversion_functions[fromlltype] - return llops.gencapicall(fnname, [v], - resulttype=pyobj_repr, _callable=callable) diff --git a/pypy/rpython/rlist.py b/pypy/rpython/rlist.py --- a/pypy/rpython/rlist.py +++ b/pypy/rpython/rlist.py @@ -6,7 +6,6 @@ from pypy.rpython.rstr import AbstractStringRepr, AbstractCharRepr from pypy.rpython.lltypesystem.lltype import typeOf, Ptr, Void, Signed, Bool from pypy.rpython.lltypesystem.lltype import nullptr, Char, UniChar, Number -from pypy.rpython import robject from pypy.rlib.objectmodel import malloc_zero_filled from pypy.rlib.debug import ll_assert from pypy.rlib.rarithmetic import ovfcheck, widen, r_uint, intmask @@ -40,8 +39,6 @@ if (listitem.range_step is not None and not listitem.mutated and not isinstance(s_value, annmodel.SomeImpossibleValue)): return rtyper.type_system.rrange.RangeRepr(listitem.range_step) - elif (s_value.__class__ is annmodel.SomeObject and s_value.knowntype == object): - return robject.pyobj_repr else: # cannot do the rtyper.getrepr() call immediately, for the case # of recursive structures -- i.e. if the listdef contains itself @@ -351,15 +348,6 @@ def rtype_newlist(hop, v_sizehint=None): nb_args = hop.nb_args r_list = hop.r_result - if r_list == robject.pyobj_repr: # special case: SomeObject lists! - clist = hop.inputconst(robject.pyobj_repr, list) - v_result = hop.genop('simple_call', [clist], resulttype = robject.pyobj_repr) - cname = hop.inputconst(robject.pyobj_repr, 'append') - v_meth = hop.genop('getattr', [v_result, cname], resulttype = robject.pyobj_repr) - for i in range(nb_args): - v_item = hop.inputarg(robject.pyobj_repr, arg=i) - hop.genop('simple_call', [v_meth, v_item], resulttype = robject.pyobj_repr) - return v_result r_listitem = r_list.item_repr items_v = [hop.inputarg(r_listitem, arg=i) for i in range(nb_args)] return hop.rtyper.type_system.rlist.newlist(hop.llops, r_list, items_v, diff --git a/pypy/rpython/rmodel.py b/pypy/rpython/rmodel.py --- a/pypy/rpython/rmodel.py +++ b/pypy/rpython/rmodel.py @@ -4,7 +4,7 @@ from pypy.objspace.flow.model import Constant from pypy.rpython.lltypesystem.lltype import \ Void, Bool, Float, Signed, Char, UniChar, \ - typeOf, LowLevelType, Ptr, PyObject, isCompatibleType + typeOf, LowLevelType, Ptr, isCompatibleType from pypy.rpython.lltypesystem import lltype, llmemory from pypy.rpython.ootypesystem import ootype from pypy.rpython.error import TyperError, MissingRTypeOperation @@ -426,7 +426,6 @@ return '%s_%s' % (prefix, name) # __________ utilities __________ -PyObjPtr = Ptr(PyObject) def getgcflavor(classdef): classdesc = classdef.classdesc diff --git a/pypy/rpython/rpbc.py b/pypy/rpython/rpbc.py --- a/pypy/rpython/rpbc.py +++ b/pypy/rpython/rpbc.py @@ -10,7 +10,6 @@ from pypy.rpython.rmodel import Repr, inputconst, CanBeNull, \ mangle, inputdesc, warning, impossible_repr from pypy.rpython import rclass -from pypy.rpython import robject from pypy.rpython.annlowlevel import llstr, llunicode from pypy.rpython import callparse @@ -44,10 +43,6 @@ elif issubclass(kind, description.ClassDesc): # user classes getRepr = rtyper.type_system.rpbc.ClassesPBCRepr - # XXX what about this? -## elif type(x) is type and x.__module__ in sys.builtin_module_names: -## # special case for built-in types, seen in faking -## getRepr = getPyObjRepr elif issubclass(kind, description.MethodDesc): getRepr = rtyper.type_system.rpbc.MethodsPBCRepr elif issubclass(kind, description.FrozenDesc): @@ -57,11 +52,6 @@ else: raise TyperError("unexpected PBC kind %r"%(kind,)) -## elif isinstance(x, builtin_descriptor_type): -## # strange built-in functions, method objects, etc. from fake.py -## getRepr = getPyObjRepr - - return getRepr(rtyper, self) def rtyper_makekey(self): @@ -363,9 +353,6 @@ def rtype_simple_call(self, hop): from pypy.rpython.rspecialcase import rtype_call_specialcase return rtype_call_specialcase(hop) - -def getPyObjRepr(rtyper, s_pbc): - return robject.pyobj_repr def getFrozenPBCRepr(rtyper, s_pbc): descs = list(s_pbc.descriptions) diff --git a/pypy/rpython/rtyper.py b/pypy/rpython/rtyper.py --- a/pypy/rpython/rtyper.py +++ b/pypy/rpython/rtyper.py @@ -15,6 +15,7 @@ import py from pypy.tool.pairtype import pair from pypy.annotation import model as annmodel +from pypy.annotation.annrpython import FAIL from pypy.objspace.flow.model import Variable, Constant from pypy.objspace.flow.model import SpaceOperation, c_last_exception from pypy.rpython.lltypesystem.lltype import \ @@ -185,7 +186,7 @@ assert result is not None # recursive getrepr()! return result - def binding(self, var, default=annmodel.SomeObject()): + def binding(self, var, default=FAIL): s_obj = self.annotator.binding(var, default) return s_obj @@ -1017,7 +1018,6 @@ # _______________________________________________________________________ # this has the side-effect of registering the unary and binary operations # and the rtyper_chooserepr() methods -from pypy.rpython import robject from pypy.rpython import rint, rbool, rfloat from pypy.rpython import rrange from pypy.rpython import rstr, rdict, rlist diff --git a/pypy/rpython/test/test_extfunc.py b/pypy/rpython/test/test_extfunc.py --- a/pypy/rpython/test/test_extfunc.py +++ b/pypy/rpython/test/test_extfunc.py @@ -27,7 +27,6 @@ return b(2) policy = AnnotatorPolicy() - policy.allow_someobjects = False a = RPythonAnnotator(policy=policy) s = a.build_types(f, []) assert isinstance(s, annmodel.SomeInteger) @@ -79,7 +78,6 @@ return d(callback) policy = AnnotatorPolicy() - policy.allow_someobjects = False a = RPythonAnnotator(policy=policy) s = a.build_types(f, []) assert isinstance(s, annmodel.SomeFloat) @@ -97,7 +95,6 @@ return dd(3) policy = AnnotatorPolicy() - policy.allow_someobjects = False a = RPythonAnnotator(policy=policy) s = a.build_types(f, []) assert isinstance(s, annmodel.SomeInteger) @@ -120,7 +117,6 @@ return function_with_tuple_arg((1,)) policy = AnnotatorPolicy() - policy.allow_someobjects = False a = RPythonAnnotator(policy=policy) s = a.build_types(f, []) @@ -145,7 +141,6 @@ return function_with_list(function_returning_list()) policy = AnnotatorPolicy() - policy.allow_someobjects = False a = RPythonAnnotator(policy=policy) s = a.build_types(f, []) assert isinstance(s, annmodel.SomeInteger) @@ -163,7 +158,6 @@ return x(33) + x("aaa") + x([]) + "\n" policy = AnnotatorPolicy() - policy.allow_someobjects = False a = RPythonAnnotator(policy=policy) s = a.build_types(f, []) assert isinstance(s, annmodel.SomeString) @@ -176,7 +170,6 @@ def f(s): return os_open(s) policy = AnnotatorPolicy() - policy.allow_someobjects = False a = RPythonAnnotator(policy=policy) a.build_types(f, [str]) # Does not raise assert a.translator.config.translation.check_str_without_nul == False @@ -195,7 +188,6 @@ def f(l): return os_execve(l) policy = AnnotatorPolicy() - policy.allow_someobjects = False a = RPythonAnnotator(policy=policy) a.build_types(f, [[str]]) # Does not raise assert a.translator.config.translation.check_str_without_nul == False diff --git a/pypy/rpython/test/test_llinterp.py b/pypy/rpython/test/test_llinterp.py --- a/pypy/rpython/test/test_llinterp.py +++ b/pypy/rpython/test/test_llinterp.py @@ -1,22 +1,19 @@ from __future__ import with_statement import py import sys -from pypy.rpython.lltypesystem.lltype import typeOf, pyobjectptr, Ptr,\ - PyObject, Void, malloc, free -from pypy.rpython.lltypesystem.lloperation import llop -from pypy.rpython.llinterp import LLInterpreter, LLException, log +from pypy.rpython.lltypesystem.lltype import typeOf, Void, malloc, free +from pypy.rpython.llinterp import LLInterpreter, LLException from pypy.rpython.rmodel import inputconst from pypy.rpython.annlowlevel import hlstr from pypy.translator.translator import TranslationContext, graphof -from pypy.rpython.rint import signed_repr -from pypy.rpython.lltypesystem import rstr, lltype +from pypy.rpython.lltypesystem import lltype from pypy.annotation import model as annmodel from pypy.annotation.model import lltype_to_annotation from pypy.rlib.rarithmetic import r_uint, ovfcheck -from pypy.rpython.ootypesystem import ootype from pypy.tool import leakfinder from pypy import conftest + # switch on logging of interp to show more info on failing tests def setup_module(mod): @@ -71,27 +68,23 @@ _tcache.clear() def get_interpreter(func, values, view='auto', viewbefore='auto', policy=None, - someobjects=False, type_system="lltype", backendopt=False, - config=None, **extraconfigopts): + type_system="lltype", backendopt=False, config=None, + **extraconfigopts): extra_key = [(key, value) for key, value in extraconfigopts.iteritems()] extra_key.sort() extra_key = tuple(extra_key) key = ((func,) + tuple([typeOf(x) for x in values]) + - (someobjects, backendopt, extra_key)) - try: + (backendopt, extra_key)) + try: (t, interp, graph) = _tcache[key] except KeyError: def annotation(x): T = typeOf(x) - if T == Ptr(PyObject) and someobjects: - return object - else: - return lltype_to_annotation(T) + return lltype_to_annotation(T) - if policy is None and not someobjects: + if policy is None: from pypy.annotation.policy import AnnotatorPolicy policy = AnnotatorPolicy() - policy.allow_someobjects = False t, typer, graph = gengraph(func, [annotation(x) for x in values], viewbefore, policy, type_system=type_system, @@ -110,10 +103,10 @@ return interp, graph def interpret(func, values, view='auto', viewbefore='auto', policy=None, - someobjects=False, type_system="lltype", backendopt=False, - config=None, malloc_check=True, **kwargs): + type_system="lltype", backendopt=False, config=None, + malloc_check=True, **kwargs): interp, graph = get_interpreter(func, values, view, viewbefore, policy, - someobjects, type_system=type_system, + type_system=type_system, backendopt=backendopt, config=config, **kwargs) if not malloc_check: @@ -129,10 +122,10 @@ return result def interpret_raises(exc, func, values, view='auto', viewbefore='auto', - policy=None, someobjects=False, type_system="lltype", + policy=None, type_system="lltype", backendopt=False): interp, graph = get_interpreter(func, values, view, viewbefore, policy, - someobjects, type_system=type_system, + type_system=type_system, backendopt=backendopt) info = py.test.raises(LLException, "interp.eval_graph(graph, values)") try: @@ -269,21 +262,6 @@ res = interpret(f, [3]) assert res == 3 -##def test_unicode(): -## def f(): -## return u'Hello world' -## res = interpret(f, [], someobjects=True) - -## assert res._obj.value == u'Hello world' - -##def test_unicode_split(): -## def f(): -## res = u'Hello world'.split() -## return u' '.join(res) -## res = interpret(f,[],True) -## -## assert res == u'Hello world' - def test_list_reverse(): def f(): l = [1,2,3] @@ -305,14 +283,6 @@ res = interpret(f,[]) assert len(res.ll_items()) == 3 -def test_obj_obj_add(): - def f(x,y): - return x+y - _1L = pyobjectptr(1L) - _2L = pyobjectptr(2L) - res = interpret(f, [_1L, _2L], someobjects=True) - assert res._obj.value == 3L - def test_ovf(): def f(x): try: @@ -367,14 +337,6 @@ assert res == (-sys.maxint - 1) % 30 -def test_obj_obj_is(): - def f(x,y): - return x is y - o = pyobjectptr(object()) - res = interpret(f, [o, o], someobjects=True) - assert res is True - - def test_funny_links(): from pypy.objspace.flow.model import Block, FunctionGraph, \ SpaceOperation, Variable, Constant, Link diff --git a/pypy/rpython/test/test_rpbc.py b/pypy/rpython/test/test_rpbc.py --- a/pypy/rpython/test/test_rpbc.py +++ b/pypy/rpython/test/test_rpbc.py @@ -1660,8 +1660,6 @@ return -1 class P(policy.AnnotatorPolicy): - allow_someobjects = False - def specialize__w(pol, funcdesc, args_s): typ = args_s[1].knowntype if args_s[0].is_constant() and args_s[1].is_constant(): diff --git a/pypy/tool/test/test_error.py b/pypy/tool/test/test_error.py --- a/pypy/tool/test/test_error.py +++ b/pypy/tool/test/test_error.py @@ -3,17 +3,14 @@ """ from pypy.translator.translator import TranslationContext -from pypy.tool.error import AnnotatorError, NoSuchAttrError -from pypy.annotation.policy import BasicAnnotatorPolicy +from pypy.tool.error import AnnotatorError import py -class Policy(BasicAnnotatorPolicy): - allow_someobjects = False def compile_function(function, annotation=[]): t = TranslationContext() - t.buildannotator(policy=Policy()).build_types(function, annotation) + t.buildannotator().build_types(function, annotation) class AAA(object): pass diff --git a/pypy/translator/c/src/exception.h b/pypy/translator/c/src/exception.h --- a/pypy/translator/c/src/exception.h +++ b/pypy/translator/c/src/exception.h @@ -2,25 +2,10 @@ /************************************************************/ /*** C header subsection: exceptions ***/ -#if defined(PYPY_CPYTHON_EXTENSION) && !defined(PYPY_NOT_MAIN_FILE) - PyObject *RPythonError; -#endif - /* just a renaming, unless DO_LOG_EXC is set */ #define RPyExceptionOccurred RPyExceptionOccurred1 #define RPY_DEBUG_RETURN() /* nothing */ -#ifndef PyExceptionClass_Check /* Python < 2.5 */ -# define PyExceptionClass_Check(x) PyClass_Check(x) -# define PyExceptionInstance_Check(x) PyInstance_Check(x) -# define PyExceptionInstance_Class(x) \ - (PyObject*)((PyInstanceObject*)(x))->in_class -#endif - - -/******************************************************************/ -#ifdef HAVE_RTYPER /* RPython version of exceptions */ -/******************************************************************/ #ifdef DO_LOG_EXC #undef RPyExceptionOccurred @@ -69,11 +54,6 @@ #define RPyRaiseSimpleException(exc, msg) _RPyRaiseSimpleException(R##exc) void _RPyRaiseSimpleException(RPYTHON_EXCEPTION rexc); -#ifndef PYPY_STANDALONE -void RPyConvertExceptionFromCPython(void); -void RPyConvertExceptionToCPython(void); -#endif - /* implementations */ #ifndef PYPY_NOT_MAIN_FILE @@ -83,82 +63,4 @@ /* XXX msg is ignored */ RPyRaiseException(RPYTHON_TYPE_OF_EXC_INST(rexc), rexc); } - -#ifdef PYPY_CPYTHON_EXTENSION -void RPyConvertExceptionFromCPython(void) -{ - /* convert the CPython exception to an RPython one */ - PyObject *exc_type, *exc_value, *exc_tb; - RPYTHON_EXCEPTION rexc; - - assert(PyErr_Occurred()); - assert(!RPyExceptionOccurred()); - PyErr_Fetch(&exc_type, &exc_value, &exc_tb); - - /* XXX losing the error message here */ - rexc = RPYTHON_PYEXCCLASS2EXC(exc_type); - RPyRaiseException(RPYTHON_TYPE_OF_EXC_INST(rexc), rexc); -} - -void RPyConvertExceptionToCPython(void) -{ - /* XXX 1. uses officially bad fishing */ - /* XXX 2. looks for exception classes by name, fragile */ - char* clsname; - PyObject *pycls, *v, *tb; - assert(RPyExceptionOccurred()); - assert(!PyErr_Occurred()); - clsname = RPyFetchExceptionType()->ov_name->items; - v = NULL; - if (strcmp(clsname, "AssertionError") == 0) { - /* workaround against the py lib's BuiltinAssertionError */ - pycls = PyExc_AssertionError; - } - else if (strcmp(clsname, "StackOverflow") == 0) { - pycls = PyExc_RuntimeError; - } - else { - 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; - RPyClearException(); - - PyErr_NormalizeException(&pycls, &v, &tb); - PyErr_Restore(pycls, v, tb); -} -#endif /* !PYPY_STANDALONE */ - #endif /* PYPY_NOT_MAIN_FILE */ - - - -/******************************************************************/ -#else /* non-RPython version of exceptions, using CPython only */ -/******************************************************************/ - -#define RPyExceptionOccurred1() PyErr_Occurred() -#define RPyRaiseException(etype, evalue) PyErr_Restore(etype, evalue, NULL) -#define RPyFetchException(etypevar, evaluevar, ignored) do { \ - PyObject *__tb; \ - PyErr_Fetch(&etypevar, &evaluevar, &__tb); \ - if (evaluevar == NULL) { \ - evaluevar = Py_None; \ - Py_INCREF(Py_None); \ - } \ - Py_XDECREF(__tb); \ - } while (0) -#define RPyConvertExceptionFromCPython() /* nothing */ -#define RPyConvertExceptionToCPython(vanishing) vanishing = NULL - -#define RPyRaiseSimpleException(exc, msg) \ - PyErr_SetString(exc, msg) - -/******************************************************************/ -#endif /* HAVE_RTYPER */ -/******************************************************************/ diff --git a/pypy/translator/c/support.py b/pypy/translator/c/support.py --- a/pypy/translator/c/support.py +++ b/pypy/translator/c/support.py @@ -7,8 +7,6 @@ # USESLOTS = True -PyObjPtr = lltype.Ptr(lltype.PyObject) - def barebonearray(ARRAY): """Check if ARRAY is a 'simple' array type, i.e. doesn't need a length nor GC headers.""" @@ -59,23 +57,17 @@ return isinstance(T.TO, lltype.ForwardReference) def llvalue_from_constant(c): - try: - T = c.concretetype - except AttributeError: - T = PyObjPtr - if T == PyObjPtr and not isinstance(c.value, lltype._ptr): - return lltype.pyobjectptr(c.value) + T = c.concretetype + if T == lltype.Void: + return None else: - if T == lltype.Void: - return None - else: - ACTUAL_TYPE = lltype.typeOf(c.value) - # If the type is still uncomputed, we can't make this - # check. Something else will blow up instead, probably - # very confusingly. - if not is_pointer_to_forward_ref(ACTUAL_TYPE): - assert ACTUAL_TYPE == T - return c.value + ACTUAL_TYPE = lltype.typeOf(c.value) + # If the type is still uncomputed, we can't make this + # check. Something else will blow up instead, probably + # very confusingly. + if not is_pointer_to_forward_ref(ACTUAL_TYPE): + assert ACTUAL_TYPE == T + return c.value class CNameManager(NameManager): diff --git a/pypy/translator/driver.py b/pypy/translator/driver.py --- a/pypy/translator/driver.py +++ b/pypy/translator/driver.py @@ -188,8 +188,6 @@ if policy is None: policy = annpolicy.AnnotatorPolicy() - if standalone: - policy.allow_someobjects = False self.policy = policy self.extra = extra @@ -345,22 +343,6 @@ lost = query.qoutput(query.check_methods_qgen(translator)) assert not lost, "lost methods, something gone wrong with the annotation of method defs" - so = query.qoutput(query.polluted_qgen(translator)) - tot = len(translator.graphs) - percent = int(tot and (100.0*so / tot) or 0) - # if there are a few SomeObjects even if the policy doesn't allow - # them, it means that they were put there in a controlled way - # and then it's not a warning. - if not translator.annotator.policy.allow_someobjects: - pr = self.log.info - elif percent == 0: - pr = self.log.info - else: - pr = log.WARNING - pr("-- someobjectness %2d%% (%d of %d functions polluted by SomeObjects)" % (percent, so, tot)) - - - def task_rtype_lltype(self): """ RTyping - lltype version """ diff --git a/pypy/translator/goal/ann_override.py b/pypy/translator/goal/ann_override.py --- a/pypy/translator/goal/ann_override.py +++ b/pypy/translator/goal/ann_override.py @@ -19,8 +19,6 @@ class PyPyAnnotatorPolicy(AnnotatorPolicy): - allow_someobjects = False - def __init__(pol, single_space=None): pol.lookups = {} pol.lookups_where = {} diff --git a/pypy/translator/goal/sharedpypy.py b/pypy/translator/goal/sharedpypy.py --- a/pypy/translator/goal/sharedpypy.py +++ b/pypy/translator/goal/sharedpypy.py @@ -6,7 +6,6 @@ from pypy.tool.option import make_objspace from pypy.interpreter.error import OperationError from pypy.config.pypyoption import pypy_optiondescription, set_pypy_opt_level -from pypy.interpreter.pyopcode import prepare_exec from pypy.translator.goal.ann_override import PyPyAnnotatorPolicy from pypy.config.translationoption import set_opt_level from pypy.config.pypyoption import enable_allworkingmodules @@ -26,8 +25,7 @@ enable_allworkingmodules(config) space = make_objspace(config) - policy = PyPyAnnotatorPolicy(single_space = space) - policy.allow_someobjects = False + policy = PyPyAnnotatorPolicy(single_space=space) def interpret(source, context): source = charp2str(source) _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit