forked from dotnet/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRuntime_69612.cs
More file actions
64 lines (53 loc) · 1.64 KB
/
Runtime_69612.cs
File metadata and controls
64 lines (53 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.Runtime.CompilerServices;
using System.Threading;
ref struct NewReference
{
public IntPtr pointer;
}
static unsafe class Delegates
{
static Delegates()
{
PyLong_FromLongLong = (delegate* unmanaged[Cdecl]<long, NewReference>)0xbadcab;
z = 100;
}
public static delegate* unmanaged[Cdecl]<long, NewReference> PyLong_FromLongLong { get; }
public static long z;
}
class Runtime_69612
{
static NewReference ToPython(object value, Type type)
{
TypeCode tc = Type.GetTypeCode(type);
switch (tc)
{
case TypeCode.Byte:
return PyInt_FromInt32((byte)value);
case TypeCode.Int16:
return PyInt_FromInt32((short)value);
case TypeCode.UInt16:
return PyInt_FromInt32((ushort)value);
case TypeCode.Int32:
return PyInt_FromInt32((int)value);
default:
return new NewReference();
}
}
static NewReference PyInt_FromInt32(int value) => PyLong_FromLongLong(value);
unsafe static NewReference PyLong_FromLongLong(long value) => Delegates.PyLong_FromLongLong(value);
[MethodImpl(MethodImplOptions.NoOptimization)]
static int Main()
{
for (int i = 0; i < 100; i++)
{
_ = ToPython(Delegates.z, typeof(long));
Thread.Sleep(15);
}
Thread.Sleep(50);
_ = ToPython(Delegates.z, typeof(long));
return 100;
}
}