Skip to content

Added side-by-side VS 2017 build with NetStandard 1.5 support. #444

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 19 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Merge branch 'master' into coreclr
  • Loading branch information
filmor authored Jul 10, 2017
commit 45eaa721d012aba917bdd4a49d2bd433b45d8796
77 changes: 50 additions & 27 deletions src/runtime/runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public class Runtime
// We needs to replace all public constants to static readonly fields to allow
// binary substitution of different Python.Runtime.dll builds in a target application.

public static readonly int UCS = _UCS;
public static int UCS => _UCS;

#if UCS4
internal const int _UCS = 4;
Expand All @@ -102,7 +102,7 @@ public class Runtime
/// </summary>
private const string PyUnicodeEntryPoint = "PyUnicodeUCS4_";
#elif UCS2
public const int _UCS = 2;
internal const int _UCS = 2;

/// <summary>
/// EntryPoint to be used in DllImport to map to correct Unicode
Expand All @@ -117,27 +117,27 @@ public class Runtime
// We needs to replace all public constants to static readonly fields to allow
// binary substitution of different Python.Runtime.dll builds in a target application.

public const string pyversion = _pyversion;
public const string pyver = _pyver;
public string pyversion => _pyversion;
public string pyver => _pyver;

#if PYTHON27
internal const string _pyversion = "2.7";
internal const string _pyver = "27";
#elif PYTHON33
public const string _pyversion = "3.3";
public const string _pyver = "33";
internal const string _pyversion = "3.3";
internal const string _pyver = "33";
#elif PYTHON34
public const string _pyversion = "3.4";
public const string _pyver = "34";
internal const string _pyversion = "3.4";
internal const string _pyver = "34";
#elif PYTHON35
public const string _pyversion = "3.5";
public const string _pyver = "35";
internal const string _pyversion = "3.5";
internal const string _pyver = "35";
#elif PYTHON36
public const string _pyversion = "3.6";
public const string _pyver = "36";
internal const string _pyversion = "3.6";
internal const string _pyver = "36";
#elif PYTHON37 // TODO: Add `interop37.cs` after PY37 is released
public const string _pyversion = "3.7";
public const string _pyver = "37";
internal const string _pyversion = "3.7";
internal const string _pyver = "37";
#else
#error You must define one of PYTHON33 to PYTHON37 or PYTHON27
#endif
Expand Down Expand Up @@ -166,9 +166,9 @@ public class Runtime
public static readonly string PythonDLL = _PythonDll;

#if PYTHON_WITHOUT_ENABLE_SHARED
public const string _PythonDll = "__Internal";
internal const string _PythonDll = "__Internal";
#else
public const string _PythonDll = dllBase + dllWithPyDebug + dllWithPyMalloc;
internal const string _PythonDll = dllBase + dllWithPyDebug + dllWithPyMalloc;
#endif

public static readonly int pyversionnumber = Convert.ToInt32(_pyver);
Expand Down Expand Up @@ -308,7 +308,7 @@ internal static void Initialize()
if (_PythonDll != "__Internal")
{
#if !NETSTANDARD1_5
NativeMethods.LoadLibrary(_PythonDll);
dllLocal = NativeMethods.LoadLibrary(_PythonDll);
#endif
}
#if !NETSTANDARD1_5
Expand Down Expand Up @@ -639,7 +639,7 @@ internal static unsafe long Refcount(IntPtr op)

#if PYTHON3
#if NETSTANDARD1_5
[DllImport(_PythonDll)]
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
private static extern int Py_Main(
int argc,
IntPtr argv
Expand All @@ -661,7 +661,7 @@ string[] argv
return result;
}
#else
[DllImport(_PythonDll)]
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
public static extern int Py_Main(
int argc,
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(StrArrayMarshaler))] string[] argv
Expand Down Expand Up @@ -744,6 +744,9 @@ public static extern int Py_Main(
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern IntPtr PyRun_String(string code, IntPtr st, IntPtr globals, IntPtr locals);

[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern IntPtr PyEval_EvalCode(IntPtr co, IntPtr globals, IntPtr locals);

[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern IntPtr Py_CompileString(string code, string file, IntPtr tok);

Expand Down Expand Up @@ -814,6 +817,21 @@ internal static string PyObject_GetTypeName(IntPtr op)
return Marshal.PtrToStringAnsi(ppName);
}

/// <summary>
/// Test whether the Python object is an iterable.
/// </summary>
internal static bool PyObject_IsIterable(IntPtr pointer)
{
var ob_type = Marshal.ReadIntPtr(pointer, ObjectOffset.ob_type);
#if PYTHON2
long tp_flags = Util.ReadCLong(ob_type, TypeOffset.tp_flags);
if ((tp_flags & TypeFlags.HaveIter) == 0)
return false;
#endif
IntPtr tp_iter = Marshal.ReadIntPtr(ob_type, TypeOffset.tp_iter);
return tp_iter != IntPtr.Zero;
}

[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern int PyObject_HasAttrString(IntPtr pointer, string name);

Expand Down Expand Up @@ -1205,7 +1223,8 @@ internal static IntPtr PyBytes_AS_STRING(IntPtr ob)
}

#if NETSTANDARD1_5
[DllImport(_PythonDll, EntryPoint = "PyUnicode_FromStringAndSize")]
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl,
EntryPoint = "PyUnicode_FromStringAndSize")]
private static extern IntPtr PyString_FromStringAndSize(
IntPtr value,
int size
Expand All @@ -1228,7 +1247,8 @@ int size
return result;
}
#else
[DllImport(_PythonDll, EntryPoint = "PyUnicode_FromStringAndSize")]
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl,
EntryPoint = "PyUnicode_FromStringAndSize")]
internal static extern IntPtr PyString_FromStringAndSize(
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Utf8Marshaler))] string value,
int size
Expand Down Expand Up @@ -1261,7 +1281,7 @@ internal static bool PyUnicode_Check(IntPtr ob)
internal static extern IntPtr PyUnicode_FromEncodedObject(IntPtr ob, IntPtr enc, IntPtr err);

#if NETSTANDARD1_5
[DllImport(_PythonDll)]
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
private static extern IntPtr PyUnicode_FromKindAndData(
int kind,
IntPtr s,
Expand All @@ -1287,7 +1307,7 @@ int size
return result;
}
#else
[DllImport(_PythonDll)]
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern IntPtr PyUnicode_FromKindAndData(
int kind,
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(UcsMarshaler))] string s,
Expand Down Expand Up @@ -1318,7 +1338,8 @@ internal static IntPtr PyUnicode_FromUnicode(string s, int size)
internal static extern IntPtr PyUnicode_FromEncodedObject(IntPtr ob, IntPtr enc, IntPtr err);

#if NETSTANDARD1_5
[DllImport(_PythonDll, EntryPoint = PyUnicodeEntryPoint + "FromUnicode")]
[DllImport(_PythonDll, EntryPoint = PyUnicodeEntryPoint + "FromUnicode",
CallingConvention = CallingConvention.Cdecl)]
private static extern IntPtr PyUnicode_FromUnicode(
IntPtr s,
int size
Expand All @@ -1341,12 +1362,14 @@ int size
return result;
}
#else
[DllImport(PythonDll, EntryPoint = PyUnicodeEntryPoint + "FromUnicode")]
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl,
EntryPoint = PyUnicodeEntryPoint + "FromUnicode")]
internal static extern IntPtr PyUnicode_FromUnicode(
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(UcsMarshaler))] string s,
int size
);
#endif

[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl,
EntryPoint = PyUnicodeEntryPoint + "GetSize")]
internal static extern int PyUnicode_GetSize(IntPtr ob);
Expand Down Expand Up @@ -1592,7 +1615,7 @@ internal static bool PyIter_Check(IntPtr pointer)

#if PYTHON3
#if NETSTANDARD1_5
[DllImport(_PythonDll)]
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
private static extern void PySys_SetArgvEx(
int argc,
IntPtr argv,
Expand All @@ -1615,7 +1638,7 @@ int updatepath
}
}
#else
[DllImport(_PythonDll)]
[DllImport(_PythonDll, CallingConvention = CallingConvention.Cdecl)]
internal static extern void PySys_SetArgvEx(
int argc,
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(StrArrayMarshaler))] string[] argv,
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.