Explore Enterprise Education Gitee Premium Gitee AI AI teammates
Fetch the repository succeeded.
Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
Already have an account? Sign in
文件
master
Branches (11)
Tags (29)
master
fix-binaryformatter-usage
compare-maybetype-by-name
python3.13
noncopyableanalyzer
null-check-before-bind
python-3.13
linting-and-formatting
gitpod
backports-2.5
improve-ci
v3.0.4
v3.0.3
v3.0.2
v3.0.1
v3.0.0-r1
v3.0.0
v3.0.0-rc6
v3.0.0-rc5
v3.0.0-rc4
v3.0.0-rc3
v3.0.0-rc2
v3.0.0-rc1
v3.0.0-a2
v3.0.0-a1
v2.5.2
v2.5.1
v2.5.0
v2.5.0-rc1
v2.4.0
v2.4.0-rc2
master
Branches (11)
Tags (29)
master
fix-binaryformatter-usage
compare-maybetype-by-name
python3.13
noncopyableanalyzer
null-check-before-bind
python-3.13
linting-and-formatting
gitpod
backports-2.5
improve-ci
v3.0.4
v3.0.3
v3.0.2
v3.0.1
v3.0.0-r1
v3.0.0
v3.0.0-rc6
v3.0.0-rc5
v3.0.0-rc4
v3.0.0-rc3
v3.0.0-rc2
v3.0.0-rc1
v3.0.0-a2
v3.0.0-a1
v2.5.2
v2.5.1
v2.5.0
v2.5.0-rc1
v2.4.0
v2.4.0-rc2
Clone or Download
Clone/Download
Prompt
To download the code, please copy the following command and execute it in the terminal
To ensure that your submitted code identity is correctly recognized by Gitee, please execute the following command.
When using the SSH protocol for the first time to clone or push code, follow the prompts below to complete the SSH configuration.
1 Generate RSA keys.
2 Obtain the content of the RSA public key and configure it in SSH Public Keys
To use SVN on Gitee, please visit the usage guide
When using the HTTPS protocol, the command line will prompt for account and password verification as follows. For security reasons, Gitee recommends configure and use personal access tokens instead of login passwords for cloning, pushing, and other operations.
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # Private Token
master
Branches (11)
Tags (29)
master
fix-binaryformatter-usage
compare-maybetype-by-name
python3.13
noncopyableanalyzer
null-check-before-bind
python-3.13
linting-and-formatting
gitpod
backports-2.5
improve-ci
v3.0.4
v3.0.3
v3.0.2
v3.0.1
v3.0.0-r1
v3.0.0
v3.0.0-rc6
v3.0.0-rc5
v3.0.0-rc4
v3.0.0-rc3
v3.0.0-rc2
v3.0.0-rc1
v3.0.0-a2
v3.0.0-a1
v2.5.2
v2.5.1
v2.5.0
v2.5.0-rc1
v2.4.0
v2.4.0-rc2
pythonnet
/
src
/
runtime
/
Interop.cs
pythonnet
/
src
/
runtime
/
Interop.cs
Interop.cs 6.95 KB
Copy Edit Raw Blame History
Benedikt Reinartz authored 2022年03月30日 21:29 +08:00 . Modernise syntax a bit
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using Python.Runtime.Reflection;
using System.Reflection;
namespace Python.Runtime
{
/// <summary>
/// This file defines objects to support binary interop with the Python
/// runtime. Generally, the definitions here need to be kept up to date
/// when moving to new Python versions.
/// </summary>
[Serializable]
[AttributeUsage(AttributeTargets.All)]
public class DocStringAttribute : Attribute
{
public DocStringAttribute(string docStr)
{
DocString = docStr;
}
public string DocString { get; }
}
[Serializable]
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Delegate)]
internal class ModuleFunctionAttribute : Attribute
{
public ModuleFunctionAttribute()
{
}
}
[Serializable]
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Delegate)]
internal class ForbidPythonThreadsAttribute : Attribute
{
public ForbidPythonThreadsAttribute()
{
}
}
[Serializable]
[AttributeUsage(AttributeTargets.Property)]
internal class ModulePropertyAttribute : Attribute
{
public ModulePropertyAttribute()
{
}
}
/// <summary>
/// TypeFlags(): The actual bit values for the Type Flags stored
/// in a class.
/// Note that the two values reserved for stackless have been put
/// to good use as PythonNet specific flags (Managed and Subclass)
/// </summary>
// Py_TPFLAGS_*
[Flags]
public enum TypeFlags: long
{
HeapType = (1 << 9),
BaseType = (1 << 10),
Ready = (1 << 12),
Readying = (1 << 13),
HaveGC = (1 << 14),
// 15 and 16 are reserved for stackless
HaveStacklessExtension = 0,
/* XXX Reusing reserved constants */
/// <remarks>PythonNet specific</remarks>
HasClrInstance = (1 << 15),
/// <remarks>PythonNet specific</remarks>
Subclass = (1 << 16),
/* Objects support nb_index in PyNumberMethods */
HaveVersionTag = (1 << 18),
ValidVersionTag = (1 << 19),
IsAbstract = (1 << 20),
HaveNewBuffer = (1 << 21),
// TODO: Implement FastSubclass functions
IntSubclass = (1 << 23),
LongSubclass = (1 << 24),
ListSubclass = (1 << 25),
TupleSubclass = (1 << 26),
StringSubclass = (1 << 27),
UnicodeSubclass = (1 << 28),
DictSubclass = (1 << 29),
BaseExceptionSubclass = (1 << 30),
TypeSubclass = (1 << 31),
Default = (
HaveStacklessExtension |
HaveVersionTag),
}
// This class defines the function prototypes (delegates) used for low
// level integration with the CPython runtime. It also provides name
// based lookup of the correct prototype for a particular Python type
// slot and utilities for generating method thunks for managed methods.
internal class Interop
{
static readonly Dictionary<MethodInfo, Type> delegateTypes = new();
internal static Type GetPrototype(MethodInfo method)
{
if (delegateTypes.TryGetValue(method, out var delegateType))
return delegateType;
var parameters = method.GetParameters().Select(p => new ParameterHelper(p)).ToArray();
foreach (var candidate in typeof(Interop).GetNestedTypes())
{
if (!typeof(Delegate).IsAssignableFrom(candidate))
continue;
MethodInfo invoke = candidate.GetMethod("Invoke");
var candiateParameters = invoke.GetParameters();
if (candiateParameters.Length != parameters.Length)
continue;
var parametersMatch = parameters.Zip(candiateParameters,
(expected, actual) => expected.Matches(actual))
.All(matches => matches);
if (!parametersMatch) continue;
if (invoke.ReturnType != method.ReturnType) continue;
delegateTypes.Add(method, candidate);
return candidate;
}
throw new NotImplementedException(method.ToString());
}
internal static Dictionary<IntPtr, Delegate> allocatedThunks = new();
internal static ThunkInfo GetThunk(MethodInfo method)
{
Type dt = GetPrototype(method);
Delegate d = Delegate.CreateDelegate(dt, method);
return GetThunk(d);
}
internal static ThunkInfo GetThunk(Delegate @delegate)
{
var info = new ThunkInfo(@delegate);
allocatedThunks[info.Address] = @delegate;
return info;
}
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate NewReference B_N(BorrowedReference ob);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate NewReference BB_N(BorrowedReference ob, BorrowedReference a);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate NewReference BBB_N(BorrowedReference ob, BorrowedReference a1, BorrowedReference a2);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate int B_I32(BorrowedReference ob);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate int BB_I32(BorrowedReference ob, BorrowedReference a);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate int BBB_I32(BorrowedReference ob, BorrowedReference a1, BorrowedReference a2);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate int BP_I32(BorrowedReference ob, IntPtr arg);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate IntPtr B_P(BorrowedReference ob);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate NewReference BBI32_N(BorrowedReference ob, BorrowedReference a1, int a2);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate NewReference BP_N(BorrowedReference ob, IntPtr arg);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void N_V(NewReference ob);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate int BPP_I32(BorrowedReference ob, IntPtr a1, IntPtr a2);
}
internal class ThunkInfo
{
public readonly Delegate Target;
public readonly IntPtr Address;
public ThunkInfo(Delegate target)
{
Debug.Assert(target is not null);
Target = target!;
Address = Marshal.GetFunctionPointerForDelegate(target);
}
}
[StructLayout(LayoutKind.Sequential)]
struct PyMethodDef
{
public IntPtr ml_name;
public IntPtr ml_meth;
public int ml_flags;
public IntPtr ml_doc;
}
}
Loading...
Report
Report success
We will send you the feedback within 2 working days through the letter!
Please fill in the reason for the report carefully. Provide as detailed a description as possible.
Please select a report type
Cancel
Send
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

Releases

No release

Contributors

All

Language(Optional)

Activities

can not load any more
Edit
About
Homepage
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C#
1
https://gitee.com/MicroDistanceStudio/pythonnet.git
git@gitee.com:MicroDistanceStudio/pythonnet.git
MicroDistanceStudio
pythonnet
pythonnet
master
Going to Help Center

Search

Comment
Repository Report
Back to the top
Login prompt
This operation requires login to the code cloud account. Please log in before operating.
Go to login
No account. Register

AltStyle によって変換されたページ (->オリジナル) /