[pypy-svn] r51489 - in pypy/dist/pypy/translator/cli: . test

antocuni at codespeak.net antocuni at codespeak.net
Thu Feb 14 16:02:11 CET 2008


Author: antocuni
Date: Thu Feb 14 16:02:10 2008
New Revision: 51489

Modified:
   pypy/dist/pypy/translator/cli/query.py
   pypy/dist/pypy/translator/cli/test/test_dotnet.py
Log:
a test to show that bound delegates actually work



Modified: pypy/dist/pypy/translator/cli/query.py
==============================================================================
--- pypy/dist/pypy/translator/cli/query.py	(original)
+++ pypy/dist/pypy/translator/cli/query.py	Thu Feb 14 16:02:10 2008
@@ -160,8 +160,7 @@
         TYPE._assembly_qualified_name = self.AssemblyQualifiedName
         Class = CliClass(TYPE, {}, {})
         self._cliclass = Class
-        # we need to check also for System.Array to prevent a circular recursion
-        if self.FullName in ('System.Object', 'System.Array'):
+        if self.FullName == 'System.Object':
             TYPE._set_superclass(ootype.ROOT)
         else:
             BASETYPE = get_ootype(self.BaseType)

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 Feb 14 16:02:10 2008
@@ -512,6 +512,27 @@
         res = self.interpret(fn, [])
         assert res == 42
 
+    def test_bound_delegate(self):
+        def build_fn():
+            tObjArray = System.Type.GetType("System.Object[]")
+            tInt = typeof(System.Int32)
+            args = init_array(System.Type, tObjArray, tInt, tInt)
+            meth = Utils.CreateDynamicMethod("add", tInt, args)
+            il = meth.GetILGenerator()
+            il.Emit(OpCodes.Ldarg_1)
+            il.Emit(OpCodes.Ldarg_2)
+            il.Emit(OpCodes.Add)
+            il.Emit(OpCodes.Ret)
+            array = new_array(System.Object, 0)
+            myfunc = meth.CreateDelegate(typeof(FUNCTYPE), array)
+            return myfunc
+
+        def fn():
+            myfunc = clidowncast(build_fn(), FUNCTYPE)
+            return myfunc(30, 12)
+        res = self.interpret(fn, [])
+        assert res == 42
+
     def test_valuetype_field(self):
         class Foo:
             def __init__(self, x):



More information about the Pypy-commit mailing list