Skip to content

Add support for Python 3.5 #163

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

Merged
merged 2 commits into from
Feb 24, 2016
Merged
Show file tree
Hide file tree
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
Add Python 3.5 support.
  • Loading branch information
tonyroberts committed Feb 23, 2016
commit 3df332431bf202e37f58dbddb3a059c9cf6760d8
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ python:
- 2.7
- 3.2
- 3.4
- 3.5
before_install:
- sudo apt-get install software-properties-common
- sudo add-apt-repository -y "deb http://archive.ubuntu.com/ubuntu/ trusty main universe"
Expand Down
2 changes: 2 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ environment:
- PYTHON: "C:\\Python33-x64"
- PYTHON: "C:\\Python34"
- PYTHON: "C:\\Python34-x64"
- PYTHON: "C:\\Python35"
- PYTHON: "C:\\Python35-x64"

install:
- "%PYTHON%\\python.exe -m pip install --upgrade pip"
Expand Down
6 changes: 3 additions & 3 deletions src/clrmodule/ClrModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class clrModule
// ReSharper restore CheckNamespace
{
// ReSharper disable InconsistentNaming
#if (PYTHON32 || PYTHON33 || PYTHON34)
#if (PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35)
[RGiesecke.DllExport.DllExport("PyInit_clr", System.Runtime.InteropServices.CallingConvention.StdCall)]
public static IntPtr PyInit_clr()
#else
Expand Down Expand Up @@ -107,7 +107,7 @@ public static void initclr()
#if DEBUG_PRINT
System.Console.WriteLine("Could not load Python.Runtime, so sad.");
#endif
#if (PYTHON32 || PYTHON33 || PYTHON34)
#if (PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35)
return IntPtr.Zero;
#else
return;
Expand All @@ -119,7 +119,7 @@ public static void initclr()
// So now we get the PythonEngine and execute the InitExt method on it.
var pythonEngineType = pythonRuntime.GetType("Python.Runtime.PythonEngine");

#if (PYTHON32 || PYTHON33 || PYTHON34)
#if (PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35)
return (IntPtr)pythonEngineType.InvokeMember("InitExt", System.Reflection.BindingFlags.InvokeMethod, null, null, null);
#else
pythonEngineType.InvokeMember("InitExt", System.Reflection.BindingFlags.InvokeMethod, null, null, null);
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/classbase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public virtual IntPtr type_subscript(IntPtr idx) {
//====================================================================
// Standard comparison implementation for instances of reflected types.
//====================================================================
#if (PYTHON32 || PYTHON33 || PYTHON34)
#if (PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35)
public static IntPtr tp_richcompare(IntPtr ob, IntPtr other, int op) {
if (op != Runtime.Py_EQ && op != Runtime.Py_NE)
{
Expand Down
8 changes: 4 additions & 4 deletions src/runtime/converter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ static bool ToPrimitive(IntPtr value, Type obType, out Object result,
return true;

case TypeCode.Int32:
#if !(PYTHON32 || PYTHON33 || PYTHON34)
#if !(PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35)
// Trickery to support 64-bit platforms.
if (IntPtr.Size == 4) {
op = Runtime.PyNumber_Int(value);
Expand Down Expand Up @@ -457,7 +457,7 @@ static bool ToPrimitive(IntPtr value, Type obType, out Object result,
return true;

case TypeCode.Byte:
#if (PYTHON32 || PYTHON33 || PYTHON34)
#if (PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35)
if (Runtime.PyObject_TypeCheck(value, Runtime.PyBytesType))
{
if (Runtime.PyBytes_Size(value) == 1)
Expand Down Expand Up @@ -497,7 +497,7 @@ static bool ToPrimitive(IntPtr value, Type obType, out Object result,
return true;

case TypeCode.SByte:
#if (PYTHON32 || PYTHON33 || PYTHON34)
#if (PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35)
if (Runtime.PyObject_TypeCheck(value, Runtime.PyBytesType)) {
if (Runtime.PyBytes_Size(value) == 1) {
op = Runtime.PyBytes_AS_STRING(value);
Expand Down Expand Up @@ -535,7 +535,7 @@ static bool ToPrimitive(IntPtr value, Type obType, out Object result,
return true;

case TypeCode.Char:
#if (PYTHON32 || PYTHON33 || PYTHON34)
#if (PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35)
if (Runtime.PyObject_TypeCheck(value, Runtime.PyBytesType)) {
if (Runtime.PyBytes_Size(value) == 1) {
op = Runtime.PyBytes_AS_STRING(value);
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/delegateobject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public static IntPtr tp_call(IntPtr ob, IntPtr args, IntPtr kw) {
//====================================================================
// Implements __cmp__ for reflected delegate types.
//====================================================================
#if (PYTHON32 || PYTHON33 || PYTHON34)
#if (PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35)
public static new IntPtr tp_richcompare(IntPtr ob, IntPtr other, int op) {
if (op != Runtime.Py_EQ && op != Runtime.Py_NE)
{
Expand Down
14 changes: 7 additions & 7 deletions src/runtime/exceptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ internal class ExceptionClassObject : ClassObject {
internal ExceptionClassObject(Type tp) : base(tp) {
}

#if (PYTHON25 || PYTHON26 || PYTHON27 || PYTHON32 || PYTHON33 || PYTHON34)
#if (PYTHON25 || PYTHON26 || PYTHON27 || PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35)
internal static Exception ToException(IntPtr ob) {
CLRObject co = GetManagedObject(ob) as CLRObject;
if (co == null) {
Expand Down Expand Up @@ -114,7 +114,7 @@ public static IntPtr tp_getattro(IntPtr ob, IntPtr key)

return Runtime.PyObject_GenericGetAttr(ob, key);
}
#endif // (PYTHON25 || PYTHON26 || PYTHON27 || PYTHON32 || PYTHON33 || PYTHON34)
#endif // (PYTHON25 || PYTHON26 || PYTHON27 || PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35)
}

/// <summary>
Expand All @@ -136,7 +136,7 @@ private Exceptions() {}
//===================================================================

internal static void Initialize() {
#if (PYTHON32 || PYTHON33 || PYTHON34)
#if (PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35)
exceptions_module = Runtime.PyImport_ImportModule("builtins");
#else
exceptions_module = Runtime.PyImport_ImportModule("exceptions");
Expand Down Expand Up @@ -572,15 +572,15 @@ internal static IntPtr RaiseTypeError(string message) {
puplic static variables on the Exceptions class filled in from
the python class using reflection in Initialize() looked up by
name, not posistion. */
#if (PYTHON25 || PYTHON26 || PYTHON27 || PYTHON32 || PYTHON33 || PYTHON34)
#if (PYTHON25 || PYTHON26 || PYTHON27 || PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35)
public static IntPtr BaseException;
#endif
public static IntPtr Exception;
public static IntPtr StopIteration;
#if (PYTHON25 || PYTHON26 || PYTHON27 || PYTHON32 || PYTHON33 || PYTHON34)
#if (PYTHON25 || PYTHON26 || PYTHON27 || PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35)
public static IntPtr GeneratorExit;
#endif
#if !(PYTHON32 || PYTHON33 || PYTHON34)
#if !(PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35)
public static IntPtr StandardError;
#endif
public static IntPtr ArithmeticError;
Expand Down Expand Up @@ -637,7 +637,7 @@ puplic static variables on the Exceptions class filled in from
public static IntPtr SyntaxWarning;
public static IntPtr RuntimeWarning;
public static IntPtr FutureWarning;
#if (PYTHON25 || PYTHON26 || PYTHON27 || PYTHON32 || PYTHON33 || PYTHON34)
#if (PYTHON25 || PYTHON26 || PYTHON27 || PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35)
public static IntPtr ImportWarning;
public static IntPtr UnicodeWarning;
//PyAPI_DATA(PyObject *) PyExc_BytesWarning;
Expand Down
10 changes: 5 additions & 5 deletions src/runtime/importhook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ internal class ImportHook {
static CLRModule root;
static MethodWrapper hook;

#if (PYTHON32 || PYTHON33 || PYTHON34)
#if (PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35)
static IntPtr py_clr_module;
static IntPtr module_def;
#endif
Expand All @@ -38,7 +38,7 @@ internal static void Initialize() {
// but it provides the most "Pythonic" way of dealing with CLR
// modules (Python doesn't provide a way to emulate packages).
IntPtr dict = Runtime.PyImport_GetModuleDict();
#if (PYTHON32 || PYTHON33 || PYTHON34)
#if (PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35)
IntPtr mod = Runtime.PyImport_ImportModule("builtins");
py_import = Runtime.PyObject_GetAttrString(mod, "__import__");
#else
Expand All @@ -51,7 +51,7 @@ internal static void Initialize() {

root = new CLRModule();

#if (PYTHON32 || PYTHON33 || PYTHON34)
#if (PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35)
// create a python module with the same methods as the clr module-like object
module_def = ModuleDefOffset.AllocModuleDef("clr");
py_clr_module = Runtime.PyModule_Create2(module_def, 3);
Expand All @@ -78,7 +78,7 @@ internal static void Initialize() {
//===================================================================

internal static void Shutdown() {
#if (PYTHON32 || PYTHON33 || PYTHON34)
#if (PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35)
if (0 != Runtime.Py_IsInitialized()) {
Runtime.Decref(py_clr_module);
Runtime.Decref(root.pyHandle);
Expand All @@ -100,7 +100,7 @@ internal static void Shutdown() {
//===================================================================
public static IntPtr GetCLRModule(IntPtr? fromList=null) {
root.InitializePreload();
#if (PYTHON32 || PYTHON33 || PYTHON34)
#if (PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35)
// update the module dictionary with the contents of the root dictionary
root.LoadNames();
IntPtr py_mod_dict = Runtime.PyModule_GetDict(py_clr_module);
Expand Down
22 changes: 11 additions & 11 deletions src/runtime/interop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ static ObjectOffset() {
}

public static int magic(IntPtr ob) {
#if (PYTHON32 || PYTHON33 || PYTHON34)
#if (PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35)
if ((Runtime.PyObject_TypeCheck(ob, Exceptions.BaseException) ||
(Runtime.PyType_Check(ob) && Runtime.PyType_IsSubtype(ob, Exceptions.BaseException))))
{
Expand All @@ -91,7 +91,7 @@ public static int magic(IntPtr ob) {

public static int DictOffset(IntPtr ob)
{
#if (PYTHON32 || PYTHON33 || PYTHON34)
#if (PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35)
if ((Runtime.PyObject_TypeCheck(ob, Exceptions.BaseException) ||
(Runtime.PyType_Check(ob) && Runtime.PyType_IsSubtype(ob, Exceptions.BaseException))))
{
Expand All @@ -102,7 +102,7 @@ public static int DictOffset(IntPtr ob)
}

public static int Size(IntPtr ob) {
#if (PYTHON32 || PYTHON33 || PYTHON34)
#if (PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35)
if ((Runtime.PyObject_TypeCheck(ob, Exceptions.BaseException) ||
(Runtime.PyType_Check(ob) && Runtime.PyType_IsSubtype(ob, Exceptions.BaseException))))
{
Expand All @@ -126,7 +126,7 @@ public static int Size(IntPtr ob) {
private static int ob_data;
}

#if (PYTHON32 || PYTHON33 || PYTHON34)
#if (PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35)
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
internal class ExceptionOffset
{
Expand Down Expand Up @@ -161,7 +161,7 @@ public static int Size()
#endif


#if (PYTHON32 || PYTHON33 || PYTHON34)
#if (PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35)
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
internal class BytesOffset
{
Expand Down Expand Up @@ -281,10 +281,10 @@ internal class TypeFlags {
/* XXX Reusing reserved constants */
public static int Managed = (1 << 15); // PythonNet specific
public static int Subclass = (1 << 16); // PythonNet specific
#if (PYTHON25 || PYTHON26 || PYTHON27 || PYTHON32 || PYTHON33 || PYTHON34)
#if (PYTHON25 || PYTHON26 || PYTHON27 || PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35)
public static int HaveIndex = (1 << 17);
#endif
#if (PYTHON26 || PYTHON27 || PYTHON32 || PYTHON33 || PYTHON34)
#if (PYTHON26 || PYTHON27 || PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35)
/* Objects support nb_index in PyNumberMethods */
public static int HaveVersionTag = (1 << 18);
public static int ValidVersionTag = (1 << 19);
Expand Down Expand Up @@ -320,7 +320,7 @@ internal class TypeFlags {
#endif

// Default flags for Python 3
#if (PYTHON32 || PYTHON33 || PYTHON34)
#if (PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35)
public static int Default = (
HaveStacklessExtension |
HaveVersionTag);
Expand Down Expand Up @@ -383,7 +383,7 @@ static Interop() {
pmap["nb_add"] = p["BinaryFunc"];
pmap["nb_subtract"] = p["BinaryFunc"];
pmap["nb_multiply"] = p["BinaryFunc"];
#if !(PYTHON32 || PYTHON33 || PYTHON34)
#if !(PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35)
pmap["nb_divide"] = p["BinaryFunc"];
#endif
pmap["nb_remainder"] = p["BinaryFunc"];
Expand All @@ -408,7 +408,7 @@ static Interop() {
pmap["nb_inplace_add"] = p["BinaryFunc"];
pmap["nb_inplace_subtract"] = p["BinaryFunc"];
pmap["nb_inplace_multiply"] = p["BinaryFunc"];
#if !(PYTHON32 || PYTHON33 || PYTHON34)
#if !(PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35)
pmap["nb_inplace_divide"] = p["BinaryFunc"];
#endif
pmap["nb_inplace_remainder"] = p["BinaryFunc"];
Expand All @@ -422,7 +422,7 @@ static Interop() {
pmap["nb_true_divide"] = p["BinaryFunc"];
pmap["nb_inplace_floor_divide"] = p["BinaryFunc"];
pmap["nb_inplace_true_divide"] = p["BinaryFunc"];
#if (PYTHON25 || PYTHON26 || PYTHON27 || PYTHON32 || PYTHON33 || PYTHON34)
#if (PYTHON25 || PYTHON26 || PYTHON27 || PYTHON32 || PYTHON33 || PYTHON34 || PYTHON35)
pmap["nb_index"] = p["UnaryFunc"];
#endif

Expand Down
Loading