| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -158,6 +158,7 @@ internal static void Initialize(bool initSigs = false) | |||
| 158 | 158 | ClassManager.Reset(); | |
| 159 | 159 | ClassDerivedObject.Reset(); | |
| 160 | 160 | TypeManager.Initialize(); | |
| 161 | + CLRObject.creationBlocked = false; | ||
| 161 | 162 | _typesInitialized = true; | |
| 162 | 163 | ||
| 163 | 164 | // Initialize modules that depend on the runtime class. | |
@@ -356,6 +357,7 @@ static bool TryCollectingGarbage(int runs, bool forceBreakLoops, | |||
| 356 | 357 | { | |
| 357 | 358 | NullGCHandles(CLRObject.reflectedObjects); | |
| 358 | 359 | CLRObject.reflectedObjects.Clear(); | |
| 360 | + CLRObject.creationBlocked = true; | ||
| 359 | 361 | } | |
| 360 | 362 | } | |
| 361 | 363 | return false; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,10 +11,15 @@ internal sealed class CLRObject : ManagedType | |||
| 11 | 11 | { | |
| 12 | 12 | internal readonly object inst; | |
| 13 | 13 | ||
| 14 | + internal static bool creationBlocked = false; | ||
| 15 | + | ||
| 14 | 16 | // "borrowed" references | |
| 15 | 17 | internal static readonly HashSet<IntPtr> reflectedObjects = new(); | |
| 16 | 18 | static NewReference Create(object ob, BorrowedReference tp) | |
| 17 | 19 | { | |
| 20 | + if (creationBlocked) | ||
| 21 | + throw new InvalidOperationException("Reflected objects should not be created anymore."); | ||
| 22 | + | ||
| 18 | 23 | Debug.Assert(tp != null); | |
| 19 | 24 | var py = Runtime.PyType_GenericAlloc(tp, 0); | |
| 20 | 25 | ||
@@ -61,6 +66,9 @@ internal static void Restore(object ob, BorrowedReference pyHandle, Dictionary<s | |||
| 61 | 66 | ||
| 62 | 67 | protected override void OnLoad(BorrowedReference ob, Dictionary<string, object?>? context) | |
| 63 | 68 | { | |
| 69 | + if (creationBlocked) | ||
| 70 | + throw new InvalidOperationException("Reflected objects should not be loaded anymore."); | ||
| 71 | + | ||
| 64 | 72 | base.OnLoad(ob, context); | |
| 65 | 73 | GCHandle gc = GCHandle.Alloc(this); | |
| 66 | 74 | SetGCHandle(ob, gc); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments