Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jul 22, 2023. It is now read-only.
/pythonnetPublic archive
forked frompythonnet/pythonnet

Commit5aca5cb

Browse files
author
denfromufa
authored
Merge pull requestpythonnet#250 from matthid/fix_stackoverflow
Fix a StackOverflowException.
2 parents8029ffe +502001e commit5aca5cb

File tree

4 files changed

+48
-8
lines changed

4 files changed

+48
-8
lines changed

‎src/runtime/classmanager.cs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ internal static ClassBase GetClass(Type type)
5050
}
5151
cb=CreateClass(type);
5252
cache.Add(type,cb);
53+
// Initialize the object later, as this might call this GetClass method recursivly (for example when a nested class inherits its declaring class...)
54+
InitClassBase(type,cb);
5355
returncb;
5456
}
5557

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

6365
privatestaticClassBaseCreateClass(Typetype)
6466
{
65-
// First, we introspect the managed type and build some class
66-
// information, including generating the member descriptors
67-
// that we'll be putting in the Python class __dict__.
68-
69-
ClassInfoinfo=GetClassInfo(type);
70-
7167
// Next, select the appropriate managed implementation class.
7268
// Different kinds of types, such as array types or interface
7369
// types, want to vary certain implementation details to make
@@ -115,6 +111,18 @@ private static ClassBase CreateClass(Type type)
115111
impl=newClassObject(type);
116112
}
117113

114+
115+
returnimpl;
116+
}
117+
118+
privatestaticvoidInitClassBase(Typetype,ClassBaseimpl)
119+
{
120+
// First, we introspect the managed type and build some class
121+
// information, including generating the member descriptors
122+
// that we'll be putting in the Python class __dict__.
123+
124+
ClassInfoinfo=GetClassInfo(type);
125+
118126
impl.indexer=info.indexer;
119127

120128
// Now we allocate the Python type object to reflect the given
@@ -182,10 +190,8 @@ private static ClassBase CreateClass(Type type)
182190
}
183191
}
184192

185-
returnimpl;
186193
}
187194

188-
189195
privatestaticClassInfoGetClassInfo(Typetype)
190196
{
191197
ClassInfoci=newClassInfo(type);
@@ -353,6 +359,7 @@ private static ClassInfo GetClassInfo(Type type)
353359
if(!(tp.IsNestedPublic||tp.IsNestedFamily||
354360
tp.IsNestedFamORAssem))
355361
continue;
362+
// Note the given instance might be uninitialized
356363
ob=ClassManager.GetClass(tp);
357364
ci.members[mi.Name]=ob;
358365
continue;

‎src/testing/subclasstest.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,17 @@ public virtual void OnTestEvent(int value)
6464
}
6565
}
6666

67+
publicabstractclassRecursiveInheritance
68+
{
69+
publicclassSubClass:RecursiveInheritance
70+
{
71+
publicvoidSomeMethod()
72+
{
73+
74+
}
75+
}
76+
}
77+
6778
publicclassTestFunctions
6879
{
6980
publicstaticstringtest_foo(IInterfaceTestx)

‎src/tests/test_suite/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44

55
from .test_importimporttest_suiteasimport_tests
66
from .test_callbackimporttest_suiteascallback_tests
7+
from .test_recursiveTypesimporttest_suiteasrecursiveTypes_tests
78

89
deftest_suite():
910
suite=unittest.TestSuite()
1011
suite.addTests((import_tests(),))
1112
suite.addTests((callback_tests(),))
13+
suite.addTests((recursiveTypes_tests(),))
1214
returnsuite
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
importunittest,sys
2+
importclr
3+
4+
this_module=sys.modules[__name__]
5+
clr.AddReference("Python.Test")
6+
classRecursiveTypesTests(unittest.TestCase):
7+
"""Test if interop with recursive type inheritance works."""
8+
9+
deftestRecursiveTypeCreation(self):
10+
"""Test that a recursive types don't crash with a StackOverflowException"""
11+
importPython.TestasTest
12+
fromPython.TestimportRecursiveInheritance
13+
test_instance=RecursiveInheritance.SubClass()
14+
test_instance.SomeMethod()
15+
pass
16+
17+
18+
deftest_suite():
19+
returnunittest.makeSuite(RecursiveTypesTests)
20+

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp