[pypy-svn] r54734 - pypy/branch/oo-jit/pypy/translator/cli

antocuni at codespeak.net antocuni at codespeak.net
Wed May 14 15:41:13 CEST 2008


Author: antocuni
Date: Wed May 14 15:41:10 2008
New Revision: 54734

Modified:
   pypy/branch/oo-jit/pypy/translator/cli/dotnet.py
Log:
create real .NET arrays instead of python lists



Modified: pypy/branch/oo-jit/pypy/translator/cli/dotnet.py
==============================================================================
--- pypy/branch/oo-jit/pypy/translator/cli/dotnet.py	(original)
+++ pypy/branch/oo-jit/pypy/translator/cli/dotnet.py	Wed May 14 15:41:10 2008
@@ -508,11 +508,23 @@
         return hop.genop('same_as', [v_obj], hop.r_result.lowleveltype)
 
 def new_array(type, length):
-    return [None] * length
+    # PythonNet doesn't provide a straightforward way to create arrays,
+    # let's use reflection instead
+
+    # hack to produce the array type name from the member type name
+    typename = type._INSTANCE._assembly_qualified_name
+    parts = typename.split(',')
+    parts[0] = parts[0] + '[]'
+    typename = ','.join(parts)
+    t = PythonNet.System.Type.GetType(typename)
+    ctor = t.GetConstructors()[0]
+    return ctor.Invoke([length])
 
 def init_array(type, *args):
-    # PythonNet doesn't provide a straightforward way to create arrays... fake it with a list
-    return list(args)
+    array = new_array(type, len(args))
+    for i, arg in enumerate(args):
+        array[i] = arg
+    return array
 
 class Entry(ExtRegistryEntry):
     _about_ = new_array



More information about the Pypy-commit mailing list