X Tutup
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions src/runtime/classmanager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ internal static ClassBase GetClass(Type type)
}
cb = CreateClass(type);
cache.Add(type, cb);
// Initialize the object later, as this might call this GetClass method recursivly (for example when a nested class inherits its declaring class...)
InitClassBase(type, cb);
return cb;
}

Expand All @@ -62,12 +64,6 @@ internal static ClassBase GetClass(Type type)

private static ClassBase CreateClass(Type type)
{
// First, we introspect the managed type and build some class
// information, including generating the member descriptors
// that we'll be putting in the Python class __dict__.

ClassInfo info = GetClassInfo(type);

// Next, select the appropriate managed implementation class.
// Different kinds of types, such as array types or interface
// types, want to vary certain implementation details to make
Expand Down Expand Up @@ -115,6 +111,18 @@ private static ClassBase CreateClass(Type type)
impl = new ClassObject(type);
}


return impl;
}

private static void InitClassBase(Type type, ClassBase impl)
{
// First, we introspect the managed type and build some class
// information, including generating the member descriptors
// that we'll be putting in the Python class __dict__.

ClassInfo info = GetClassInfo(type);

impl.indexer = info.indexer;

// Now we allocate the Python type object to reflect the given
Expand Down Expand Up @@ -182,10 +190,8 @@ private static ClassBase CreateClass(Type type)
}
}

return impl;
}


private static ClassInfo GetClassInfo(Type type)
{
ClassInfo ci = new ClassInfo(type);
Expand Down Expand Up @@ -353,6 +359,7 @@ private static ClassInfo GetClassInfo(Type type)
if (!(tp.IsNestedPublic || tp.IsNestedFamily ||
tp.IsNestedFamORAssem))
continue;
// Note the given instance might be uninitialized
ob = ClassManager.GetClass(tp);
ci.members[mi.Name] = ob;
continue;
Expand Down
11 changes: 11 additions & 0 deletions src/testing/subclasstest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,17 @@ public virtual void OnTestEvent(int value)
}
}

public abstract class RecursiveInheritance
{
public class SubClass : RecursiveInheritance
{
public void SomeMethod()
{

}
}
}

public class TestFunctions
{
public static string test_foo(IInterfaceTest x)
Expand Down
2 changes: 2 additions & 0 deletions src/tests/test_suite/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

from .test_import import test_suite as import_tests
from .test_callback import test_suite as callback_tests
from .test_recursiveTypes import test_suite as recursiveTypes_tests

def test_suite():
suite = unittest.TestSuite()
suite.addTests((import_tests(),))
suite.addTests((callback_tests(),))
suite.addTests((recursiveTypes_tests(),))
return suite
20 changes: 20 additions & 0 deletions src/tests/test_suite/test_recursiveTypes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import unittest, sys
import clr

this_module = sys.modules[__name__]
clr.AddReference("Python.Test")
class RecursiveTypesTests(unittest.TestCase):
"""Test if interop with recursive type inheritance works."""

def testRecursiveTypeCreation(self):
"""Test that a recursive types don't crash with a StackOverflowException"""
import Python.Test as Test
from Python.Test import RecursiveInheritance
test_instance = RecursiveInheritance.SubClass()
test_instance.SomeMethod()
pass


def test_suite():
return unittest.makeSuite(RecursiveTypesTests)

X Tutup