Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitce3d6b4

Browse files
committed
Use get_ident and LLP64 and LP64 in DllImport names and ulong in public methods and assert nativeThreadID value
1 parent3fa42f8 commitce3d6b4

File tree

4 files changed

+11
-61
lines changed

4 files changed

+11
-61
lines changed

‎CHANGELOG.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,8 @@ This document follows the conventions laid out in [Keep a CHANGELOG][].
1010
###Added
1111

1212
- Ability to instantiate new .NET arrays using`Array[T](dim1, dim2, ...)` syntax
13-
<<<<<<< HEAD
14-
<<<<<<< HEAD
1513
- Python operator method will call C# operator method for supported binary and unary operators ([#1324][p1324]).
16-
=======
17-
- Add Interrupt method in PythonEngine
18-
>>>>>>>Add Interrupt method in PythonEngine
19-
=======
2014
- Add GetNativeThreadID and Interrupt methods in PythonEngine
21-
>>>>>>>Add GetNativeThreadID method in PythonEngine and different PyThreadState_SetAsyncExc calls for OS and Python version
2215

2316
###Changed
2417
- Drop support for Python 2, 3.4, and 3.5

‎src/embed_tests/TestInterrupt.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public void Dispose()
3131
publicvoidInterruptTest()
3232
{
3333
intrunSimpleStringReturnValue=int.MinValue;
34-
uintnativeThreadID=uint.MinValue;
34+
ulongnativeThreadID=ulong.MinValue;
3535
Task.Factory.StartNew(()=>
3636
{
3737
using(Py.GIL())
@@ -47,6 +47,8 @@ import time
4747

4848
Thread.Sleep(200);
4949

50+
Assert.AreNotEqual(ulong.MinValue,nativeThreadID);
51+
5052
using(Py.GIL())
5153
{
5254
intinterruptReturnValue=PythonEngine.Interrupt(nativeThreadID);

‎src/runtime/pythonengine.cs

Lines changed: 6 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,6 @@ namespace Python.Runtime
1212
/// </summary>
1313
publicclassPythonEngine:IDisposable
1414
{
15-
[DllImport("Kernel32",EntryPoint="GetCurrentThreadId",ExactSpelling=true)]
16-
privatestaticexternuintGetCurrentThreadId();
17-
18-
[DllImport("libc",EntryPoint="pthread_self")]
19-
privatestaticexternUIntPtrpthread_selfLinux();
20-
21-
[DllImport("pthread",EntryPoint="pthread_self",CallingConvention=CallingConvention.Cdecl)]
22-
privatestaticexternuintpthread_selfOSX();
23-
2415
publicstaticShutdownModeShutdownMode
2516
{
2617
get=>Runtime.ShutdownMode;
@@ -580,55 +571,25 @@ public static void Exec(string code, IntPtr? globals = null, IntPtr? locals = nu
580571
/// Gets the native thread ID.
581572
/// </summary>
582573
/// <returns>The native thread ID.</returns>
583-
publicstaticuintGetNativeThreadID()
574+
publicstaticulongGetNativeThreadID()
584575
{
585-
if(Runtime.PyVersion>=newVersion(3,8))
586-
{
587-
dynamicthreading=Py.Import("threading");
588-
returnthreading.get_native_id();
589-
}
590-
591-
if(RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
592-
{
593-
returnGetCurrentThreadId();
594-
}
595-
596-
if(RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
597-
{
598-
returnpthread_selfLinux().ToUInt32();
599-
}
600-
601-
if(RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
602-
{
603-
returnpthread_selfOSX();
604-
}
605-
606-
thrownewInvalidOperationException("Could not retrieve native thread ID.");
576+
dynamicthreading=Py.Import("threading");
577+
returnthreading.get_ident();
607578
}
608579

609580
/// <summary>
610581
/// Interrupts the execution of a thread.
611582
/// </summary>
612583
/// <param name="nativeThreadID">The native thread ID.</param>
613584
/// <returns>The number of thread states modified; this is normally one, but will be zero if the thread id isn’t found.</returns>
614-
publicstaticintInterrupt(uintnativeThreadID)
585+
publicstaticintInterrupt(ulongnativeThreadID)
615586
{
616-
if(Runtime.PyVersion>=newVersion(3,7))
617-
{
618-
if(RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
619-
{
620-
returnRuntime.PyThreadState_SetAsyncExc37Windows(nativeThreadID,Exceptions.KeyboardInterrupt);
621-
}
622-
623-
returnRuntime.PyThreadState_SetAsyncExc37NonWindows(newUIntPtr(nativeThreadID),Exceptions.KeyboardInterrupt);
624-
}
625-
626587
if(RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
627588
{
628-
returnRuntime.PyThreadState_SetAsyncExc36Windows((int)nativeThreadID,Exceptions.KeyboardInterrupt);
589+
returnRuntime.PyThreadState_SetAsyncExcLLP64((uint)nativeThreadID,Exceptions.KeyboardInterrupt);
629590
}
630591

631-
returnRuntime.PyThreadState_SetAsyncExc36NonWindows(newIntPtr(nativeThreadID),Exceptions.KeyboardInterrupt);
592+
returnRuntime.PyThreadState_SetAsyncExcLP64(nativeThreadID,Exceptions.KeyboardInterrupt);
632593
}
633594

634595
/// <summary>

‎src/runtime/runtime.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2147,16 +2147,10 @@ internal static void Py_CLEAR(ref IntPtr ob)
21472147
internalstaticexternint Py_AddPendingCall(IntPtr func, IntPtr arg);
21482148

21492149
[DllImport(_PythonDll, EntryPoint= "PyThreadState_SetAsyncExc", CallingConvention= CallingConvention.Cdecl)]
2150-
internalstaticexternintPyThreadState_SetAsyncExc37Windows(uint id, IntPtr exc);
2150+
internalstaticexternintPyThreadState_SetAsyncExcLLP64(uint id, IntPtr exc);
21512151

21522152
[DllImport(_PythonDll, EntryPoint= "PyThreadState_SetAsyncExc", CallingConvention= CallingConvention.Cdecl)]
2153-
internalstaticexternint PyThreadState_SetAsyncExc36Windows(int id, IntPtr exc);
2154-
2155-
[DllImport(_PythonDll, EntryPoint= "PyThreadState_SetAsyncExc", CallingConvention= CallingConvention.Cdecl)]
2156-
internalstaticexternint PyThreadState_SetAsyncExc37NonWindows(UIntPtr id, IntPtr exc);
2157-
2158-
[DllImport(_PythonDll, EntryPoint= "PyThreadState_SetAsyncExc", CallingConvention= CallingConvention.Cdecl)]
2159-
internalstaticexternint PyThreadState_SetAsyncExc36NonWindows(IntPtr id, IntPtr exc);
2153+
internalstaticexternint PyThreadState_SetAsyncExcLP64(ulong id, IntPtr exc);
21602154

21612155
[DllImport(_PythonDll, CallingConvention= CallingConvention.Cdecl)]
21622156
internalstaticexternint Py_MakePendingCalls();

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp