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

Commitc99cdf3

Browse files
committed
Throw exception trying to add a reflected object after the hashset is cleared
1 parent6f0f671 commitc99cdf3

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

‎src/runtime/Runtime.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ internal static void Initialize(bool initSigs = false)
158158
ClassManager.Reset();
159159
ClassDerivedObject.Reset();
160160
TypeManager.Initialize();
161+
CLRObject.creationBlocked=false;
161162
_typesInitialized=true;
162163

163164
// Initialize modules that depend on the runtime class.
@@ -356,6 +357,7 @@ static bool TryCollectingGarbage(int runs, bool forceBreakLoops,
356357
{
357358
NullGCHandles(CLRObject.reflectedObjects);
358359
CLRObject.reflectedObjects.Clear();
360+
CLRObject.creationBlocked=true;
359361
}
360362
}
361363
returnfalse;

‎src/runtime/Types/ClrObject.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,15 @@ internal sealed class CLRObject : ManagedType
1111
{
1212
internalreadonlyobjectinst;
1313

14+
internalstaticboolcreationBlocked=false;
15+
1416
// "borrowed" references
1517
internalstaticreadonlyHashSet<IntPtr>reflectedObjects=new();
1618
staticNewReferenceCreate(objectob,BorrowedReferencetp)
1719
{
20+
if(creationBlocked)
21+
thrownewInvalidOperationException("Reflected objects should not be created anymore.");
22+
1823
Debug.Assert(tp!=null);
1924
varpy=Runtime.PyType_GenericAlloc(tp,0);
2025

@@ -61,6 +66,9 @@ internal static void Restore(object ob, BorrowedReference pyHandle, Dictionary<s
6166

6267
protectedoverridevoidOnLoad(BorrowedReferenceob,Dictionary<string,object?>?context)
6368
{
69+
if(creationBlocked)
70+
thrownewInvalidOperationException("Reflected objects should not be loaded anymore.");
71+
6472
base.OnLoad(ob,context);
6573
GCHandlegc=GCHandle.Alloc(this);
6674
SetGCHandle(ob,gc);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp