Skip to content

Commit 3fa42f8

Browse files
committed
Fix DllImport declarations
1 parent fde3454 commit 3fa42f8

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

src/embed_tests/TestInterrupt.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ public void Dispose()
3131
public void InterruptTest()
3232
{
3333
int runSimpleStringReturnValue = int.MinValue;
34-
ulong nativeThreadId = 0;
34+
uint nativeThreadID = uint.MinValue;
3535
Task.Factory.StartNew(() =>
3636
{
3737
using (Py.GIL())
3838
{
39-
nativeThreadId = PythonEngine.GetNativeThreadID();
39+
nativeThreadID = PythonEngine.GetNativeThreadID();
4040
runSimpleStringReturnValue = PythonEngine.RunSimpleString(@"
4141
import time
4242
@@ -49,11 +49,11 @@ import time
4949

5050
using (Py.GIL())
5151
{
52-
int interruptReturnValue = PythonEngine.Interrupt(nativeThreadId);
52+
int interruptReturnValue = PythonEngine.Interrupt(nativeThreadID);
5353
Assert.AreEqual(1, interruptReturnValue);
5454
}
5555

56-
Thread.Sleep(500);
56+
Thread.Sleep(300);
5757

5858
Assert.AreEqual(-1, runSimpleStringReturnValue);
5959
}

src/runtime/pythonengine.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ public class PythonEngine : IDisposable
1616
private static extern uint GetCurrentThreadId();
1717

1818
[DllImport("libc", EntryPoint = "pthread_self")]
19-
private static extern IntPtr pthread_selfLinux();
19+
private static extern UIntPtr pthread_selfLinux();
2020

2121
[DllImport("pthread", EntryPoint = "pthread_self", CallingConvention = CallingConvention.Cdecl)]
22-
private static extern ulong pthread_selfOSX();
22+
private static extern uint pthread_selfOSX();
2323

2424
public static ShutdownMode ShutdownMode
2525
{
@@ -580,7 +580,7 @@ public static void Exec(string code, IntPtr? globals = null, IntPtr? locals = nu
580580
/// Gets the native thread ID.
581581
/// </summary>
582582
/// <returns>The native thread ID.</returns>
583-
public static ulong GetNativeThreadID()
583+
public static uint GetNativeThreadID()
584584
{
585585
if (Runtime.PyVersion >= new Version(3, 8))
586586
{
@@ -595,7 +595,7 @@ public static ulong GetNativeThreadID()
595595

596596
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
597597
{
598-
return (ulong)pthread_selfLinux();
598+
return pthread_selfLinux().ToUInt32();
599599
}
600600

601601
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
@@ -611,7 +611,7 @@ public static ulong GetNativeThreadID()
611611
/// </summary>
612612
/// <param name="nativeThreadID">The native thread ID.</param>
613613
/// <returns>The number of thread states modified; this is normally one, but will be zero if the thread id isn’t found.</returns>
614-
public static int Interrupt(ulong nativeThreadID)
614+
public static int Interrupt(uint nativeThreadID)
615615
{
616616
if (Runtime.PyVersion >= new Version(3, 7))
617617
{
@@ -620,15 +620,15 @@ public static int Interrupt(ulong nativeThreadID)
620620
return Runtime.PyThreadState_SetAsyncExc37Windows(nativeThreadID, Exceptions.KeyboardInterrupt);
621621
}
622622

623-
return Runtime.PyThreadState_SetAsyncExc37NonWindows((UIntPtr)nativeThreadID, Exceptions.KeyboardInterrupt);
623+
return Runtime.PyThreadState_SetAsyncExc37NonWindows(new UIntPtr(nativeThreadID), Exceptions.KeyboardInterrupt);
624624
}
625625

626626
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
627627
{
628-
return Runtime.PyThreadState_SetAsyncExc36Windows((long)nativeThreadID, Exceptions.KeyboardInterrupt);
628+
return Runtime.PyThreadState_SetAsyncExc36Windows((int)nativeThreadID, Exceptions.KeyboardInterrupt);
629629
}
630630

631-
return Runtime.PyThreadState_SetAsyncExc36NonWindows((IntPtr)nativeThreadID, Exceptions.KeyboardInterrupt);
631+
return Runtime.PyThreadState_SetAsyncExc36NonWindows(new IntPtr(nativeThreadID), Exceptions.KeyboardInterrupt);
632632
}
633633

634634
/// <summary>

src/runtime/runtime.cs

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

21492149
[DllImport(_PythonDll, EntryPoint = "PyThreadState_SetAsyncExc", CallingConvention = CallingConvention.Cdecl)]
2150-
internal static extern int PyThreadState_SetAsyncExc37Windows(ulong id, IntPtr exc);
2150+
internal static extern int PyThreadState_SetAsyncExc37Windows(uint id, IntPtr exc);
21512151

21522152
[DllImport(_PythonDll, EntryPoint = "PyThreadState_SetAsyncExc", CallingConvention = CallingConvention.Cdecl)]
2153-
internal static extern int PyThreadState_SetAsyncExc36Windows(long id, IntPtr exc);
2153+
internal static extern int PyThreadState_SetAsyncExc36Windows(int id, IntPtr exc);
21542154

21552155
[DllImport(_PythonDll, EntryPoint = "PyThreadState_SetAsyncExc", CallingConvention = CallingConvention.Cdecl)]
21562156
internal static extern int PyThreadState_SetAsyncExc37NonWindows(UIntPtr id, IntPtr exc);

0 commit comments

Comments
 (0)