| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent ab33b86 commit 9d0c4e0
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -68,7 +68,7 @@ public void GetPointer() | |||
| 68 | 68 | int[] shape = [10, 10, 10]; | |
| 69 | 69 | PyObject ndArray = np.zeros(shape); | |
| 70 | 70 | ||
| 71 | - PyBuffer buf = ndArray.GetBuffer(PyBUF.ND); | ||
| 71 | + using PyBuffer buf = ndArray.GetBuffer(PyBUF.STRIDED); | ||
| 72 | 72 | ||
| 73 | 73 | // this throws System.ExecutionEngineException | |
| 74 | 74 | var ptr = buf.GetPointer([0, 0, 0]); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,4 +1,5 @@ | |||
| 1 | 1 | using System; | |
| 2 | + using System.Runtime.InteropServices; | ||
| 2 | 3 | ||
| 3 | 4 | using Python.Runtime.Native; | |
| 4 | 5 | using Python.Runtime.Platform; | |
@@ -9,6 +10,9 @@ public unsafe partial class Runtime | |||
| 9 | 10 | { | |
| 10 | 11 | internal static class Delegates | |
| 11 | 12 | { | |
| 13 | + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] | ||
| 14 | + internal delegate IntPtr PyBufferGetPointer(ref Py_buffer view, [MarshalAs(UnmanagedType.LPArray)] nint[] indices); | ||
| 15 | + | ||
| 12 | 16 | static readonly ILibraryLoader libraryLoader = LibraryLoader.Instance; | |
| 13 | 17 | ||
| 14 | 18 | static Delegates() | |
@@ -117,7 +121,7 @@ static Delegates() | |||
| 117 | 121 | // only in 3.9+ | |
| 118 | 122 | } | |
| 119 | 123 | PyBuffer_IsContiguous = (delegate* unmanaged[Cdecl]<ref Py_buffer, char, int>)GetFunctionByName(nameof(PyBuffer_IsContiguous), GetUnmanagedDll(_PythonDll)); | |
| 120 | - PyBuffer_GetPointer = (delegate* unmanaged[Cdecl]<ref Py_buffer, nint*, IntPtr>)GetFunctionByName(nameof(PyBuffer_GetPointer), GetUnmanagedDll(_PythonDll)); | ||
| 124 | + PyBuffer_GetPointer = Marshal.GetDelegateForFunctionPointer<PyBufferGetPointer>(GetFunctionByName(nameof(PyBuffer_GetPointer), GetUnmanagedDll(_PythonDll))); | ||
| 121 | 125 | PyBuffer_FromContiguous = (delegate* unmanaged[Cdecl]<ref Py_buffer, IntPtr, IntPtr, char, int>)GetFunctionByName(nameof(PyBuffer_FromContiguous), GetUnmanagedDll(_PythonDll)); | |
| 122 | 126 | PyBuffer_ToContiguous = (delegate* unmanaged[Cdecl]<IntPtr, ref Py_buffer, IntPtr, char, int>)GetFunctionByName(nameof(PyBuffer_ToContiguous), GetUnmanagedDll(_PythonDll)); | |
| 123 | 127 | PyBuffer_FillContiguousStrides = (delegate* unmanaged[Cdecl]<int, IntPtr, IntPtr, int, char, void>)GetFunctionByName(nameof(PyBuffer_FillContiguousStrides), GetUnmanagedDll(_PythonDll)); | |
@@ -394,7 +398,7 @@ static Delegates() | |||
| 394 | 398 | internal static delegate* unmanaged[Cdecl]<ref Py_buffer, void> PyBuffer_Release { get; } | |
| 395 | 399 | internal static delegate* unmanaged[Cdecl]<StrPtr, nint> PyBuffer_SizeFromFormat { get; } | |
| 396 | 400 | internal static delegate* unmanaged[Cdecl]<ref Py_buffer, char, int> PyBuffer_IsContiguous { get; } | |
| 397 | - internal static delegate* unmanaged[Cdecl]<ref Py_buffer, nint*, IntPtr> PyBuffer_GetPointer { get; } | ||
| 401 | + internal static PyBufferGetPointer PyBuffer_GetPointer { get; } | ||
| 398 | 402 | internal static delegate* unmanaged[Cdecl]<ref Py_buffer, IntPtr, IntPtr, char, int> PyBuffer_FromContiguous { get; } | |
| 399 | 403 | internal static delegate* unmanaged[Cdecl]<IntPtr, ref Py_buffer, IntPtr, char, int> PyBuffer_ToContiguous { get; } | |
| 400 | 404 | internal static delegate* unmanaged[Cdecl]<int, IntPtr, IntPtr, int, char, void> PyBuffer_FillContiguousStrides { get; } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1017,13 +1017,7 @@ internal static nint PyBuffer_SizeFromFormat(string format) | |||
| 1017 | 1017 | internal static int PyBuffer_IsContiguous(ref Py_buffer view, char order) => Delegates.PyBuffer_IsContiguous(ref view, order); | |
| 1018 | 1018 | ||
| 1019 | 1019 | ||
| 1020 | - internal static IntPtr PyBuffer_GetPointer(ref Py_buffer view, nint[] indices) | ||
| 1021 | - { | ||
| 1022 | - fixed (nint* indicesPtr = indices) | ||
| 1023 | - { | ||
| 1024 | - return Delegates.PyBuffer_GetPointer(ref view, indicesPtr); | ||
| 1025 | - } | ||
| 1026 | - } | ||
| 1020 | + internal static IntPtr PyBuffer_GetPointer(ref Py_buffer view, nint[] indices) => Delegates.PyBuffer_GetPointer(ref view, indices); | ||
| 1027 | 1021 | ||
| 1028 | 1022 | ||
| 1029 | 1023 | internal static int PyBuffer_FromContiguous(ref Py_buffer view, IntPtr buf, IntPtr len, char fort) => Delegates.PyBuffer_FromContiguous(ref view, buf, len, fort); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments