Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ad227f4

Browse files
committed
Code review adjustments
- Use `BorrowedReference` where applicable - Readd `OperatingSystemName` and `MachineName` for now
1 parent c6ae15b commit ad227f4

File tree

3 files changed

+167
-6
lines changed

3 files changed

+167
-6
lines changed

src/runtime/interop37m.cs

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
2+
// Auto-generated by geninterop.py.
3+
// DO NOT MODIFY BY HAND.
4+
5+
6+
#if PYTHON37 && PYTHON_WITH_PYMALLOC
7+
using System;
8+
using System.Collections;
9+
using System.Collections.Specialized;
10+
using System.Runtime.InteropServices;
11+
using System.Reflection;
12+
using System.Text;
13+
14+
namespace Python.Runtime
15+
{
16+
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
17+
internal class TypeOffset
18+
{
19+
static TypeOffset()
20+
{
21+
Type type = typeof(TypeOffset);
22+
FieldInfo[] fi = type.GetFields();
23+
int size = IntPtr.Size;
24+
for (int i = 0; i < fi.Length; i++)
25+
{
26+
fi[i].SetValue(null, i * size);
27+
}
28+
}
29+
30+
public static int magic()
31+
{
32+
return ob_size;
33+
}
34+
35+
// Auto-generated from PyHeapTypeObject in Python.h
36+
public static int ob_refcnt = 0;
37+
public static int ob_type = 0;
38+
public static int ob_size = 0;
39+
public static int tp_name = 0;
40+
public static int tp_basicsize = 0;
41+
public static int tp_itemsize = 0;
42+
public static int tp_dealloc = 0;
43+
public static int tp_print = 0;
44+
public static int tp_getattr = 0;
45+
public static int tp_setattr = 0;
46+
public static int tp_as_async = 0;
47+
public static int tp_repr = 0;
48+
public static int tp_as_number = 0;
49+
public static int tp_as_sequence = 0;
50+
public static int tp_as_mapping = 0;
51+
public static int tp_hash = 0;
52+
public static int tp_call = 0;
53+
public static int tp_str = 0;
54+
public static int tp_getattro = 0;
55+
public static int tp_setattro = 0;
56+
public static int tp_as_buffer = 0;
57+
public static int tp_flags = 0;
58+
public static int tp_doc = 0;
59+
public static int tp_traverse = 0;
60+
public static int tp_clear = 0;
61+
public static int tp_richcompare = 0;
62+
public static int tp_weaklistoffset = 0;
63+
public static int tp_iter = 0;
64+
public static int tp_iternext = 0;
65+
public static int tp_methods = 0;
66+
public static int tp_members = 0;
67+
public static int tp_getset = 0;
68+
public static int tp_base = 0;
69+
public static int tp_dict = 0;
70+
public static int tp_descr_get = 0;
71+
public static int tp_descr_set = 0;
72+
public static int tp_dictoffset = 0;
73+
public static int tp_init = 0;
74+
public static int tp_alloc = 0;
75+
public static int tp_new = 0;
76+
public static int tp_free = 0;
77+
public static int tp_is_gc = 0;
78+
public static int tp_bases = 0;
79+
public static int tp_mro = 0;
80+
public static int tp_cache = 0;
81+
public static int tp_subclasses = 0;
82+
public static int tp_weaklist = 0;
83+
public static int tp_del = 0;
84+
public static int tp_version_tag = 0;
85+
public static int tp_finalize = 0;
86+
public static int am_await = 0;
87+
public static int am_aiter = 0;
88+
public static int am_anext = 0;
89+
public static int nb_add = 0;
90+
public static int nb_subtract = 0;
91+
public static int nb_multiply = 0;
92+
public static int nb_remainder = 0;
93+
public static int nb_divmod = 0;
94+
public static int nb_power = 0;
95+
public static int nb_negative = 0;
96+
public static int nb_positive = 0;
97+
public static int nb_absolute = 0;
98+
public static int nb_bool = 0;
99+
public static int nb_invert = 0;
100+
public static int nb_lshift = 0;
101+
public static int nb_rshift = 0;
102+
public static int nb_and = 0;
103+
public static int nb_xor = 0;
104+
public static int nb_or = 0;
105+
public static int nb_int = 0;
106+
public static int nb_reserved = 0;
107+
public static int nb_float = 0;
108+
public static int nb_inplace_add = 0;
109+
public static int nb_inplace_subtract = 0;
110+
public static int nb_inplace_multiply = 0;
111+
public static int nb_inplace_remainder = 0;
112+
public static int nb_inplace_power = 0;
113+
public static int nb_inplace_lshift = 0;
114+
public static int nb_inplace_rshift = 0;
115+
public static int nb_inplace_and = 0;
116+
public static int nb_inplace_xor = 0;
117+
public static int nb_inplace_or = 0;
118+
public static int nb_floor_divide = 0;
119+
public static int nb_true_divide = 0;
120+
public static int nb_inplace_floor_divide = 0;
121+
public static int nb_inplace_true_divide = 0;
122+
public static int nb_index = 0;
123+
public static int nb_matrix_multiply = 0;
124+
public static int nb_inplace_matrix_multiply = 0;
125+
public static int mp_length = 0;
126+
public static int mp_subscript = 0;
127+
public static int mp_ass_subscript = 0;
128+
public static int sq_length = 0;
129+
public static int sq_concat = 0;
130+
public static int sq_repeat = 0;
131+
public static int sq_item = 0;
132+
public static int was_sq_slice = 0;
133+
public static int sq_ass_item = 0;
134+
public static int was_sq_ass_slice = 0;
135+
public static int sq_contains = 0;
136+
public static int sq_inplace_concat = 0;
137+
public static int sq_inplace_repeat = 0;
138+
public static int bf_getbuffer = 0;
139+
public static int bf_releasebuffer = 0;
140+
public static int name = 0;
141+
public static int ht_slots = 0;
142+
public static int qualname = 0;
143+
public static int ht_cached_keys = 0;
144+
145+
/* here are optional user slots, followed by the members. */
146+
public static int members = 0;
147+
}
148+
}
149+
150+
#endif

src/runtime/runtime.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Reflection.Emit;
12
using System;
23
using System.Diagnostics.Contracts;
34
using System.Runtime.InteropServices;
@@ -118,6 +119,12 @@ public class Runtime
118119
{ "Linux", OperatingSystemType.Linux },
119120
};
120121

122+
[Obsolete]
123+
public static string OperatingSystemName => Enum.GetName(typeof(OperatingSystemType), OperatingSystem);
124+
125+
[Obsolete]
126+
public static string MachineName => Enum.GetName(typeof(MachineType), Machine);
127+
121128
/// <summary>
122129
/// Gets the operating system as reported by python's platform.system().
123130
/// </summary>
@@ -1990,10 +1997,10 @@ internal static IntPtr PyMem_Realloc(IntPtr ptr, long size)
19901997
//====================================================================
19911998

19921999
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
1993-
internal static extern NewReference PyCell_Get(IntPtr cell);
2000+
internal static extern NewReference PyCell_Get(BorrowedReference cell);
19942001

19952002
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
1996-
internal static extern int PyCell_Set(IntPtr cell, IntPtr value);
2003+
internal static extern int PyCell_Set(BorrowedReference cell, IntPtr value);
19972004

19982005
//====================================================================
19992006
// Miscellaneous

src/runtime/typemanager.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,8 @@ internal static IntPtr CreateSubType(IntPtr py_name, IntPtr py_base_type, IntPtr
281281
Runtime.PyDict_Update(cls_dict, py_dict);
282282

283283
// Update the __classcell__ if it exists
284-
IntPtr cell = Runtime.PyDict_GetItemString(cls_dict, "__classcell__");
285-
if (cell != IntPtr.Zero)
284+
var cell = new BorrowedReference(Runtime.PyDict_GetItemString(cls_dict, "__classcell__"));
285+
if (!cell.IsNull)
286286
{
287287
Runtime.PyCell_Set(cell, py_type);
288288
Runtime.PyDict_DelItemString(cls_dict, "__classcell__");
@@ -625,7 +625,9 @@ int MAP_ANONYMOUS
625625
case OperatingSystemType.Linux:
626626
return 0x20;
627627
default:
628-
throw new NotImplementedException($"mmap is not supported on this operating system");
628+
throw new NotImplementedException(
629+
$"mmap is not supported on {Enum.GetName(typeof(OperatingSystemType), Runtime.OperatingSystem)}"
630+
);
629631
}
630632
}
631633
}
@@ -659,7 +661,9 @@ internal static IMemoryMapper CreateMemoryMapper()
659661
case OperatingSystemType.Windows:
660662
return new WindowsMemoryMapper();
661663
default:
662-
throw new NotImplementedException($"No support for this operating system");
664+
throw new NotImplementedException(
665+
$"No support for {Enum.GetName(typeof(OperatingSystemType), Runtime.OperatingSystem)}"
666+
);
663667
}
664668
}
665669

0 commit comments

Comments
 (0)