[pypy-svn] r37735 - in pypy/dist/pypy/module/clr: . test
antocuni at codespeak.net
antocuni at codespeak.net
Thu Feb 1 15:32:39 CET 2007
Author: antocuni
Date: Thu Feb 1 15:32:38 2007
New Revision: 37735
Modified:
pypy/dist/pypy/module/clr/boxing_rules.py
pypy/dist/pypy/module/clr/interp_clr.py
pypy/dist/pypy/module/clr/test/test_clr.py
Log:
Add rules for converting strings from and to .NET
Modified: pypy/dist/pypy/module/clr/boxing_rules.py
==============================================================================
--- pypy/dist/pypy/module/clr/boxing_rules.py (original)
+++ pypy/dist/pypy/module/clr/boxing_rules.py Thu Feb 1 15:32:38 2007
@@ -2,6 +2,7 @@
from pypy.objspace.std.intobject import W_IntObject
from pypy.objspace.std.floatobject import W_FloatObject
from pypy.objspace.std.noneobject import W_NoneObject
+from pypy.objspace.std.stringobject import W_StringObject
from pypy.translator.cli.dotnet import box
def tocli(self):
@@ -20,6 +21,10 @@
return None
W_NoneObject.tocli = tocli
+def tocli(self):
+ return box(self._value)
+W_StringObject.tocli = tocli
+
from pypy.objspace.fake.objspace import W_Object as W_Object_Fake
from pypy.rlib.nonconst import NonConstant
Modified: pypy/dist/pypy/module/clr/interp_clr.py
==============================================================================
--- pypy/dist/pypy/module/clr/interp_clr.py (original)
+++ pypy/dist/pypy/module/clr/interp_clr.py Thu Feb 1 15:32:38 2007
@@ -84,6 +84,9 @@
elif b_type == typeof(System.Double):
floatval = unbox(b_obj, ootype.Float)
return space.wrap(floatval)
+ elif b_type == typeof(System.String):
+ strval = unbox(b_obj, ootype.String)
+ return space.wrap(strval)
else:
msg = "Can't convert object %s to Python" % str(b_obj.ToString())
raise OperationError(space.w_TypeError, space.wrap(msg))
Modified: pypy/dist/pypy/module/clr/test/test_clr.py
==============================================================================
--- pypy/dist/pypy/module/clr/test/test_clr.py (original)
+++ pypy/dist/pypy/module/clr/test/test_clr.py Thu Feb 1 15:32:38 2007
@@ -114,3 +114,11 @@
x.Add(obj)
obj2 = x[0]
assert obj is obj2
+
+ def test_string_wrapping(self):
+ import clr
+ ArrayList = clr.load_cli_class('System.Collections', 'ArrayList')
+ x = ArrayList()
+ x.Add("bar")
+ s = x[0]
+ assert s == "bar"
More information about the pypy-svn
mailing list