-
Notifications
You must be signed in to change notification settings - Fork 772
Modernize import hook #1369
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Modernize import hook #1369
Changes from 1 commit
a321daa
279b535
f92e95b
afffc18
d821c0f
e469a8a
685b972
be81364
73958ed
e71a0ef
2af066d
bb490bf
31ea876
c02d5c6
970a189
059605b
ff170e9
63de923
624f7e3
bd7e745
46a85fe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -174,7 +174,7 @@ internal static void Initialize(bool initSigs = false, ShutdownMode mode = Shutd | |
| IntPtr item = PyString_FromString(rtdir); | ||
| if (PySequence_Contains(path, item) == 0) | ||
| { | ||
| PyList_Append(new BorrowedReference(path), item); | ||
| PyList_Append(new BorrowedReference(path), new BorrowedReference(item)); | ||
| } | ||
| XDecref(item); | ||
| AssemblyManager.UpdatePath(); | ||
|
|
@@ -1087,6 +1087,8 @@ internal static IntPtr PyObject_GetAttr(IntPtr pointer, IntPtr name) | |
|
|
||
|
|
||
| internal static IntPtr PyObject_Call(IntPtr pointer, IntPtr args, IntPtr kw) => Delegates.PyObject_Call(pointer, args, kw); | ||
| internal static IntPtr PyObject_Call(BorrowedReference pointer, BorrowedReference args, BorrowedReference kw) | ||
| => Delegates.PyObject_Call(pointer.DangerousGetAddress(), args.DangerousGetAddress(), kw.DangerousGetAddressOrNull()); | ||
|
|
||
|
|
||
| internal static NewReference PyObject_CallObject(BorrowedReference callable, BorrowedReference args) => Delegates.PyObject_CallObject(callable, args); | ||
|
|
@@ -1822,7 +1824,7 @@ internal static int PyList_Insert(BorrowedReference pointer, long index, IntPtr | |
| private static int PyList_Insert(BorrowedReference pointer, IntPtr index, IntPtr value) => Delegates.PyList_Insert(pointer, index, value); | ||
|
|
||
|
|
||
| internal static int PyList_Append(BorrowedReference pointer, IntPtr value) => Delegates.PyList_Append(pointer, value); | ||
| internal static int PyList_Append(BorrowedReference pointer, BorrowedReference value) => Delegates.PyList_Append(pointer, value); | ||
|
|
||
|
|
||
| internal static int PyList_Reverse(BorrowedReference pointer) => Delegates.PyList_Reverse(pointer); | ||
|
|
@@ -1885,7 +1887,15 @@ internal static int PyTuple_SetItem(IntPtr pointer, long index, IntPtr value) | |
| { | ||
| return PyTuple_SetItem(pointer, new IntPtr(index), value); | ||
| } | ||
| internal static int PyTuple_SetItem(BorrowedReference pointer, long index, StolenReference value) | ||
| => PyTuple_SetItem(pointer.DangerousGetAddress(), new IntPtr(index), value.DangerousGetAddressOrNull()); | ||
|
|
||
| internal static int PyTuple_SetItem(BorrowedReference pointer, long index, BorrowedReference value) | ||
| { | ||
| var increfValue = value.DangerousGetAddress(); | ||
| Runtime.XIncref(increfValue); | ||
| return PyTuple_SetItem(pointer.DangerousGetAddress(), new IntPtr(index), increfValue); | ||
| } | ||
|
|
||
| private static int PyTuple_SetItem(IntPtr pointer, IntPtr index, IntPtr value) => Delegates.PyTuple_SetItem(pointer, index, value); | ||
|
|
||
|
|
@@ -1944,6 +1954,14 @@ internal static string PyModule_GetFilename(IntPtr module) | |
|
|
||
|
|
||
| internal static IntPtr PyImport_Import(IntPtr name) => Delegates.PyImport_Import(name); | ||
|
|
||
| /// <summary> | ||
| /// We can't use a StolenReference here because the reference is stolen only on success. | ||
| /// </summary> | ||
| /// <param name="module">The module to add the object to.</param> | ||
| /// <param name="name">The key that will refer to the object.</param> | ||
| /// <param name="stolenObject">The object to add to the module.</param> | ||
| /// <returns>Return -1 on error, 0 on success.</returns> | ||
| internal static int PyModule_AddObject(BorrowedReference module, string name, BorrowedReference stolenObject) | ||
|
Member
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. Looks like
Contributor
Author
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.
🎉
Contributor
Author
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. Although I'm reviewing the semantics, and this function only steals on success, so by using
Member
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. Dang you are right. Why did they not make it consistent? Maybe we should make a wrapper, that always steals?
Member
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 think that we should not use Or alternatively, make a wrapper, that takes either
Contributor
Author
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 leaning towards the |
||
| { | ||
| using var namePtr = new StrPtr(name, Encoding.UTF8); | ||
|
|
@@ -2483,7 +2501,7 @@ static Delegates() | |
| PyList_GetItem = (delegate* unmanaged[Cdecl]<BorrowedReference, IntPtr, BorrowedReference>)GetFunctionByName(nameof(PyList_GetItem), GetUnmanagedDll(_PythonDll)); | ||
| PyList_SetItem = (delegate* unmanaged[Cdecl]<IntPtr, IntPtr, IntPtr, int>)GetFunctionByName(nameof(PyList_SetItem), GetUnmanagedDll(_PythonDll)); | ||
| PyList_Insert = (delegate* unmanaged[Cdecl]<BorrowedReference, IntPtr, IntPtr, int>)GetFunctionByName(nameof(PyList_Insert), GetUnmanagedDll(_PythonDll)); | ||
| PyList_Append = (delegate* unmanaged[Cdecl]<BorrowedReference, IntPtr, int>)GetFunctionByName(nameof(PyList_Append), GetUnmanagedDll(_PythonDll)); | ||
| PyList_Append = (delegate* unmanaged[Cdecl]<BorrowedReference, BorrowedReference, int>)GetFunctionByName(nameof(PyList_Append), GetUnmanagedDll(_PythonDll)); | ||
| PyList_Reverse = (delegate* unmanaged[Cdecl]<BorrowedReference, int>)GetFunctionByName(nameof(PyList_Reverse), GetUnmanagedDll(_PythonDll)); | ||
| PyList_Sort = (delegate* unmanaged[Cdecl]<BorrowedReference, int>)GetFunctionByName(nameof(PyList_Sort), GetUnmanagedDll(_PythonDll)); | ||
| PyList_GetSlice = (delegate* unmanaged[Cdecl]<IntPtr, IntPtr, IntPtr, IntPtr>)GetFunctionByName(nameof(PyList_GetSlice), GetUnmanagedDll(_PythonDll)); | ||
|
|
@@ -2780,7 +2798,7 @@ static Delegates() | |
| internal static delegate* unmanaged[Cdecl]<BorrowedReference, IntPtr, BorrowedReference> PyList_GetItem { get; } | ||
| internal static delegate* unmanaged[Cdecl]<IntPtr, IntPtr, IntPtr, int> PyList_SetItem { get; } | ||
| internal static delegate* unmanaged[Cdecl]<BorrowedReference, IntPtr, IntPtr, int> PyList_Insert { get; } | ||
| internal static delegate* unmanaged[Cdecl]<BorrowedReference, IntPtr, int> PyList_Append { get; } | ||
| internal static delegate* unmanaged[Cdecl]<BorrowedReference, BorrowedReference, int> PyList_Append { get; } | ||
| internal static delegate* unmanaged[Cdecl]<BorrowedReference, int> PyList_Reverse { get; } | ||
| internal static delegate* unmanaged[Cdecl]<BorrowedReference, int> PyList_Sort { get; } | ||
| internal static delegate* unmanaged[Cdecl]<IntPtr, IntPtr, IntPtr, IntPtr> PyList_GetSlice { get; } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT: