[pypy-svn] r37680 - in pypy/dist/pypy/module/clr: . test

antocuni at codespeak.net antocuni at codespeak.net
Wed Jan 31 17:36:50 CET 2007


Author: antocuni
Date: Wed Jan 31 17:36:49 2007
New Revision: 37680

Modified:
   pypy/dist/pypy/module/clr/interp_clr.py
   pypy/dist/pypy/module/clr/test/test_clr.py
Log:
If we don't know how to box a wrapped value, just pass it to .NET as
an opaque object so that we can retrieve it later.



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:36:49 2007
@@ -72,6 +72,11 @@
     # select the correct case
     if b_obj is None:
         return space.w_None
+
+    w_obj = unbox(b_obj, W_Root)
+    if w_obj is not None:
+        return w_obj # it's already a wrapped object!
+    
     b_type = b_obj.GetType()
     if b_type == typeof(System.Int32):
         intval = unbox(b_obj, ootype.Signed)

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:36:49 2007
@@ -97,3 +97,14 @@
         assert x[0] is None
         y = Hashtable()
         assert y["foo"] is None
+
+    def test_pass_opaque_arguments(self):
+        import clr
+        ArrayList = clr.load_cli_class('System.Collections', 'ArrayList')
+        class Foo:
+            pass
+        obj = Foo()
+        x = ArrayList()
+        x.Add(obj)
+        obj2 = x[0]
+        assert obj is obj2



More information about the Pypy-commit mailing list