| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -299,29 +299,9 @@ public static int tp_clear(IntPtr ob) | |||
| 299 | 299 | { | |
| 300 | 300 | ClearObjectDict(ob); | |
| 301 | 301 | } | |
| 302 | + self.tpHandle = IntPtr.Zero; | ||
| 302 | 303 | Runtime.Py_CLEAR(ref self.tpHandle); | |
| 303 | 304 | return 0; | |
| 304 | 305 | } | |
| 305 | - | ||
| 306 | - private static IntPtr GetObjectDict(IntPtr ob) | ||
| 307 | - { | ||
| 308 | - return Marshal.ReadIntPtr(ob, ObjectOffset.DictOffset(ob)); | ||
| 309 | - } | ||
| 310 | - | ||
| 311 | - private static void SetObjectDict(IntPtr ob, IntPtr value) | ||
| 312 | - { | ||
| 313 | - Marshal.WriteIntPtr(ob, ObjectOffset.DictOffset(ob), value); | ||
| 314 | - } | ||
| 315 | - | ||
| 316 | - private static void ClearObjectDict(IntPtr ob) | ||
| 317 | - { | ||
| 318 | - IntPtr dict = GetObjectDict(ob); | ||
| 319 | - if (dict == IntPtr.Zero) | ||
| 320 | - { | ||
| 321 | - return; | ||
| 322 | - } | ||
| 323 | - SetObjectDict(ob, IntPtr.Zero); | ||
| 324 | - Runtime.XDecref(dict); | ||
| 325 | - } | ||
| 326 | 306 | } | |
| 327 | 307 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -53,9 +53,9 @@ internal static void RemoveClasses() | |||
| 53 | 53 | { | |
| 54 | 54 | foreach (var cls in cache.Values) | |
| 55 | 55 | { | |
| 56 | - cls.TypeTraverse(OnVisit, visitedPtr); | ||
| 56 | + cls.CallTypeTraverse(OnVisit, visitedPtr); | ||
| 57 | 57 | // XXX: Force release instance resources but not dealloc itself. | |
| 58 | - cls.TypeClear(); | ||
| 58 | + cls.CallTypeClear(); | ||
| 59 | 59 | } | |
| 60 | 60 | } | |
| 61 | 61 | finally | |
@@ -75,8 +75,8 @@ private static int OnVisit(IntPtr ob, IntPtr arg) | |||
| 75 | 75 | var clrObj = ManagedType.GetManagedObject(ob); | |
| 76 | 76 | if (clrObj != null) | |
| 77 | 77 | { | |
| 78 | - clrObj.TypeTraverse(OnVisit, arg); | ||
| 79 | - clrObj.TypeClear(); | ||
| 78 | + clrObj.CallTypeTraverse(OnVisit, arg); | ||
| 79 | + clrObj.CallTypeClear(); | ||
| 80 | 80 | } | |
| 81 | 81 | return 0; | |
| 82 | 82 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -49,6 +49,7 @@ public ExtensionType() | |||
| 49 | 49 | /// </summary> | |
| 50 | 50 | public static void FinalizeObject(ManagedType self) | |
| 51 | 51 | { | |
| 52 | + ClearObjectDict(self.pyHandle); | ||
| 52 | 53 | Runtime.PyObject_GC_Del(self.pyHandle); | |
| 53 | 54 | // Not necessary for decref of `tpHandle`. | |
| 54 | 55 | self.FreeGCHandle(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -149,7 +149,7 @@ internal static int PyVisit(IntPtr ob, IntPtr visit, IntPtr arg) | |||
| 149 | 149 | /// <summary> | |
| 150 | 150 | /// Wrapper for calling tp_clear | |
| 151 | 151 | /// </summary> | |
| 152 | - internal void TypeClear() | ||
| 152 | + internal void CallTypeClear() | ||
| 153 | 153 | { | |
| 154 | 154 | if (tpHandle == IntPtr.Zero || pyHandle == IntPtr.Zero) | |
| 155 | 155 | { | |
@@ -168,7 +168,7 @@ internal void TypeClear() | |||
| 168 | 168 | /// <summary> | |
| 169 | 169 | /// Wrapper for calling tp_traverse | |
| 170 | 170 | /// </summary> | |
| 171 | - internal void TypeTraverse(Interop.ObjObjFunc visitproc, IntPtr arg) | ||
| 171 | + internal void CallTypeTraverse(Interop.ObjObjFunc visitproc, IntPtr arg) | ||
| 172 | 172 | { | |
| 173 | 173 | if (tpHandle == IntPtr.Zero || pyHandle == IntPtr.Zero) | |
| 174 | 174 | { | |
@@ -184,5 +184,31 @@ internal void TypeTraverse(Interop.ObjObjFunc visitproc, IntPtr arg) | |||
| 184 | 184 | // TODO: Handle errors base on return value | |
| 185 | 185 | traverseFunc(pyHandle, visiPtr, arg); | |
| 186 | 186 | } | |
| 187 | + | ||
| 188 | + protected void TypeClear() | ||
| 189 | + { | ||
| 190 | + ClearObjectDict(pyHandle); | ||
| 191 | + } | ||
| 192 | + | ||
| 193 | + protected static void ClearObjectDict(IntPtr ob) | ||
| 194 | + { | ||
| 195 | + IntPtr dict = GetObjectDict(ob); | ||
| 196 | + if (dict == IntPtr.Zero) | ||
| 197 | + { | ||
| 198 | + return; | ||
| 199 | + } | ||
| 200 | + SetObjectDict(ob, IntPtr.Zero); | ||
| 201 | + Runtime.XDecref(dict); | ||
| 202 | + } | ||
| 203 | + | ||
| 204 | + private static IntPtr GetObjectDict(IntPtr ob) | ||
| 205 | + { | ||
| 206 | + return Marshal.ReadIntPtr(ob, ObjectOffset.DictOffset(ob)); | ||
| 207 | + } | ||
| 208 | + | ||
| 209 | + private static void SetObjectDict(IntPtr ob, IntPtr value) | ||
| 210 | + { | ||
| 211 | + Marshal.WriteIntPtr(ob, ObjectOffset.DictOffset(ob), value); | ||
| 212 | + } | ||
| 187 | 213 | } | |
| 188 | 214 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -208,13 +208,15 @@ public static IntPtr tp_repr(IntPtr ob) | |||
| 208 | 208 | { | |
| 209 | 209 | var self = (MethodObject)GetManagedObject(ob); | |
| 210 | 210 | self.ClearMembers(); | |
| 211 | + ClearObjectDict(ob); | ||
| 211 | 212 | self.Dealloc(); | |
| 212 | 213 | } | |
| 213 | 214 | ||
| 214 | 215 | public static int tp_clear(IntPtr ob) | |
| 215 | 216 | { | |
| 216 | 217 | var self = (MethodObject)GetManagedObject(ob); | |
| 217 | 218 | self.ClearMembers(); | |
| 219 | + ClearObjectDict(ob); | ||
| 218 | 220 | return 0; | |
| 219 | 221 | } | |
| 220 | 222 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -277,9 +277,8 @@ public PyObject Eval(string code, PyDict locals = null) | |||
| 277 | 277 | { | |
| 278 | 278 | Check(); | |
| 279 | 279 | IntPtr _locals = locals == null ? variables : locals.obj; | |
| 280 | - var flag = (IntPtr)Runtime.Py_eval_input; | ||
| 281 | 280 | IntPtr ptr = Runtime.PyRun_String( | |
| 282 | - code, flag, variables, _locals | ||
| 281 | + code, RunFlagType.Eval, variables, _locals | ||
| 283 | 282 | ); | |
| 284 | 283 | Runtime.CheckExceptionOccurred(); | |
| 285 | 284 | return new PyObject(ptr); | |
@@ -315,9 +314,8 @@ public void Exec(string code, PyDict locals = null) | |||
| 315 | 314 | ||
| 316 | 315 | private void Exec(string code, IntPtr _globals, IntPtr _locals) | |
| 317 | 316 | { | |
| 318 | - var flag = (IntPtr)Runtime.Py_file_input; | ||
| 319 | 317 | IntPtr ptr = Runtime.PyRun_String( | |
| 320 | - code, flag, _globals, _locals | ||
| 318 | + code, RunFlagType.File, _globals, _locals | ||
| 321 | 319 | ); | |
| 322 | 320 | Runtime.CheckExceptionOccurred(); | |
| 323 | 321 | if (ptr != Runtime.PyNone) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -600,7 +600,7 @@ internal static PyObject RunString(string code, IntPtr? globals, IntPtr? locals, | |||
| 600 | 600 | try | |
| 601 | 601 | { | |
| 602 | 602 | IntPtr result = Runtime.PyRun_String( | |
| 603 | - code, (IntPtr)flag, globals.Value, locals.Value | ||
| 603 | + code, flag, globals.Value, locals.Value | ||
| 604 | 604 | ); | |
| 605 | 605 | ||
| 606 | 606 | Runtime.CheckExceptionOccurred(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -209,7 +209,7 @@ internal static void Initialize(bool initSigs = false, bool softShutdown = false | |||
| 209 | 209 | PyScopeManager.Reset(); | |
| 210 | 210 | ClassManager.Reset(); | |
| 211 | 211 | ClassDerivedObject.Reset(); | |
| 212 | - TypeManager.Reset(); | ||
| 212 | + TypeManager.Initialize(); | ||
| 213 | 213 | ||
| 214 | 214 | IntPtr op; | |
| 215 | 215 | { | |
@@ -527,7 +527,7 @@ private static void MoveClrInstancesOnwershipToPython() | |||
| 527 | 527 | { | |
| 528 | 528 | continue; | |
| 529 | 529 | } | |
| 530 | - obj.TypeClear(); | ||
| 530 | + obj.CallTypeClear(); | ||
| 531 | 531 | // obj's tp_type will degenerate to a pure Python type after TypeManager.RemoveTypes(), | |
| 532 | 532 | // thus just be safe to give it back to GC chain. | |
| 533 | 533 | PyObject_GC_Track(obj.pyHandle); | |
@@ -537,11 +537,6 @@ private static void MoveClrInstancesOnwershipToPython() | |||
| 537 | 537 | ManagedType.ClearTrackedObjects(); | |
| 538 | 538 | } | |
| 539 | 539 | ||
| 540 | - | ||
| 541 | - internal static IntPtr Py_single_input = (IntPtr)256; | ||
| 542 | - internal static IntPtr Py_file_input = (IntPtr)257; | ||
| 543 | - internal static IntPtr Py_eval_input = (IntPtr)258; | ||
| 544 | - | ||
| 545 | 540 | internal static IntPtr PyBaseObjectType; | |
| 546 | 541 | internal static IntPtr PyModuleType; | |
| 547 | 542 | internal static IntPtr PyClassType; | |
@@ -903,7 +898,7 @@ public static extern int Py_Main( | |||
| 903 | 898 | internal static extern int PyRun_SimpleString(string code); | |
| 904 | 899 | ||
| 905 | 900 | [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] | |
| 906 | - internal static extern IntPtr PyRun_String(string code, IntPtr st, IntPtr globals, IntPtr locals); | ||
| 901 | + internal static extern IntPtr PyRun_String(string code, RunFlagType st, IntPtr globals, IntPtr locals); | ||
| 907 | 902 | ||
| 908 | 903 | [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] | |
| 909 | 904 | internal static extern IntPtr PyEval_EvalCode(IntPtr co, IntPtr globals, IntPtr locals); | |
@@ -2013,7 +2008,7 @@ internal static IntPtr PyType_GenericAlloc(IntPtr type, long n) | |||
| 2013 | 2008 | private static extern IntPtr PyType_GenericAlloc(IntPtr type, IntPtr n); | |
| 2014 | 2009 | ||
| 2015 | 2010 | /// <summary> | |
| 2016 | - /// Finalize a type object. This should be called on all type objects to finish their initialization. This function is responsible for adding inherited slots from a type¡¯s base class. Return 0 on success, or return -1 and sets an exception on error. | ||
| 2011 | + /// Finalize a type object. This should be called on all type objects to finish their initialization. This function is responsible for adding inherited slots from a type’s base class. Return 0 on success, or return -1 and sets an exception on error. | ||
| 2017 | 2012 | /// </summary> | |
| 2018 | 2013 | [DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)] | |
| 2019 | 2014 | internal static extern int PyType_Ready(IntPtr type); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments