[pypy-svn] r37677 - in pypy/dist/pypy/module/clr: . test
antocuni at codespeak.net
antocuni at codespeak.net
Wed Jan 31 17:12:09 CET 2007
Author: antocuni
Date: Wed Jan 31 17:12:08 2007
New Revision: 37677
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:
Convert None to .NET "null" and vice-versa.
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 Wed Jan 31 17:12:08 2007
@@ -1,10 +1,11 @@
from pypy.interpreter.baseobjspace import W_Root
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.translator.cli.dotnet import box
def tocli(self):
- return None
+ return box(self)
W_Root.tocli = tocli
def tocli(self):
@@ -15,6 +16,9 @@
return box(self.floatval)
W_FloatObject.tocli = tocli
+def tocli(self):
+ return None
+W_NoneObject.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 Wed Jan 31 17:12:08 2007
@@ -36,7 +36,10 @@
j = i-startfrom
b_obj = py2cli(space, args[i])
b_args[j] = b_obj
- b_paramtypes[j] = b_obj.GetType() # XXX: potentially inefficient
+ if b_obj is None:
+ b_paramtypes[j] = typeof(System.Object) # we really can't be more precise
+ else:
+ b_paramtypes[j] = b_obj.GetType() # XXX: potentially inefficient
return b_args, b_paramtypes
@@ -62,25 +65,14 @@
call_staticmethod.unwrap_spec = [ObjSpace, str, str, W_Root]
def py2cli(space, w_obj):
-## if space.is_true(space.isinstance(w_obj, space.w_int)):
-## return box(space.int_w(w_obj))
-## if space.is_true(space.isinstance(w_obj, space.w_float)):
-## return box(space.float_w(w_obj))
-## else:
-## typename = space.type(w_obj).getname(space, '?')
-## msg = "Can't convert type %s to .NET" % typename
-## raise OperationError(space.w_TypeError, space.wrap(msg))
- b_result = w_obj.tocli()
- if b_result is None:
- typename = space.type(w_obj).getname(space, '?')
- msg = "Can't convert type %s to .NET" % typename
- raise OperationError(space.w_TypeError, space.wrap(msg))
- else:
- return b_result
+ return w_obj.tocli()
def cli2py(space, b_obj):
+ # TODO: support other types and find the most efficient way to
+ # select the correct case
+ if b_obj is None:
+ return space.w_None
b_type = b_obj.GetType()
- # TODO: support other types
if b_type == typeof(System.Int32):
intval = unbox(b_obj, ootype.Signed)
return space.wrap(intval)
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 Wed Jan 31 17:12:08 2007
@@ -87,3 +87,13 @@
ArrayList = clr.load_cli_class('System.Collections', 'ArrayList')
obj = ArrayList(42)
assert obj.Capacity == 42
+
+ def test_None_as_null(self):
+ import clr
+ ArrayList = clr.load_cli_class('System.Collections', 'ArrayList')
+ Hashtable = clr.load_cli_class('System.Collections', 'Hashtable')
+ x = ArrayList()
+ x.Add(None)
+ assert x[0] is None
+ y = Hashtable()
+ assert y["foo"] is None
More information about the Pypy-commit
mailing list