[pypy-svn] r21884 - in pypy/dist/pypy: annotation annotation/test rpython rpython/test translator/c/test
pedronis at codespeak.net
pedronis at codespeak.net
Tue Jan 10 15:53:39 CET 2006
Author: pedronis
Date: Tue Jan 10 15:53:36 2006
New Revision: 21884
Modified:
pypy/dist/pypy/annotation/builtin.py
pypy/dist/pypy/annotation/test/test_annrpython.py
pypy/dist/pypy/rpython/objectmodel.py
pypy/dist/pypy/rpython/rbuiltin.py
pypy/dist/pypy/rpython/test/test_objectmodel.py
pypy/dist/pypy/translator/c/test/test_backendoptimized.py
Log:
remove cast_object<->int, they are dangerous and of unclear purpose right now
Modified: pypy/dist/pypy/annotation/builtin.py
==============================================================================
--- pypy/dist/pypy/annotation/builtin.py (original)
+++ pypy/dist/pypy/annotation/builtin.py Tue Jan 10 15:53:36 2006
@@ -270,15 +270,6 @@
def rarith_intmask(s_obj):
return SomeInteger()
-def robjmodel_cast_obj_to_int(s_instance): # XXX GC behavior
- return SomeInteger()
-
-def robjmodel_cast_int_to_obj(s_int, s_clspbc): # XXX GC behavior
- assert len(s_clspbc.descriptions) == 1
- desc = s_clspbc.descriptions.keys()[0]
- cdef = desc.getuniqueclassdef()
- return SomeInstance(cdef)
-
def robjmodel_instantiate(s_clspbc):
assert isinstance(s_clspbc, SomePBC)
clsdef = None
@@ -362,8 +353,6 @@
##BUILTIN_ANALYZERS[pypy.rpython.rarithmetic.ovfcheck] = rarith_ovfcheck
##BUILTIN_ANALYZERS[pypy.rpython.rarithmetic.ovfcheck_lshift] = rarith_ovfcheck_lshift
BUILTIN_ANALYZERS[pypy.rpython.rarithmetic.intmask] = rarith_intmask
-BUILTIN_ANALYZERS[pypy.rpython.objectmodel.cast_object_to_int] = robjmodel_cast_obj_to_int
-BUILTIN_ANALYZERS[pypy.rpython.objectmodel.cast_int_to_object] = robjmodel_cast_int_to_obj
BUILTIN_ANALYZERS[pypy.rpython.objectmodel.instantiate] = robjmodel_instantiate
BUILTIN_ANALYZERS[pypy.rpython.objectmodel.we_are_translated] = (
robjmodel_we_are_translated)
Modified: pypy/dist/pypy/annotation/test/test_annrpython.py
==============================================================================
--- pypy/dist/pypy/annotation/test/test_annrpython.py (original)
+++ pypy/dist/pypy/annotation/test/test_annrpython.py Tue Jan 10 15:53:36 2006
@@ -1944,21 +1944,6 @@
assert s.knowntype == int
graph = tgraphof(t, A.__del__.im_func)
assert graph.startblock in a.annotated
-
- def test_casttoandfromint(self):
- class A(object):
- pass
- def f():
- a = A()
- return objectmodel.cast_object_to_int(a)
- def g(i):
- return objectmodel.cast_int_to_object(i, A)
- a = self.RPythonAnnotator()
- s = a.build_types(f, [])
- assert isinstance(s, annmodel.SomeInteger)
- s = a.build_types(g, [annmodel.SomeInteger()])
- assert isinstance(s, annmodel.SomeInstance)
- assert s.classdef.classdesc.pyobj is A
def g(n):
Modified: pypy/dist/pypy/rpython/objectmodel.py
==============================================================================
--- pypy/dist/pypy/rpython/objectmodel.py (original)
+++ pypy/dist/pypy/rpython/objectmodel.py Tue Jan 10 15:53:36 2006
@@ -37,29 +37,7 @@
obj.__class__ = FREED_OBJECT
-# support for cast from object to int and back
-
-__int_to_weakref = {}
-
-def cast_object_to_int(obj):
- i = id(obj)
- if i not in __int_to_weakref:
- __int_to_weakref[i] = weakref.ref(obj)
- return i
-
-def cast_int_to_object(i, expected_class):
- # only ints are valid that are the result of cast_object_to_int
- if i not in __int_to_weakref:
- raise ValueError("not a valid object")
- obj = __int_to_weakref[i]()
- if obj is not None:
- if type(obj) != expected_class:
- raise ValueError("class of obj != expected_class")
- return obj
- else:
- return FREED_OBJECT()
-
-# __ invoke XXX this doesn't seem completely the right place for this
+# __ hlinvoke XXX this doesn't seem completely the right place for this
def hlinvoke(repr, llcallable, *args):
raise TypeError, "hlinvoke is meant to be rtyped and not called direclty"
Modified: pypy/dist/pypy/rpython/rbuiltin.py
==============================================================================
--- pypy/dist/pypy/rpython/rbuiltin.py (original)
+++ pypy/dist/pypy/rpython/rbuiltin.py Tue Jan 10 15:53:36 2006
@@ -301,18 +301,6 @@
return hop.genop('runtime_type_info', vlist,
resulttype = rptr.PtrRepr(lltype.Ptr(lltype.RuntimeTypeInfo)))
-def rtype_cast_object_to_int(hop):
- assert isinstance(hop.args_r[0], rclass.InstanceRepr)
- vlist = hop.inputargs(hop.args_r[0])
- return hop.genop('cast_ptr_to_int', vlist,
- resulttype = rint.signed_repr)
-
-def rtype_cast_int_to_object(hop):
- assert isinstance(hop.args_r[0], rint.IntegerRepr)
- vlist = [hop.inputarg(rint.signed_repr, arg=0)]
- return hop.genop('cast_int_to_ptr', vlist,
- resulttype = hop.r_result.lowleveltype)
-
BUILTIN_TYPER[lltype.malloc] = rtype_malloc
BUILTIN_TYPER[lltype.cast_pointer] = rtype_cast_pointer
BUILTIN_TYPER[lltype.cast_ptr_to_int] = rtype_cast_ptr_to_int
@@ -326,8 +314,6 @@
BUILTIN_TYPER[rarithmetic.r_ulonglong] = rtype_r_ulonglong
BUILTIN_TYPER[objectmodel.r_dict] = rtype_r_dict
BUILTIN_TYPER[objectmodel.we_are_translated] = rtype_we_are_translated
-BUILTIN_TYPER[objectmodel.cast_object_to_int] = rtype_cast_object_to_int
-BUILTIN_TYPER[objectmodel.cast_int_to_object] = rtype_cast_int_to_object
BUILTIN_TYPER[rstack.yield_current_frame_to_caller] = (
rtype_yield_current_frame_to_caller)
Modified: pypy/dist/pypy/rpython/test/test_objectmodel.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_objectmodel.py (original)
+++ pypy/dist/pypy/rpython/test/test_objectmodel.py Tue Jan 10 15:53:36 2006
@@ -11,39 +11,6 @@
res = interpret(fn, [])
assert res is True
-def test_casttoandfromint_on_cpython():
- class A(object):
- pass
- class B(object):
- pass
- a = A()
- b = B()
- i1 = cast_object_to_int(a)
- i2 = cast_object_to_int(b)
- assert cast_int_to_object(i1, A) is a
- assert cast_int_to_object(i2, B) is b
- a = None
- b = None
- a = cast_int_to_object(i1, A)
- py.test.raises(RuntimeError, "a.b")
-
-def test_casttoandfromint():
- class A(object):
- pass
- def f():
- a = A()
- return cast_object_to_int(a)
- def g():
- a = A()
- i = cast_object_to_int(a)
- return cast_object_to_int(cast_int_to_object(i, A)) == i
- res = interpret(f, [])
- # cannot really check anything about 'res' here
-
- # XXX humpf: there is no sane way to implement cast_ptr_to_int
- # without going for the same hacks as in robjectmodel.cast_XXX_to_XXX
- py.test.raises(AssertionError, interpret, g, [])
-
def strange_key_eq(key1, key2):
return key1[0] == key2[0] # only the 1st character is relevant
def strange_key_hash(key):
Modified: pypy/dist/pypy/translator/c/test/test_backendoptimized.py
==============================================================================
--- pypy/dist/pypy/translator/c/test/test_backendoptimized.py (original)
+++ pypy/dist/pypy/translator/c/test/test_backendoptimized.py Tue Jan 10 15:53:36 2006
@@ -77,25 +77,6 @@
res = fn()
assert res == 42
- def test_casttoandfromint(self):
- class A(object):
- pass
- def f():
- a = A()
- return objectmodel.cast_object_to_int(a)
- def g():
- a = A()
- i = objectmodel.cast_object_to_int(a)
- return objectmodel.cast_object_to_int(
- objectmodel.cast_int_to_object(i, A)) == i
- fn = self.getcompiled(f)
- res = fn()
- # cannot really test anything about 'res' here
- gn = self.getcompiled(g)
- res = gn()
- assert res
-
-
class TestTypedOptimizedSwitchTestCase:
More information about the Pypy-commit
mailing list