This repository was archived by the owner on Jul 22, 2023. It is now read-only.
forked from pythonnet/pythonnet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtil.cs
More file actions
43 lines (39 loc) · 1.33 KB
/
Util.cs
File metadata and controls
43 lines (39 loc) · 1.33 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
using System;
using System.Runtime.InteropServices;
namespace Python.Runtime
{
internal static class Util
{
internal const string UnstableApiMessage =
"This API is unstable, and might be changed or removed in the next minor release";
internal static Int64 ReadCLong(IntPtr tp, int offset)
{
// On Windows, a C long is always 32 bits.
if (Runtime.IsWindows || Runtime.Is32Bit)
{
return Marshal.ReadInt32(tp, offset);
}
else
{
return Marshal.ReadInt64(tp, offset);
}
}
internal static void WriteCLong(IntPtr type, int offset, Int64 flags)
{
if (Runtime.IsWindows || Runtime.Is32Bit)
{
Marshal.WriteInt32(type, offset, (Int32)(flags & 0xffffffffL));
}
else
{
Marshal.WriteInt64(type, offset, flags);
}
}
/// <summary>
/// Null-coalesce: if <paramref name="primary"/> parameter is not
/// <see cref="IntPtr.Zero"/>, return it. Otherwise return <paramref name="fallback"/>.
/// </summary>
internal static IntPtr Coalesce(this IntPtr primary, IntPtr fallback)
=> primary == IntPtr.Zero ? fallback : primary;
}
}