Skip to content

Commit 8e54d26

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

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

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 => OperatingSystem.ToString();
124+
125+
[Obsolete]
126+
public static string MachineName => Machine.ToString();
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 {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 {Runtime.OperatingSystem}"
666+
);
663667
}
664668
}
665669

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy