Author: Michal Bendowski <mic...@bendowski.pl> Branch: jvm-improvements Changeset: r56528:41d2ef9fed11 Date: 2012-08-01 17:23 +0200 http://bitbucket.org/pypy/pypy/changeset/41d2ef9fed11/
Log: Detect missing oo_primitive during RTyping. diff --git a/pypy/rpython/rpbc.py b/pypy/rpython/rpbc.py --- a/pypy/rpython/rpbc.py +++ b/pypy/rpython/rpbc.py @@ -5,7 +5,7 @@ from pypy.annotation import description from pypy.objspace.flow.model import Constant from pypy.rpython.lltypesystem.lltype import \ - typeOf, Void, Bool, nullptr, frozendict, Ptr, Struct, malloc + typeOf, Void, Bool, nullptr, frozendict, Ptr, Struct, malloc, FuncType from pypy.rpython.error import TyperError from pypy.rpython.rmodel import Repr, inputconst, CanBeNull, \ mangle, inputdesc, warning, impossible_repr @@ -322,6 +322,14 @@ args = bk.build_args(opname, hop.args_s[1:]) s_pbc = hop.args_s[0] # possibly more precise than self.s_pbc descs = list(s_pbc.descriptions) + + try: + s_pbc.const._ptr._obj.external + # This is an rffi call + self.rtyper.type_system.check_rffi_call(s_pbc.const) + except AttributeError: + pass + vfcs = description.FunctionDesc.variant_for_call_site shape, index = vfcs(bk, self.callfamily, descs, args, hop.spaceop) row_of_graphs = self.callfamily.calltables[shape][index] diff --git a/pypy/rpython/typesystem.py b/pypy/rpython/typesystem.py --- a/pypy/rpython/typesystem.py +++ b/pypy/rpython/typesystem.py @@ -101,6 +101,11 @@ from pypy.rpython.normalizecalls import perform_normalizations perform_normalizations(rtyper) + def check_rffi_call(self, func): + """Check if the rffi primitive is correct. Raise a TypeError otherwise. + """ + pass + class LowLevelTypeSystem(TypeSystem): name = "lltypesystem" callable_trait = (lltype.FuncType, lltype.functionptr) @@ -181,6 +186,11 @@ v_list = hop.inputargs(robj1, robj2) return hop.genop('oois', v_list, resulttype=lltype.Bool) + def check_rffi_call(self, func): + if not hasattr(func._ptr._obj, 'oo_promitive'): + raise TyperError( + "Calling {func_name} via rffi, but it has no OO primitive assigned.".format(func_name=func.func_name)) + # All typesystems are singletons LowLevelTypeSystem.instance = LowLevelTypeSystem() ObjectOrientedTypeSystem.instance = ObjectOrientedTypeSystem() diff --git a/pypy/translator/oosupport/test_template/builtin.py b/pypy/translator/oosupport/test_template/builtin.py --- a/pypy/translator/oosupport/test_template/builtin.py +++ b/pypy/translator/oosupport/test_template/builtin.py @@ -2,6 +2,7 @@ import errno import stat from py.builtin import sorted +from py.test import raises from pypy.tool import udir from pypy.rpython.test.test_rbuiltin import BaseTestRbuiltin from pypy.rpython.module.test.test_ll_time import BaseTestTime as llBaseTestTime @@ -227,6 +228,23 @@ assert res == ord('a') + def test_rffi_missing_primitive(self): + from pypy.rpython.lltypesystem import rffi, lltype + from pypy.translator.tool.cbuild import ExternalCompilationInfo + eci = ExternalCompilationInfo( + includes = ['ctype.h'] + ) + + tolower_no_oo_primitive = rffi.llexternal('tolower', [lltype.Signed], lltype.Signed, + compilation_info=eci) + + def fn(n): + return tolower_no_oo_primitive(n) + + with raises(TypeError): + self.interpret(fn, ord('A')) + + def test_rlocale(self): from pypy.rlib.rlocale import isupper, islower, isalpha, isalnum, tolower def fn(): _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit