| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 8075f48 commit eb8cb8a
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -29,19 +29,24 @@ public ExtensionType() | |||
| 29 | 29 | ||
| 30 | 30 | IntPtr py = Runtime.PyType_GenericAlloc(tp, 0); | |
| 31 | 31 | ||
| 32 | + // Steals a ref to tpHandle. | ||
| 33 | + tpHandle = tp; | ||
| 34 | + pyHandle = py; | ||
| 35 | + | ||
| 36 | + SetupGc(); | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | + void SetupGc () | ||
| 40 | + { | ||
| 32 | 41 | GCHandle gc = AllocGCHandle(TrackTypes.Extension); | |
| 33 | - Marshal.WriteIntPtr(py, ObjectOffset.magic(tp), (IntPtr)gc); | ||
| 42 | + Marshal.WriteIntPtr(pyHandle, ObjectOffset.magic(tpHandle), (IntPtr)gc); | ||
| 34 | 43 | ||
| 35 | 44 | // We have to support gc because the type machinery makes it very | |
| 36 | 45 | // hard not to - but we really don't have a need for it in most | |
| 37 | 46 | // concrete extension types, so untrack the object to save calls | |
| 38 | 47 | // from Python into the managed runtime that are pure overhead. | |
| 39 | 48 | ||
| 40 | - Runtime.PyObject_GC_UnTrack(py); | ||
| 41 | - | ||
| 42 | - // Steals a ref to tpHandle. | ||
| 43 | - tpHandle = tp; | ||
| 44 | - pyHandle = py; | ||
| 49 | + Runtime.PyObject_GC_UnTrack(pyHandle); | ||
| 45 | 50 | } | |
| 46 | 51 | ||
| 47 | 52 | ||
@@ -101,9 +106,7 @@ public static void tp_dealloc(IntPtr ob) | |||
| 101 | 106 | protected override void OnLoad(InterDomainContext context) | |
| 102 | 107 | { | |
| 103 | 108 | base.OnLoad(context); | |
| 104 | - GCHandle gc = AllocGCHandle(TrackTypes.Extension); | ||
| 105 | - Marshal.WriteIntPtr(pyHandle, ObjectOffset.magic(tpHandle), (IntPtr)gc); | ||
| 106 | - Runtime.PyObject_GC_UnTrack(pyHandle); | ||
| 109 | + SetupGc(); | ||
| 107 | 110 | } | |
| 108 | 111 | } | |
| 109 | 112 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments