- Notifications
You must be signed in to change notification settings - Fork749
Replace magic offsets with proper offset calculation#1441
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,6 @@ | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
namespace Python.Runtime | ||
{ | ||
@@ -355,19 +352,21 @@ public static void tp_dealloc(IntPtr ob) | ||
{ | ||
ManagedType self = GetManagedObject(ob); | ||
tp_clear(ob); | ||
Runtime.PyObject_GC_UnTrack(ob); | ||
Runtime.PyObject_GC_Del(ob); | ||
self?.FreeGCHandle(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Is this expected?/Should this be an error in debug? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I've seen a scenario or two when this happens after | ||
} | ||
public static int tp_clear(IntPtr ob) | ||
{ | ||
ManagedType self = GetManagedObject(ob); | ||
bool isTypeObject = Runtime.PyObject_TYPE(ob) == Runtime.PyCLRMetaType; | ||
if (!isTypeObject) | ||
{ | ||
ClearObjectDict(ob); | ||
} | ||
if (self is not null)self.tpHandle = IntPtr.Zero; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. same as above | ||
return 0; | ||
} | ||
@@ -391,7 +390,7 @@ protected override void OnLoad(InterDomainContext context) | ||
SetObjectDict(pyHandle, dict); | ||
} | ||
gcHandle = AllocGCHandle(); | ||
SetGCHandle(ObjectReference,gcHandle); | ||
} | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -14,26 +14,16 @@ internal CLRObject(object ob, IntPtr tp) | ||
System.Diagnostics.Debug.Assert(tp != IntPtr.Zero); | ||
IntPtr py = Runtime.PyType_GenericAlloc(tp, 0); | ||
tpHandle = tp; | ||
pyHandle = py; | ||
inst = ob; | ||
GCHandle gc = AllocGCHandle(TrackTypes.Wrapper); | ||
InitGCHandle(ObjectReference, type: TypeReference, gc); | ||
// Fix the BaseException args (and __cause__ in case of Python 3) | ||
// slot if wrapping a CLR exception | ||
if (ob is Exception e)Exceptions.SetArgsAndCause(e,py); | ||
} | ||
protected CLRObject() | ||
@@ -78,6 +68,9 @@ internal static IntPtr GetInstHandle(object ob) | ||
return co.pyHandle; | ||
} | ||
internal static NewReference GetReference(object ob) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Should this throw if ob is null? (maybe debug only) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. It does raise a | ||
=> NewReference.DangerousFromPointer(GetInstHandle(ob)); | ||
internal static CLRObject Restore(object ob, IntPtr pyHandle, InterDomainContext context) | ||
{ | ||
CLRObject co = new CLRObject() | ||
@@ -101,7 +94,7 @@ protected override void OnLoad(InterDomainContext context) | ||
{ | ||
base.OnLoad(context); | ||
GCHandle gc = AllocGCHandle(TrackTypes.Wrapper); | ||
SetGCHandle(ObjectReference, TypeReference,gc); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -15,26 +15,6 @@ internal static class ImportHook | ||
private static IntPtr py_clr_module; | ||
static BorrowedReference ClrModuleReference => new BorrowedReference(py_clr_module); | ||
/// <summary> | ||
/// Initialize just the __import__ hook itself. | ||
/// </summary> | ||
@@ -90,8 +70,7 @@ internal static unsafe void Initialize() | ||
root = new CLRModule(); | ||
// create a python module with the same methods as the clr module-like object | ||
py_clr_module = Runtime.PyModule_New("clr").DangerousMoveToPointer(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I'm not entirely sure of the internal differences with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more.
| ||
// both dicts are borrowed references | ||
BorrowedReference mod_dict = Runtime.PyModule_GetDict(ClrModuleReference); | ||
@@ -116,13 +95,8 @@ internal static void Shutdown() | ||
RestoreImport(); | ||
Runtime.XDecref(py_clr_module); | ||
py_clr_module = IntPtr.Zero; | ||
Runtime.XDecref(root.pyHandle); | ||
root = null; | ||
Uh oh!
There was an error while loading.Please reload this page.