| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -51,13 +51,12 @@ public static void FinalizeObject(ManagedType self) | |||
| 51 | 51 | { | |
| 52 | 52 | Runtime.PyObject_GC_Del(self.pyHandle); | |
| 53 | 53 | // Not necessary for decref of `tpHandle`. | |
| 54 | - self.gcHandle.Free(); | ||
| 54 | + self.FreeGCHandle(); | ||
| 55 | 55 | } | |
| 56 | 56 | ||
| 57 | 57 | protected void Dealloc() | |
| 58 | 58 | { | |
| 59 | 59 | FinalizeObject(this); | |
| 60 | - FreeGCHandle(); | ||
| 61 | 60 | } | |
| 62 | 61 | ||
| 63 | 62 | /// <summary> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -19,6 +19,11 @@ internal abstract class ManagedType | |||
| 19 | 19 | ||
| 20 | 20 | private static readonly HashSet<ManagedType> _managedObjs = new HashSet<ManagedType>(); | |
| 21 | 21 | ||
| 22 | + internal void IncrRefCount() | ||
| 23 | + { | ||
| 24 | + Runtime.XIncref(pyHandle); | ||
| 25 | + } | ||
| 26 | + | ||
| 22 | 27 | internal void DecrRefCount() | |
| 23 | 28 | { | |
| 24 | 29 | Runtime.XDecref(pyHandle); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -174,7 +174,11 @@ public ManagedType GetAttribute(string name, bool guess) | |||
| 174 | 174 | /// </summary> | |
| 175 | 175 | private void StoreAttribute(string name, ManagedType ob) | |
| 176 | 176 | { | |
| 177 | - Runtime.PyDict_SetItemString(dict, name, ob.pyHandle); | ||
| 177 | + if (Runtime.PyDict_SetItemString(dict, name, ob.pyHandle) != 0) | ||
| 178 | + { | ||
| 179 | + throw new PythonException(); | ||
| 180 | + } | ||
| 181 | + ob.IncrRefCount(); | ||
| 178 | 182 | cache[name] = ob; | |
| 179 | 183 | } | |
| 180 | 184 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -17,14 +17,9 @@ namespace Python.Runtime | |||
| 17 | 17 | /// </summary> | |
| 18 | 18 | internal class TypeManager | |
| 19 | 19 | { | |
| 20 | - private static BindingFlags tbFlags; | ||
| 20 | + private const BindingFlags tbFlags = BindingFlags.Public | BindingFlags.Static; | ||
| 21 | 21 | private static Dictionary<Type, IntPtr> cache; | |
| 22 | 22 | ||
| 23 | - static TypeManager() | ||
| 24 | - { | ||
| 25 | - tbFlags = BindingFlags.Public | BindingFlags.Static; | ||
| 26 | - } | ||
| 27 | - | ||
| 28 | 23 | public static void Reset() | |
| 29 | 24 | { | |
| 30 | 25 | cache = new Dictionary<Type, IntPtr>(128); | |
@@ -74,6 +69,7 @@ internal static IntPtr GetTypeHandle(Type type) | |||
| 74 | 69 | ||
| 75 | 70 | ||
| 76 | 71 | /// <summary> | |
| 72 | + /// Return value: Borrowed reference. | ||
| 77 | 73 | /// Get the handle of a Python type that reflects the given CLR type. | |
| 78 | 74 | /// The given ManagedType instance is a managed object that implements | |
| 79 | 75 | /// the appropriate semantics in Python for the reflected managed type. | |
@@ -311,7 +307,7 @@ internal static IntPtr CreateSubType(IntPtr py_name, IntPtr py_base_type, IntPtr | |||
| 311 | 307 | // derived class we want the python overrides in there instead if they exist. | |
| 312 | 308 | IntPtr cls_dict = Marshal.ReadIntPtr(py_type, TypeOffset.tp_dict); | |
| 313 | 309 | Runtime.PyDict_Update(cls_dict, py_dict); | |
| 314 | - | ||
| 310 | + Runtime.XIncref(py_type); | ||
| 315 | 311 | return py_type; | |
| 316 | 312 | } | |
| 317 | 313 | catch (Exception e) | |
@@ -1075,7 +1071,9 @@ private void ResetSlots() | |||
| 1075 | 1071 | foreach (var offset in _slots.Keys) | |
| 1076 | 1072 | { | |
| 1077 | 1073 | IntPtr ptr = GetDefaultSlot(offset); | |
| 1074 | + #if DEBUG | ||
| 1078 | 1075 | //DebugUtil.Print($"Set slot<{TypeOffsetHelper.GetSlotNameByOffset(offset)}> to 0x{ptr.ToString("X")} at {typeName}<0x{_type}>"); | |
| 1076 | + #endif | ||
| 1079 | 1077 | Marshal.WriteIntPtr(_type, offset, ptr); | |
| 1080 | 1078 | } | |
| 1081 | 1079 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments