[pypy-svn] r35167 - in pypy/dist/pypy/translator/cli: . test
antocuni at codespeak.net
antocuni at codespeak.net
Thu Nov 30 16:54:31 CET 2006
Author: antocuni
Date: Thu Nov 30 16:54:30 2006
New Revision: 35167
Modified:
pypy/dist/pypy/translator/cli/dotnet.py
pypy/dist/pypy/translator/cli/test/test_dotnet.py
Log:
Make box() accept also arguments that inherits from System.Object:
this is necessacy for compatibility with PythonNet; consider this
case (at RPython level):
x = ArrayList()
x.Add(42)
y = x.get_Item(0)
y.ToString()
when translated there is no problem, because y's ootype is
NativeInstance(System.Object) e y is a boxed value. However when
running on top of PythonNet the value is automatically unboxed, so y
will contain a plain python int, which of course as no ToString()
method.
To solve, just box() the result of get_Item():
y = box(x.get_Item(0))
Modified: pypy/dist/pypy/translator/cli/dotnet.py
==============================================================================
--- pypy/dist/pypy/translator/cli/dotnet.py (original)
+++ pypy/dist/pypy/translator/cli/dotnet.py Thu Nov 30 16:54:30 2006
@@ -295,6 +295,8 @@
return CLR.System.Char(x)
else:
return CLR.System.String(x)
+ elif isinstance(x, PythonNet.System.Object):
+ return x
else:
assert False
@@ -318,14 +320,16 @@
def specialize_call(self, hop):
v_obj, = hop.inputargs(*hop.args_r)
- if v_obj.concretetype not in BOXABLE_TYPES:
- raise TyperError, "Can't box values of type %s" % v_obj.concretetype
-
- if (v_obj.concretetype is ootype.String):
+
+ TYPE = v_obj.concretetype
+ if (TYPE is ootype.String or isinstance(TYPE, NativeInstance)):
return hop.genop('ooupcast', [v_obj], hop.r_result.lowleveltype)
else:
+ if TYPE not in BOXABLE_TYPES:
+ raise TyperError, "Can't box values of type %s" % v_obj.concretetype
return hop.genop('clibox', [v_obj], hop.r_result.lowleveltype)
+
class Entry(ExtRegistryEntry):
_about_ = unbox
Modified: pypy/dist/pypy/translator/cli/test/test_dotnet.py
==============================================================================
--- pypy/dist/pypy/translator/cli/test/test_dotnet.py (original)
+++ pypy/dist/pypy/translator/cli/test/test_dotnet.py Thu Nov 30 16:54:30 2006
@@ -177,6 +177,12 @@
res = self.interpret(fn, [])
assert res == 'Int32'
+ def test_box_object(self):
+ def fn():
+ return box(System.Object()).ToString()
+ res = self.interpret(fn, [])
+ assert res == 'System.Object'
+
def test_exception(self):
py.test.skip("It doesn't work so far")
def fn():
More information about the pypy-svn
mailing list